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
17,600
medialab/artoo
src/artoo.helpers.js
parallel
function parallel(tasks, params, last) { var onEnd = (typeof params === 'function') ? params : params.done || last, running = [], results = [], d = 0, t, l, i; if (typeof onEnd !== 'function') onEnd = noop; function cleanup() { running.forEach(function(r) { clearTimeout(r); }); } function onTaskEnd(err, result) { // Adding results to accumulator results.push(result); if (err) { cleanup(); return onEnd(err, results); } if (++d >= tasks.length) { // Parallel action is finished, returning return onEnd(null, results); } // Adding on stack t = tasks[i++]; running.push(async(t, onTaskEnd)); } for (i = 0, l = params.limit || tasks.length; i < l; i++) { t = tasks[i]; // Dispatching the function asynchronously running.push(async(t, onTaskEnd)); } }
javascript
function parallel(tasks, params, last) { var onEnd = (typeof params === 'function') ? params : params.done || last, running = [], results = [], d = 0, t, l, i; if (typeof onEnd !== 'function') onEnd = noop; function cleanup() { running.forEach(function(r) { clearTimeout(r); }); } function onTaskEnd(err, result) { // Adding results to accumulator results.push(result); if (err) { cleanup(); return onEnd(err, results); } if (++d >= tasks.length) { // Parallel action is finished, returning return onEnd(null, results); } // Adding on stack t = tasks[i++]; running.push(async(t, onTaskEnd)); } for (i = 0, l = params.limit || tasks.length; i < l; i++) { t = tasks[i]; // Dispatching the function asynchronously running.push(async(t, onTaskEnd)); } }
[ "function", "parallel", "(", "tasks", ",", "params", ",", "last", ")", "{", "var", "onEnd", "=", "(", "typeof", "params", "===", "'function'", ")", "?", "params", ":", "params", ".", "done", "||", "last", ",", "running", "=", "[", "]", ",", "results", "=", "[", "]", ",", "d", "=", "0", ",", "t", ",", "l", ",", "i", ";", "if", "(", "typeof", "onEnd", "!==", "'function'", ")", "onEnd", "=", "noop", ";", "function", "cleanup", "(", ")", "{", "running", ".", "forEach", "(", "function", "(", "r", ")", "{", "clearTimeout", "(", "r", ")", ";", "}", ")", ";", "}", "function", "onTaskEnd", "(", "err", ",", "result", ")", "{", "// Adding results to accumulator", "results", ".", "push", "(", "result", ")", ";", "if", "(", "err", ")", "{", "cleanup", "(", ")", ";", "return", "onEnd", "(", "err", ",", "results", ")", ";", "}", "if", "(", "++", "d", ">=", "tasks", ".", "length", ")", "{", "// Parallel action is finished, returning", "return", "onEnd", "(", "null", ",", "results", ")", ";", "}", "// Adding on stack", "t", "=", "tasks", "[", "i", "++", "]", ";", "running", ".", "push", "(", "async", "(", "t", ",", "onTaskEnd", ")", ")", ";", "}", "for", "(", "i", "=", "0", ",", "l", "=", "params", ".", "limit", "||", "tasks", ".", "length", ";", "i", "<", "l", ";", "i", "++", ")", "{", "t", "=", "tasks", "[", "i", "]", ";", "// Dispatching the function asynchronously", "running", ".", "push", "(", "async", "(", "t", ",", "onTaskEnd", ")", ")", ";", "}", "}" ]
Launching tasks in parallel with an optional limit
[ "Launching", "tasks", "in", "parallel", "with", "an", "optional", "limit" ]
89fe334cb2c2ec38b16012edfab2977822e1ecda
https://github.com/medialab/artoo/blob/89fe334cb2c2ec38b16012edfab2977822e1ecda/src/artoo.helpers.js#L324-L368
17,601
medialab/artoo
src/artoo.log.js
isAllowed
function isAllowed(level) { var threshold = artoo.settings.log.level; if (artoo.helpers.isArray(threshold)) return !!~threshold.indexOf(level); else return priorities.indexOf(level) >= priorities.indexOf(threshold); }
javascript
function isAllowed(level) { var threshold = artoo.settings.log.level; if (artoo.helpers.isArray(threshold)) return !!~threshold.indexOf(level); else return priorities.indexOf(level) >= priorities.indexOf(threshold); }
[ "function", "isAllowed", "(", "level", ")", "{", "var", "threshold", "=", "artoo", ".", "settings", ".", "log", ".", "level", ";", "if", "(", "artoo", ".", "helpers", ".", "isArray", "(", "threshold", ")", ")", "return", "!", "!", "~", "threshold", ".", "indexOf", "(", "level", ")", ";", "else", "return", "priorities", ".", "indexOf", "(", "level", ")", ">=", "priorities", ".", "indexOf", "(", "threshold", ")", ";", "}" ]
Is the level allowed to log?
[ "Is", "the", "level", "allowed", "to", "log?" ]
89fe334cb2c2ec38b16012edfab2977822e1ecda
https://github.com/medialab/artoo/blob/89fe334cb2c2ec38b16012edfab2977822e1ecda/src/artoo.log.js#L31-L39
17,602
medialab/artoo
src/methods/artoo.methods.scrape.js
scrape
function scrape(iterator, data, params, cb) { var $ = artoo.$, scraped = [], loneSelector = !!data.attr || !!data.method || data.scrape || typeof data === 'string' || typeof data === 'function'; params = params || {}; // Transforming to selector var $iterator; if (typeof iterator === 'function') $iterator = $(iterator($)); else $iterator = $(iterator); // Iteration $iterator.each(function(i) { var item = {}, p; // TODO: figure iteration scope elsewhere for scrape recursivity if (loneSelector) item = (typeof data === 'object' && 'scrape' in data) ? scrape( (data.sel ? $(this).find(data.sel) : $(this)) .find(data.scrape.iterator), data.scrape.data, data.scrape.params ) : step(data, this); else for (p in data) { item[p] = (typeof data[p] === 'object' && 'scrape' in data[p]) ? scrape( (data[p].sel ? $(this).find(data[p].sel) : $(this)) .find(data[p].scrape.iterator), data[p].scrape.data, data[p].scrape.params ) : step(data[p], this); } scraped.push(item); // Breaking if limit i attained return !params.limit || i < params.limit - 1; }); scraped = params.one ? scraped[0] : scraped; // Triggering callback if (typeof cb === 'function') cb(scraped); // Returning data return scraped; }
javascript
function scrape(iterator, data, params, cb) { var $ = artoo.$, scraped = [], loneSelector = !!data.attr || !!data.method || data.scrape || typeof data === 'string' || typeof data === 'function'; params = params || {}; // Transforming to selector var $iterator; if (typeof iterator === 'function') $iterator = $(iterator($)); else $iterator = $(iterator); // Iteration $iterator.each(function(i) { var item = {}, p; // TODO: figure iteration scope elsewhere for scrape recursivity if (loneSelector) item = (typeof data === 'object' && 'scrape' in data) ? scrape( (data.sel ? $(this).find(data.sel) : $(this)) .find(data.scrape.iterator), data.scrape.data, data.scrape.params ) : step(data, this); else for (p in data) { item[p] = (typeof data[p] === 'object' && 'scrape' in data[p]) ? scrape( (data[p].sel ? $(this).find(data[p].sel) : $(this)) .find(data[p].scrape.iterator), data[p].scrape.data, data[p].scrape.params ) : step(data[p], this); } scraped.push(item); // Breaking if limit i attained return !params.limit || i < params.limit - 1; }); scraped = params.one ? scraped[0] : scraped; // Triggering callback if (typeof cb === 'function') cb(scraped); // Returning data return scraped; }
[ "function", "scrape", "(", "iterator", ",", "data", ",", "params", ",", "cb", ")", "{", "var", "$", "=", "artoo", ".", "$", ",", "scraped", "=", "[", "]", ",", "loneSelector", "=", "!", "!", "data", ".", "attr", "||", "!", "!", "data", ".", "method", "||", "data", ".", "scrape", "||", "typeof", "data", "===", "'string'", "||", "typeof", "data", "===", "'function'", ";", "params", "=", "params", "||", "{", "}", ";", "// Transforming to selector", "var", "$iterator", ";", "if", "(", "typeof", "iterator", "===", "'function'", ")", "$iterator", "=", "$", "(", "iterator", "(", "$", ")", ")", ";", "else", "$iterator", "=", "$", "(", "iterator", ")", ";", "// Iteration", "$iterator", ".", "each", "(", "function", "(", "i", ")", "{", "var", "item", "=", "{", "}", ",", "p", ";", "// TODO: figure iteration scope elsewhere for scrape recursivity", "if", "(", "loneSelector", ")", "item", "=", "(", "typeof", "data", "===", "'object'", "&&", "'scrape'", "in", "data", ")", "?", "scrape", "(", "(", "data", ".", "sel", "?", "$", "(", "this", ")", ".", "find", "(", "data", ".", "sel", ")", ":", "$", "(", "this", ")", ")", ".", "find", "(", "data", ".", "scrape", ".", "iterator", ")", ",", "data", ".", "scrape", ".", "data", ",", "data", ".", "scrape", ".", "params", ")", ":", "step", "(", "data", ",", "this", ")", ";", "else", "for", "(", "p", "in", "data", ")", "{", "item", "[", "p", "]", "=", "(", "typeof", "data", "[", "p", "]", "===", "'object'", "&&", "'scrape'", "in", "data", "[", "p", "]", ")", "?", "scrape", "(", "(", "data", "[", "p", "]", ".", "sel", "?", "$", "(", "this", ")", ".", "find", "(", "data", "[", "p", "]", ".", "sel", ")", ":", "$", "(", "this", ")", ")", ".", "find", "(", "data", "[", "p", "]", ".", "scrape", ".", "iterator", ")", ",", "data", "[", "p", "]", ".", "scrape", ".", "data", ",", "data", "[", "p", "]", ".", "scrape", ".", "params", ")", ":", "step", "(", "data", "[", "p", "]", ",", "this", ")", ";", "}", "scraped", ".", "push", "(", "item", ")", ";", "// Breaking if limit i attained", "return", "!", "params", ".", "limit", "||", "i", "<", "params", ".", "limit", "-", "1", ";", "}", ")", ";", "scraped", "=", "params", ".", "one", "?", "scraped", "[", "0", "]", ":", "scraped", ";", "// Triggering callback", "if", "(", "typeof", "cb", "===", "'function'", ")", "cb", "(", "scraped", ")", ";", "// Returning data", "return", "scraped", ";", "}" ]
Scraping function after polymorphism has been taken care of
[ "Scraping", "function", "after", "polymorphism", "has", "been", "taken", "care", "of" ]
89fe334cb2c2ec38b16012edfab2977822e1ecda
https://github.com/medialab/artoo/blob/89fe334cb2c2ec38b16012edfab2977822e1ecda/src/methods/artoo.methods.scrape.js#L47-L104
17,603
medialab/artoo
src/methods/artoo.methods.scrape.js
polymorphism
function polymorphism(iterator, data, params, cb) { var h = artoo.helpers, i, d, p, c; if (h.isPlainObject(iterator) && !h.isSelector(iterator) && !h.isDocument(iterator) && (iterator.iterator || iterator.data || iterator.params)) { d = iterator.data; p = h.isPlainObject(iterator.params) ? iterator.params : {}; i = iterator.iterator; } else { d = data; p = h.isPlainObject(params) ? params : {}; i = iterator; } // Default values d = d || 'text'; c = typeof cb === 'function' ? cb : typeof params === 'function' ? params : p.done; return [i, d, p, c]; }
javascript
function polymorphism(iterator, data, params, cb) { var h = artoo.helpers, i, d, p, c; if (h.isPlainObject(iterator) && !h.isSelector(iterator) && !h.isDocument(iterator) && (iterator.iterator || iterator.data || iterator.params)) { d = iterator.data; p = h.isPlainObject(iterator.params) ? iterator.params : {}; i = iterator.iterator; } else { d = data; p = h.isPlainObject(params) ? params : {}; i = iterator; } // Default values d = d || 'text'; c = typeof cb === 'function' ? cb : typeof params === 'function' ? params : p.done; return [i, d, p, c]; }
[ "function", "polymorphism", "(", "iterator", ",", "data", ",", "params", ",", "cb", ")", "{", "var", "h", "=", "artoo", ".", "helpers", ",", "i", ",", "d", ",", "p", ",", "c", ";", "if", "(", "h", ".", "isPlainObject", "(", "iterator", ")", "&&", "!", "h", ".", "isSelector", "(", "iterator", ")", "&&", "!", "h", ".", "isDocument", "(", "iterator", ")", "&&", "(", "iterator", ".", "iterator", "||", "iterator", ".", "data", "||", "iterator", ".", "params", ")", ")", "{", "d", "=", "iterator", ".", "data", ";", "p", "=", "h", ".", "isPlainObject", "(", "iterator", ".", "params", ")", "?", "iterator", ".", "params", ":", "{", "}", ";", "i", "=", "iterator", ".", "iterator", ";", "}", "else", "{", "d", "=", "data", ";", "p", "=", "h", ".", "isPlainObject", "(", "params", ")", "?", "params", ":", "{", "}", ";", "i", "=", "iterator", ";", "}", "// Default values", "d", "=", "d", "||", "'text'", ";", "c", "=", "typeof", "cb", "===", "'function'", "?", "cb", ":", "typeof", "params", "===", "'function'", "?", "params", ":", "p", ".", "done", ";", "return", "[", "i", ",", "d", ",", "p", ",", "c", "]", ";", "}" ]
Function taking care of harsh polymorphism
[ "Function", "taking", "care", "of", "harsh", "polymorphism" ]
89fe334cb2c2ec38b16012edfab2977822e1ecda
https://github.com/medialab/artoo/blob/89fe334cb2c2ec38b16012edfab2977822e1ecda/src/methods/artoo.methods.scrape.js#L107-L133
17,604
thumbsup/thumbsup
src/steps/step-album-zip.js
createZip
function createZip (targetZipPath, currentFolder, filesToInclude, done) { const args = ['-FS', targetZipPath].concat(filesToInclude) const startTime = Date.now() trace(`Calling: zip ${args.join(' ')}`) const child = childProcess.spawn('zip', args, { cwd: currentFolder, stdio: [ 'ignore', 'ignore', 'ignore' ] }) child.on('error', (err) => { error(`Error: please verify that <zip> is installed on your system`) error(err.toString()) }) child.on('close', (code, signal) => { const elapsed = Math.floor(Date.now() - startTime) debug(`Zip exited with code ${code} in ${elapsed}ms`) done(code === 0 ? null : new Error(`Error creating ZIP file ${targetZipPath}`)) }) }
javascript
function createZip (targetZipPath, currentFolder, filesToInclude, done) { const args = ['-FS', targetZipPath].concat(filesToInclude) const startTime = Date.now() trace(`Calling: zip ${args.join(' ')}`) const child = childProcess.spawn('zip', args, { cwd: currentFolder, stdio: [ 'ignore', 'ignore', 'ignore' ] }) child.on('error', (err) => { error(`Error: please verify that <zip> is installed on your system`) error(err.toString()) }) child.on('close', (code, signal) => { const elapsed = Math.floor(Date.now() - startTime) debug(`Zip exited with code ${code} in ${elapsed}ms`) done(code === 0 ? null : new Error(`Error creating ZIP file ${targetZipPath}`)) }) }
[ "function", "createZip", "(", "targetZipPath", ",", "currentFolder", ",", "filesToInclude", ",", "done", ")", "{", "const", "args", "=", "[", "'-FS'", ",", "targetZipPath", "]", ".", "concat", "(", "filesToInclude", ")", "const", "startTime", "=", "Date", ".", "now", "(", ")", "trace", "(", "`", "${", "args", ".", "join", "(", "' '", ")", "}", "`", ")", "const", "child", "=", "childProcess", ".", "spawn", "(", "'zip'", ",", "args", ",", "{", "cwd", ":", "currentFolder", ",", "stdio", ":", "[", "'ignore'", ",", "'ignore'", ",", "'ignore'", "]", "}", ")", "child", ".", "on", "(", "'error'", ",", "(", "err", ")", "=>", "{", "error", "(", "`", "`", ")", "error", "(", "err", ".", "toString", "(", ")", ")", "}", ")", "child", ".", "on", "(", "'close'", ",", "(", "code", ",", "signal", ")", "=>", "{", "const", "elapsed", "=", "Math", ".", "floor", "(", "Date", ".", "now", "(", ")", "-", "startTime", ")", "debug", "(", "`", "${", "code", "}", "${", "elapsed", "}", "`", ")", "done", "(", "code", "===", "0", "?", "null", ":", "new", "Error", "(", "`", "${", "targetZipPath", "}", "`", ")", ")", "}", ")", "}" ]
This function uses the Unix ZIP command, which supports "updating" a ZIP file In the future it could also delegate to 7zip on Windows
[ "This", "function", "uses", "the", "Unix", "ZIP", "command", "which", "supports", "updating", "a", "ZIP", "file", "In", "the", "future", "it", "could", "also", "delegate", "to", "7zip", "on", "Windows" ]
d2ad35d225655b59515e4cd0f431e9d7d5447615
https://github.com/thumbsup/thumbsup/blob/d2ad35d225655b59515e4cd0f431e9d7d5447615/src/steps/step-album-zip.js#L39-L56
17,605
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drop.js
function( event, drag ) { var el, drops, selector, sels; this.last_active = []; for(var i=0; i < this._elements.length; i++){ //for each element el = this._elements[i] var drops = $.event.findBySelector(el, eventNames) for(selector in drops){ //find the selectors sels = selector ? jQuery(selector, el) : [el]; for(var e= 0; e < sels.length; e++){ //for each found element, create a drop point jQuery.removeData(sels[e],"offset"); this.add(sels[e], new this(drops[selector]), event, drag); } } } }
javascript
function( event, drag ) { var el, drops, selector, sels; this.last_active = []; for(var i=0; i < this._elements.length; i++){ //for each element el = this._elements[i] var drops = $.event.findBySelector(el, eventNames) for(selector in drops){ //find the selectors sels = selector ? jQuery(selector, el) : [el]; for(var e= 0; e < sels.length; e++){ //for each found element, create a drop point jQuery.removeData(sels[e],"offset"); this.add(sels[e], new this(drops[selector]), event, drag); } } } }
[ "function", "(", "event", ",", "drag", ")", "{", "var", "el", ",", "drops", ",", "selector", ",", "sels", ";", "this", ".", "last_active", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "this", ".", "_elements", ".", "length", ";", "i", "++", ")", "{", "//for each element", "el", "=", "this", ".", "_elements", "[", "i", "]", "var", "drops", "=", "$", ".", "event", ".", "findBySelector", "(", "el", ",", "eventNames", ")", "for", "(", "selector", "in", "drops", ")", "{", "//find the selectors", "sels", "=", "selector", "?", "jQuery", "(", "selector", ",", "el", ")", ":", "[", "el", "]", ";", "for", "(", "var", "e", "=", "0", ";", "e", "<", "sels", ".", "length", ";", "e", "++", ")", "{", "//for each found element, create a drop point", "jQuery", ".", "removeData", "(", "sels", "[", "e", "]", ",", "\"offset\"", ")", ";", "this", ".", "add", "(", "sels", "[", "e", "]", ",", "new", "this", "(", "drops", "[", "selector", "]", ")", ",", "event", ",", "drag", ")", ";", "}", "}", "}", "}" ]
Gets all elements that are droppable, adds them
[ "Gets", "all", "elements", "that", "are", "droppable", "adds", "them" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drop.js#L302-L318
17,606
testem/testem
examples/template_stealjs/steal/steal.js
function( url, expand ) { var u = File(url); // if this.path is absolutely referenced if ( this.protocol() ) { //if we are absolutely referenced //try to shorten the path as much as possible: var firstDomain = this.domain(), secondDomain = u.domain(); // if domains are equal, shorten if ( firstDomain && firstDomain == secondDomain ) { return this.toReferenceFromSameDomain(url); } else { // if there is no domain or not equal, use our path return this.path; } // the path is the same as the folder the page is in } else if ( url === steal.pageUrl().dir() && !expand ) { return this.path; } else if ( this.isLocalAbsolute() ) { // we are a path like /page.js return (u.domain() ? u.protocol() + "//" + u.domain() : "" )+ this.path; } else { //we have 2 relative paths, remove folders with every ../ if ( url === '' ) { return this.path.replace(/\/$/, ''); } var urls = url.split('/'), paths = this.path.split('/'), path = paths[0]; //if we are joining from a folder like cookbook/, remove the last empty part if ( url.match(/\/$/) ) { urls.pop(); } // for each .. remove one folder while ( path == '..' && paths.length > 0 ) { // if we've emptied out, folders, just break // leaving any additional ../s if(! urls.pop() ){ break; } paths.shift(); path = paths[0]; } return urls.concat(paths).join('/'); } }
javascript
function( url, expand ) { var u = File(url); // if this.path is absolutely referenced if ( this.protocol() ) { //if we are absolutely referenced //try to shorten the path as much as possible: var firstDomain = this.domain(), secondDomain = u.domain(); // if domains are equal, shorten if ( firstDomain && firstDomain == secondDomain ) { return this.toReferenceFromSameDomain(url); } else { // if there is no domain or not equal, use our path return this.path; } // the path is the same as the folder the page is in } else if ( url === steal.pageUrl().dir() && !expand ) { return this.path; } else if ( this.isLocalAbsolute() ) { // we are a path like /page.js return (u.domain() ? u.protocol() + "//" + u.domain() : "" )+ this.path; } else { //we have 2 relative paths, remove folders with every ../ if ( url === '' ) { return this.path.replace(/\/$/, ''); } var urls = url.split('/'), paths = this.path.split('/'), path = paths[0]; //if we are joining from a folder like cookbook/, remove the last empty part if ( url.match(/\/$/) ) { urls.pop(); } // for each .. remove one folder while ( path == '..' && paths.length > 0 ) { // if we've emptied out, folders, just break // leaving any additional ../s if(! urls.pop() ){ break; } paths.shift(); path = paths[0]; } return urls.concat(paths).join('/'); } }
[ "function", "(", "url", ",", "expand", ")", "{", "var", "u", "=", "File", "(", "url", ")", ";", "// if this.path is absolutely referenced", "if", "(", "this", ".", "protocol", "(", ")", ")", "{", "//if we are absolutely referenced", "//try to shorten the path as much as possible:", "var", "firstDomain", "=", "this", ".", "domain", "(", ")", ",", "secondDomain", "=", "u", ".", "domain", "(", ")", ";", "// if domains are equal, shorten", "if", "(", "firstDomain", "&&", "firstDomain", "==", "secondDomain", ")", "{", "return", "this", ".", "toReferenceFromSameDomain", "(", "url", ")", ";", "}", "else", "{", "// if there is no domain or not equal, use our path", "return", "this", ".", "path", ";", "}", "// the path is the same as the folder the page is in", "}", "else", "if", "(", "url", "===", "steal", ".", "pageUrl", "(", ")", ".", "dir", "(", ")", "&&", "!", "expand", ")", "{", "return", "this", ".", "path", ";", "}", "else", "if", "(", "this", ".", "isLocalAbsolute", "(", ")", ")", "{", "// we are a path like /page.js", "return", "(", "u", ".", "domain", "(", ")", "?", "u", ".", "protocol", "(", ")", "+", "\"//\"", "+", "u", ".", "domain", "(", ")", ":", "\"\"", ")", "+", "this", ".", "path", ";", "}", "else", "{", "//we have 2 relative paths, remove folders with every ../", "if", "(", "url", "===", "''", ")", "{", "return", "this", ".", "path", ".", "replace", "(", "/", "\\/$", "/", ",", "''", ")", ";", "}", "var", "urls", "=", "url", ".", "split", "(", "'/'", ")", ",", "paths", "=", "this", ".", "path", ".", "split", "(", "'/'", ")", ",", "path", "=", "paths", "[", "0", "]", ";", "//if we are joining from a folder like cookbook/, remove the last empty part", "if", "(", "url", ".", "match", "(", "/", "\\/$", "/", ")", ")", "{", "urls", ".", "pop", "(", ")", ";", "}", "// for each .. remove one folder", "while", "(", "path", "==", "'..'", "&&", "paths", ".", "length", ">", "0", ")", "{", "// if we've emptied out, folders, just break", "// leaving any additional ../s", "if", "(", "!", "urls", ".", "pop", "(", ")", ")", "{", "break", ";", "}", "paths", ".", "shift", "(", ")", ";", "path", "=", "paths", "[", "0", "]", ";", "}", "return", "urls", ".", "concat", "(", "paths", ")", ".", "join", "(", "'/'", ")", ";", "}", "}" ]
Returns the path of this file referenced from another url or path. new steal.File('a/b.c').joinFrom('/d/e')//-> /d/e/a/b.c @param {String} url @param {Boolean} expand if the path should be expanded @return {String}
[ "Returns", "the", "path", "of", "this", "file", "referenced", "from", "another", "url", "or", "path", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L511-L566
17,607
testem/testem
examples/template_stealjs/steal/steal.js
function( url ) { var parts = this.path.split('/'), other_parts = url.split('/'), result = ''; while ( parts.length > 0 && other_parts.length > 0 && parts[0] == other_parts[0] ) { parts.shift(); other_parts.shift(); } each(other_parts, function(){ result += '../'; }) return result + parts.join('/'); }
javascript
function( url ) { var parts = this.path.split('/'), other_parts = url.split('/'), result = ''; while ( parts.length > 0 && other_parts.length > 0 && parts[0] == other_parts[0] ) { parts.shift(); other_parts.shift(); } each(other_parts, function(){ result += '../'; }) return result + parts.join('/'); }
[ "function", "(", "url", ")", "{", "var", "parts", "=", "this", ".", "path", ".", "split", "(", "'/'", ")", ",", "other_parts", "=", "url", ".", "split", "(", "'/'", ")", ",", "result", "=", "''", ";", "while", "(", "parts", ".", "length", ">", "0", "&&", "other_parts", ".", "length", ">", "0", "&&", "parts", "[", "0", "]", "==", "other_parts", "[", "0", "]", ")", "{", "parts", ".", "shift", "(", ")", ";", "other_parts", ".", "shift", "(", ")", ";", "}", "each", "(", "other_parts", ",", "function", "(", ")", "{", "result", "+=", "'../'", ";", "}", ")", "return", "result", "+", "parts", ".", "join", "(", "'/'", ")", ";", "}" ]
Returns the relative path between two paths with common folders. @codestart new steal.File('a/b/c/x/y').toReferenceFromSameDomain('a/b/c/d/e')//-> ../../x/y @codeend @param {Object} url @return {String}
[ "Returns", "the", "relative", "path", "between", "two", "paths", "with", "common", "folders", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L579-L589
17,608
testem/testem
examples/template_stealjs/steal/steal.js
function() { var current = File.cur().dir(), //if you are cross domain from the page, and providing a path that doesn't have an domain path = this.path; if (/^\/\//.test(this.path)) { //if path is rooted from steal's root (DEPRECATED) path = this.path.substr(2); } else if (/^\.\//.test(this.path)) { // should be relative this.path = this.path.substr(2); path = this.joinFrom(current); this.path = "./" + this.path; } else if (/^[^\.|\/]/.test(this.path)) {} else { if (this.relative() || File.cur().isCrossDomain() && //if current file is on another domain and !this.protocol()) { //this file doesn't have a protocol path = this.joinFrom(current); } } return path; }
javascript
function() { var current = File.cur().dir(), //if you are cross domain from the page, and providing a path that doesn't have an domain path = this.path; if (/^\/\//.test(this.path)) { //if path is rooted from steal's root (DEPRECATED) path = this.path.substr(2); } else if (/^\.\//.test(this.path)) { // should be relative this.path = this.path.substr(2); path = this.joinFrom(current); this.path = "./" + this.path; } else if (/^[^\.|\/]/.test(this.path)) {} else { if (this.relative() || File.cur().isCrossDomain() && //if current file is on another domain and !this.protocol()) { //this file doesn't have a protocol path = this.joinFrom(current); } } return path; }
[ "function", "(", ")", "{", "var", "current", "=", "File", ".", "cur", "(", ")", ".", "dir", "(", ")", ",", "//if you are cross domain from the page, and providing a path that doesn't have an domain", "path", "=", "this", ".", "path", ";", "if", "(", "/", "^\\/\\/", "/", ".", "test", "(", "this", ".", "path", ")", ")", "{", "//if path is rooted from steal's root (DEPRECATED) ", "path", "=", "this", ".", "path", ".", "substr", "(", "2", ")", ";", "}", "else", "if", "(", "/", "^\\.\\/", "/", ".", "test", "(", "this", ".", "path", ")", ")", "{", "// should be relative", "this", ".", "path", "=", "this", ".", "path", ".", "substr", "(", "2", ")", ";", "path", "=", "this", ".", "joinFrom", "(", "current", ")", ";", "this", ".", "path", "=", "\"./\"", "+", "this", ".", "path", ";", "}", "else", "if", "(", "/", "^[^\\.|\\/]", "/", ".", "test", "(", "this", ".", "path", ")", ")", "{", "}", "else", "{", "if", "(", "this", ".", "relative", "(", ")", "||", "File", ".", "cur", "(", ")", ".", "isCrossDomain", "(", ")", "&&", "//if current file is on another domain and", "!", "this", ".", "protocol", "(", ")", ")", "{", "//this file doesn't have a protocol", "path", "=", "this", ".", "joinFrom", "(", "current", ")", ";", "}", "}", "return", "path", ";", "}" ]
For a given path, a given working directory, and file location, update the path so it points to a location relative to steal's root. We want everything relative to steal's root so the same app can work in multiple pages. ./files/a.js = steals a.js ./files/a = a/a.js files/a = //files/a/a.js files/a.js = loads //files/a.js
[ "For", "a", "given", "path", "a", "given", "working", "directory", "and", "file", "location", "update", "the", "path", "so", "it", "points", "to", "a", "location", "relative", "to", "steal", "s", "root", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L614-L637
17,609
testem/testem
examples/template_stealjs/steal/steal.js
function(options){ var stel = new steal.p.init(options), rootSrc = stel.options.rootSrc; if(stel.unique && rootSrc){ // the .js is b/c we are not adding that automatically until // load because we defer 'type' determination until then if(!steals[rootSrc] && ! steals[rootSrc+".js"]){ //if we haven't loaded it before steals[rootSrc] = stel; } else{ // already have this steal stel = steals[rootSrc]; // extend the old stolen file with any new options extend(stel.options, typeof options === "string" ? {} : options) } } return stel; }
javascript
function(options){ var stel = new steal.p.init(options), rootSrc = stel.options.rootSrc; if(stel.unique && rootSrc){ // the .js is b/c we are not adding that automatically until // load because we defer 'type' determination until then if(!steals[rootSrc] && ! steals[rootSrc+".js"]){ //if we haven't loaded it before steals[rootSrc] = stel; } else{ // already have this steal stel = steals[rootSrc]; // extend the old stolen file with any new options extend(stel.options, typeof options === "string" ? {} : options) } } return stel; }
[ "function", "(", "options", ")", "{", "var", "stel", "=", "new", "steal", ".", "p", ".", "init", "(", "options", ")", ",", "rootSrc", "=", "stel", ".", "options", ".", "rootSrc", ";", "if", "(", "stel", ".", "unique", "&&", "rootSrc", ")", "{", "// the .js is b/c we are not adding that automatically until", "// load because we defer 'type' determination until then", "if", "(", "!", "steals", "[", "rootSrc", "]", "&&", "!", "steals", "[", "rootSrc", "+", "\".js\"", "]", ")", "{", "//if we haven't loaded it before", "steals", "[", "rootSrc", "]", "=", "stel", ";", "}", "else", "{", "// already have this steal", "stel", "=", "steals", "[", "rootSrc", "]", ";", "// extend the old stolen file with any new options", "extend", "(", "stel", ".", "options", ",", "typeof", "options", "===", "\"string\"", "?", "{", "}", ":", "options", ")", "}", "}", "return", "stel", ";", "}" ]
adds a new steal and throws an error if the script doesn't load this also checks the steals map
[ "adds", "a", "new", "steal", "and", "throws", "an", "error", "if", "the", "script", "doesn", "t", "load", "this", "also", "checks", "the", "steals", "map" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L654-L672
17,610
testem/testem
examples/template_stealjs/steal/steal.js
function(returnScript) { // if we are already loading / loaded if(this.loading || this.isLoaded){ return; } this.loading = true; var self = this; // get yourself steal.require(this.options, function load_calling_loaded(script){ self.loaded(script); }, function(error, src){ win.clearTimeout && win.clearTimeout(self.completeTimeout) throw "steal.js : "+self.options.src+" not completed" }); }
javascript
function(returnScript) { // if we are already loading / loaded if(this.loading || this.isLoaded){ return; } this.loading = true; var self = this; // get yourself steal.require(this.options, function load_calling_loaded(script){ self.loaded(script); }, function(error, src){ win.clearTimeout && win.clearTimeout(self.completeTimeout) throw "steal.js : "+self.options.src+" not completed" }); }
[ "function", "(", "returnScript", ")", "{", "// if we are already loading / loaded", "if", "(", "this", ".", "loading", "||", "this", ".", "isLoaded", ")", "{", "return", ";", "}", "this", ".", "loading", "=", "true", ";", "var", "self", "=", "this", ";", "// get yourself", "steal", ".", "require", "(", "this", ".", "options", ",", "function", "load_calling_loaded", "(", "script", ")", "{", "self", ".", "loaded", "(", "script", ")", ";", "}", ",", "function", "(", "error", ",", "src", ")", "{", "win", ".", "clearTimeout", "&&", "win", ".", "clearTimeout", "(", "self", ".", "completeTimeout", ")", "throw", "\"steal.js : \"", "+", "self", ".", "options", ".", "src", "+", "\" not completed\"", "}", ")", ";", "}" ]
Loads this steal
[ "Loads", "this", "steal" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L864-L879
17,611
testem/testem
examples/template_stealjs/steal/steal.js
function(){ var args = typeof arguments[0] == 'function' ? arguments : [function(){}].concat(makeArray( arguments ) ) return steal.apply(win, args ); }
javascript
function(){ var args = typeof arguments[0] == 'function' ? arguments : [function(){}].concat(makeArray( arguments ) ) return steal.apply(win, args ); }
[ "function", "(", ")", "{", "var", "args", "=", "typeof", "arguments", "[", "0", "]", "==", "'function'", "?", "arguments", ":", "[", "function", "(", ")", "{", "}", "]", ".", "concat", "(", "makeArray", "(", "arguments", ")", ")", "return", "steal", ".", "apply", "(", "win", ",", "args", ")", ";", "}" ]
Calls steal, but waits until all previous steals have completed loading until loading the files passed to the arguments.
[ "Calls", "steal", "but", "waits", "until", "all", "previous", "steals", "have", "completed", "loading", "until", "loading", "the", "files", "passed", "to", "the", "arguments", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L1042-L1046
17,612
testem/testem
examples/template_stealjs/steal/steal.js
function(event, listener){ if(!events[event]){ events[event] = [] } var special = steal.events[event] if(special && special.add){ listener = special.add(listener); } listener && events[event].push(listener); return steal; }
javascript
function(event, listener){ if(!events[event]){ events[event] = [] } var special = steal.events[event] if(special && special.add){ listener = special.add(listener); } listener && events[event].push(listener); return steal; }
[ "function", "(", "event", ",", "listener", ")", "{", "if", "(", "!", "events", "[", "event", "]", ")", "{", "events", "[", "event", "]", "=", "[", "]", "}", "var", "special", "=", "steal", ".", "events", "[", "event", "]", "if", "(", "special", "&&", "special", ".", "add", ")", "{", "listener", "=", "special", ".", "add", "(", "listener", ")", ";", "}", "listener", "&&", "events", "[", "event", "]", ".", "push", "(", "listener", ")", ";", "return", "steal", ";", "}" ]
Listens to events on Steal @param {String} event @param {Function} listener
[ "Listens", "to", "events", "on", "Steal" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L1052-L1062
17,613
testem/testem
examples/template_stealjs/steal/steal.js
function(event, listener){ var evs = events[event] || [], i = 0; while(i < evs.length){ if(listener === evs[i]){ evs.splice(i,1); }else{ i++; } } }
javascript
function(event, listener){ var evs = events[event] || [], i = 0; while(i < evs.length){ if(listener === evs[i]){ evs.splice(i,1); }else{ i++; } } }
[ "function", "(", "event", ",", "listener", ")", "{", "var", "evs", "=", "events", "[", "event", "]", "||", "[", "]", ",", "i", "=", "0", ";", "while", "(", "i", "<", "evs", ".", "length", ")", "{", "if", "(", "listener", "===", "evs", "[", "i", "]", ")", "{", "evs", ".", "splice", "(", "i", ",", "1", ")", ";", "}", "else", "{", "i", "++", ";", "}", "}", "}" ]
Unbinds an event listener on steal @param {Object} event @param {Object} listener
[ "Unbinds", "an", "event", "listener", "on", "steal" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L1076-L1086
17,614
testem/testem
examples/template_stealjs/steal/steal.js
function(name){ // create the steal, mark it as loading, then as loaded var stel = steal.p.make( name ); stel.loading = true; convert(stel, "complete"); steal.preloaded(stel); stel.loaded() return steal; }
javascript
function(name){ // create the steal, mark it as loading, then as loaded var stel = steal.p.make( name ); stel.loading = true; convert(stel, "complete"); steal.preloaded(stel); stel.loaded() return steal; }
[ "function", "(", "name", ")", "{", "// create the steal, mark it as loading, then as loaded", "var", "stel", "=", "steal", ".", "p", ".", "make", "(", "name", ")", ";", "stel", ".", "loading", "=", "true", ";", "convert", "(", "stel", ",", "\"complete\"", ")", ";", "steal", ".", "preloaded", "(", "stel", ")", ";", "stel", ".", "loaded", "(", ")", "return", "steal", ";", "}" ]
called when a script has loaded via production
[ "called", "when", "a", "script", "has", "loaded", "via", "production" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L1114-L1123
17,615
testem/testem
examples/template_stealjs/steal/steal.js
function(script) { script[ STR_ONREADYSTATECHANGE ] = script[ STR_ONLOAD ] = script[STR_ONERROR] = null; head().removeChild( script ); }
javascript
function(script) { script[ STR_ONREADYSTATECHANGE ] = script[ STR_ONLOAD ] = script[STR_ONERROR] = null; head().removeChild( script ); }
[ "function", "(", "script", ")", "{", "script", "[", "STR_ONREADYSTATECHANGE", "]", "=", "script", "[", "STR_ONLOAD", "]", "=", "script", "[", "STR_ONERROR", "]", "=", "null", ";", "head", "(", ")", ".", "removeChild", "(", "script", ")", ";", "}" ]
a clean up script that prevents memory leaks and removes the script
[ "a", "clean", "up", "script", "that", "prevents", "memory", "leaks", "and", "removes", "the", "script" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L1292-L1299
17,616
testem/testem
examples/template_stealjs/steal/steal.js
function(){ // if we don't have a current 'top' steal // we create one and set it up // to start loading its dependencies (the current pending steals) if(! currentCollection ){ currentCollection = new steal.p.init(); // keep a reference in case it disappears var cur = currentCollection, // runs when a steal is starting go = function(){ // indicates that a collection of steals has started steal.trigger("start", cur); when(cur,"complete", function(){ steal.trigger("end", cur); }); cur.loaded(); }; // if we are in rhino, start loading dependencies right away if(!win.setTimeout){ go() }else{ // otherwise wait a small timeout to make // sure we get all steals in the current file setTimeout(go,0) } } }
javascript
function(){ // if we don't have a current 'top' steal // we create one and set it up // to start loading its dependencies (the current pending steals) if(! currentCollection ){ currentCollection = new steal.p.init(); // keep a reference in case it disappears var cur = currentCollection, // runs when a steal is starting go = function(){ // indicates that a collection of steals has started steal.trigger("start", cur); when(cur,"complete", function(){ steal.trigger("end", cur); }); cur.loaded(); }; // if we are in rhino, start loading dependencies right away if(!win.setTimeout){ go() }else{ // otherwise wait a small timeout to make // sure we get all steals in the current file setTimeout(go,0) } } }
[ "function", "(", ")", "{", "// if we don't have a current 'top' steal", "// we create one and set it up", "// to start loading its dependencies (the current pending steals)", "if", "(", "!", "currentCollection", ")", "{", "currentCollection", "=", "new", "steal", ".", "p", ".", "init", "(", ")", ";", "// keep a reference in case it disappears ", "var", "cur", "=", "currentCollection", ",", "// runs when a steal is starting", "go", "=", "function", "(", ")", "{", "// indicates that a collection of steals has started", "steal", ".", "trigger", "(", "\"start\"", ",", "cur", ")", ";", "when", "(", "cur", ",", "\"complete\"", ",", "function", "(", ")", "{", "steal", ".", "trigger", "(", "\"end\"", ",", "cur", ")", ";", "}", ")", ";", "cur", ".", "loaded", "(", ")", ";", "}", ";", "// if we are in rhino, start loading dependencies right away", "if", "(", "!", "win", ".", "setTimeout", ")", "{", "go", "(", ")", "}", "else", "{", "// otherwise wait a small timeout to make ", "// sure we get all steals in the current file", "setTimeout", "(", "go", ",", "0", ")", "}", "}", "}" ]
called after steals are added to the pending queue
[ "called", "after", "steals", "are", "added", "to", "the", "pending", "queue" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L1535-L1562
17,617
testem/testem
examples/template_stealjs/steal/steal.js
function(){ // indicates that a collection of steals has started steal.trigger("start", cur); when(cur,"complete", function(){ steal.trigger("end", cur); }); cur.loaded(); }
javascript
function(){ // indicates that a collection of steals has started steal.trigger("start", cur); when(cur,"complete", function(){ steal.trigger("end", cur); }); cur.loaded(); }
[ "function", "(", ")", "{", "// indicates that a collection of steals has started", "steal", ".", "trigger", "(", "\"start\"", ",", "cur", ")", ";", "when", "(", "cur", ",", "\"complete\"", ",", "function", "(", ")", "{", "steal", ".", "trigger", "(", "\"end\"", ",", "cur", ")", ";", "}", ")", ";", "cur", ".", "loaded", "(", ")", ";", "}" ]
keep a reference in case it disappears
[ "keep", "a", "reference", "in", "case", "it", "disappears" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L1545-L1552
17,618
testem/testem
examples/template_stealjs/steal/steal.js
after
function after(f, after, changeRet){ return changeRet ? function after_CRet(){ return after.apply(this,[f.apply(this,arguments)].concat(makeArray(arguments))); }: function after_Ret(){ var ret = f.apply(this,arguments); after.apply(this,arguments); return ret; } }
javascript
function after(f, after, changeRet){ return changeRet ? function after_CRet(){ return after.apply(this,[f.apply(this,arguments)].concat(makeArray(arguments))); }: function after_Ret(){ var ret = f.apply(this,arguments); after.apply(this,arguments); return ret; } }
[ "function", "after", "(", "f", ",", "after", ",", "changeRet", ")", "{", "return", "changeRet", "?", "function", "after_CRet", "(", ")", "{", "return", "after", ".", "apply", "(", "this", ",", "[", "f", ".", "apply", "(", "this", ",", "arguments", ")", "]", ".", "concat", "(", "makeArray", "(", "arguments", ")", ")", ")", ";", "}", ":", "function", "after_Ret", "(", ")", "{", "var", "ret", "=", "f", ".", "apply", "(", "this", ",", "arguments", ")", ";", "after", ".", "apply", "(", "this", ",", "arguments", ")", ";", "return", "ret", ";", "}", "}" ]
Set up a function that runs after the first param. @param {Object} f @param {Object} after @param {Object} changeRet If true, the result of the function will be passed to the after function as the first param. If false, the after function's params are the same as the original function's params
[ "Set", "up", "a", "function", "that", "runs", "after", "the", "first", "param", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L1642-L1653
17,619
testem/testem
examples/template_stealjs/steal/steal.js
convert
function convert(ob, func){ var oldFunc = ob[func]; // if we don't have callbacks if(!ob[func].callbacks){ //replace start with a function that will call ob2's method ob[func] = function(){ var me = arguments.callee, ret; // call the original function ret = oldFunc.apply(ob,arguments); var cbs = me.callbacks, len = cbs.length; //mark as called so any callees added to this caller will //automatically get called me.called = true; // call other callbacks for(var i =0; i < len; i++){ cbs[i].called() } return ret; } ob[func].callbacks = []; } return ob[func]; }
javascript
function convert(ob, func){ var oldFunc = ob[func]; // if we don't have callbacks if(!ob[func].callbacks){ //replace start with a function that will call ob2's method ob[func] = function(){ var me = arguments.callee, ret; // call the original function ret = oldFunc.apply(ob,arguments); var cbs = me.callbacks, len = cbs.length; //mark as called so any callees added to this caller will //automatically get called me.called = true; // call other callbacks for(var i =0; i < len; i++){ cbs[i].called() } return ret; } ob[func].callbacks = []; } return ob[func]; }
[ "function", "convert", "(", "ob", ",", "func", ")", "{", "var", "oldFunc", "=", "ob", "[", "func", "]", ";", "// if we don't have callbacks", "if", "(", "!", "ob", "[", "func", "]", ".", "callbacks", ")", "{", "//replace start with a function that will call ob2's method", "ob", "[", "func", "]", "=", "function", "(", ")", "{", "var", "me", "=", "arguments", ".", "callee", ",", "ret", ";", "// call the original function", "ret", "=", "oldFunc", ".", "apply", "(", "ob", ",", "arguments", ")", ";", "var", "cbs", "=", "me", ".", "callbacks", ",", "len", "=", "cbs", ".", "length", ";", "//mark as called so any callees added to this caller will", "//automatically get called", "me", ".", "called", "=", "true", ";", "// call other callbacks", "for", "(", "var", "i", "=", "0", ";", "i", "<", "len", ";", "i", "++", ")", "{", "cbs", "[", "i", "]", ".", "called", "(", ")", "}", "return", "ret", ";", "}", "ob", "[", "func", "]", ".", "callbacks", "=", "[", "]", ";", "}", "return", "ob", "[", "func", "]", ";", "}" ]
converts a function to work with when
[ "converts", "a", "function", "to", "work", "with", "when" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L1656-L1687
17,620
testem/testem
examples/template_stealjs/steal/steal.js
function(obj, meth){ // converts the function to be able to call // this join var f = convert(obj, meth); if(!f.called){ // adds us to the callback ... the callback will call // called f.callbacks.push(this); this.calls++; } }
javascript
function(obj, meth){ // converts the function to be able to call // this join var f = convert(obj, meth); if(!f.called){ // adds us to the callback ... the callback will call // called f.callbacks.push(this); this.calls++; } }
[ "function", "(", "obj", ",", "meth", ")", "{", "// converts the function to be able to call ", "// this join", "var", "f", "=", "convert", "(", "obj", ",", "meth", ")", ";", "if", "(", "!", "f", ".", "called", ")", "{", "// adds us to the callback ... the callback will call", "// called", "f", ".", "callbacks", ".", "push", "(", "this", ")", ";", "this", ".", "calls", "++", ";", "}", "}" ]
adds functions that will call this join
[ "adds", "functions", "that", "will", "call", "this", "join" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/steal.js#L1703-L1714
17,621
testem/testem
examples/template_stealjs/funcunit/syn/dist/syn.js
function( event, element, type, autoPrevent ) { // dispatchEvent doesn't always work in IE (mostly in a popup) if ( element.dispatchEvent && event ) { var preventDefault = event.preventDefault, prevents = autoPrevent ? -1 : 0; //automatically prevents the default behavior for this event //this is to protect agianst nasty browser freezing bug in safari if ( autoPrevent ) { bind(element, type, function( ev ) { ev.preventDefault(); unbind(this, type, arguments.callee); }); } event.preventDefault = function() { prevents++; if (++prevents > 0 ) { preventDefault.apply(this, []); } }; element.dispatchEvent(event); return prevents <= 0; } else { try { window.event = event; } catch (e) {} //source element makes sure element is still in the document return element.sourceIndex <= 0 || (element.fireEvent && element.fireEvent('on' + type, event)); } }
javascript
function( event, element, type, autoPrevent ) { // dispatchEvent doesn't always work in IE (mostly in a popup) if ( element.dispatchEvent && event ) { var preventDefault = event.preventDefault, prevents = autoPrevent ? -1 : 0; //automatically prevents the default behavior for this event //this is to protect agianst nasty browser freezing bug in safari if ( autoPrevent ) { bind(element, type, function( ev ) { ev.preventDefault(); unbind(this, type, arguments.callee); }); } event.preventDefault = function() { prevents++; if (++prevents > 0 ) { preventDefault.apply(this, []); } }; element.dispatchEvent(event); return prevents <= 0; } else { try { window.event = event; } catch (e) {} //source element makes sure element is still in the document return element.sourceIndex <= 0 || (element.fireEvent && element.fireEvent('on' + type, event)); } }
[ "function", "(", "event", ",", "element", ",", "type", ",", "autoPrevent", ")", "{", "// dispatchEvent doesn't always work in IE (mostly in a popup)", "if", "(", "element", ".", "dispatchEvent", "&&", "event", ")", "{", "var", "preventDefault", "=", "event", ".", "preventDefault", ",", "prevents", "=", "autoPrevent", "?", "-", "1", ":", "0", ";", "//automatically prevents the default behavior for this event", "//this is to protect agianst nasty browser freezing bug in safari", "if", "(", "autoPrevent", ")", "{", "bind", "(", "element", ",", "type", ",", "function", "(", "ev", ")", "{", "ev", ".", "preventDefault", "(", ")", ";", "unbind", "(", "this", ",", "type", ",", "arguments", ".", "callee", ")", ";", "}", ")", ";", "}", "event", ".", "preventDefault", "=", "function", "(", ")", "{", "prevents", "++", ";", "if", "(", "++", "prevents", ">", "0", ")", "{", "preventDefault", ".", "apply", "(", "this", ",", "[", "]", ")", ";", "}", "}", ";", "element", ".", "dispatchEvent", "(", "event", ")", ";", "return", "prevents", "<=", "0", ";", "}", "else", "{", "try", "{", "window", ".", "event", "=", "event", ";", "}", "catch", "(", "e", ")", "{", "}", "//source element makes sure element is still in the document", "return", "element", ".", "sourceIndex", "<=", "0", "||", "(", "element", ".", "fireEvent", "&&", "element", ".", "fireEvent", "(", "'on'", "+", "type", ",", "event", ")", ")", ";", "}", "}" ]
triggers an event on an element, returns true if default events should be run Dispatches an event and returns true if default events should be run. @hide @param {Object} event @param {Object} element @param {Object} type @param {Object} autoPrevent
[ "triggers", "an", "event", "on", "an", "element", "returns", "true", "if", "default", "events", "should", "be", "run", "Dispatches", "an", "event", "and", "returns", "true", "if", "default", "events", "should", "be", "run", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/dist/syn.js#L438-L470
17,622
testem/testem
examples/template_stealjs/funcunit/syn/dist/syn.js
function( timeout, callback ) { if ( typeof timeout === 'function' ) { callback = timeout; timeout = null; } timeout = timeout || 600; var self = this; this.queue.unshift(function() { setTimeout(function() { callback && callback.apply(self, []) self.done.apply(self, arguments); }, timeout); }); return this; }
javascript
function( timeout, callback ) { if ( typeof timeout === 'function' ) { callback = timeout; timeout = null; } timeout = timeout || 600; var self = this; this.queue.unshift(function() { setTimeout(function() { callback && callback.apply(self, []) self.done.apply(self, arguments); }, timeout); }); return this; }
[ "function", "(", "timeout", ",", "callback", ")", "{", "if", "(", "typeof", "timeout", "===", "'function'", ")", "{", "callback", "=", "timeout", ";", "timeout", "=", "null", ";", "}", "timeout", "=", "timeout", "||", "600", ";", "var", "self", "=", "this", ";", "this", ".", "queue", ".", "unshift", "(", "function", "(", ")", "{", "setTimeout", "(", "function", "(", ")", "{", "callback", "&&", "callback", ".", "apply", "(", "self", ",", "[", "]", ")", "self", ".", "done", ".", "apply", "(", "self", ",", "arguments", ")", ";", "}", ",", "timeout", ")", ";", "}", ")", ";", "return", "this", ";", "}" ]
Delays the next command a set timeout. @param {Number} [timeout] @param {Function} [callback]
[ "Delays", "the", "next", "command", "a", "set", "timeout", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/dist/syn.js#L681-L695
17,623
testem/testem
examples/template_stealjs/funcunit/syn/dist/syn.js
function( keyCode ) { var specials = S.key.kinds.special; for ( var i = 0; i < specials.length; i++ ) { if ( Syn.keycodes[specials[i]] == keyCode ) { return specials[i]; } } }
javascript
function( keyCode ) { var specials = S.key.kinds.special; for ( var i = 0; i < specials.length; i++ ) { if ( Syn.keycodes[specials[i]] == keyCode ) { return specials[i]; } } }
[ "function", "(", "keyCode", ")", "{", "var", "specials", "=", "S", ".", "key", ".", "kinds", ".", "special", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "specials", ".", "length", ";", "i", "++", ")", "{", "if", "(", "Syn", ".", "keycodes", "[", "specials", "[", "i", "]", "]", "==", "keyCode", ")", "{", "return", "specials", "[", "i", "]", ";", "}", "}", "}" ]
returns the special key if special
[ "returns", "the", "special", "key", "if", "special" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/dist/syn.js#L1576-L1583
17,624
testem/testem
examples/template_stealjs/funcunit/syn/dist/syn.js
function( key ) { //check if it is described directly if ( Syn.key.defaults[key] ) { return Syn.key.defaults[key]; } for ( var kind in Syn.key.kinds ) { if ( h.inArray(key, Syn.key.kinds[kind]) > -1 && Syn.key.defaults[kind] ) { return Syn.key.defaults[kind]; } } return Syn.key.defaults.character }
javascript
function( key ) { //check if it is described directly if ( Syn.key.defaults[key] ) { return Syn.key.defaults[key]; } for ( var kind in Syn.key.kinds ) { if ( h.inArray(key, Syn.key.kinds[kind]) > -1 && Syn.key.defaults[kind] ) { return Syn.key.defaults[kind]; } } return Syn.key.defaults.character }
[ "function", "(", "key", ")", "{", "//check if it is described directly", "if", "(", "Syn", ".", "key", ".", "defaults", "[", "key", "]", ")", "{", "return", "Syn", ".", "key", ".", "defaults", "[", "key", "]", ";", "}", "for", "(", "var", "kind", "in", "Syn", ".", "key", ".", "kinds", ")", "{", "if", "(", "h", ".", "inArray", "(", "key", ",", "Syn", ".", "key", ".", "kinds", "[", "kind", "]", ")", ">", "-", "1", "&&", "Syn", ".", "key", ".", "defaults", "[", "kind", "]", ")", "{", "return", "Syn", ".", "key", ".", "defaults", "[", "kind", "]", ";", "}", "}", "return", "Syn", ".", "key", ".", "defaults", ".", "character", "}" ]
returns the default function
[ "returns", "the", "default", "function" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/dist/syn.js#L1627-L1638
17,625
testem/testem
examples/template_stealjs/funcunit/syn/dist/syn.js
function( type, options, element ) { //Everyone Else var doc = h.getWindow(element).document || document; if ( doc.createEvent ) { var event; try { event = doc.createEvent("KeyEvents"); event.initKeyEvent(type, true, true, window, options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.keyCode, options.charCode); } catch (e) { event = h.createBasicStandardEvent(type, options, doc); } event.synthetic = true; return event; } else { var event; try { event = h.createEventObject.apply(this, arguments); h.extend(event, options) } catch (e) {} return event; } }
javascript
function( type, options, element ) { //Everyone Else var doc = h.getWindow(element).document || document; if ( doc.createEvent ) { var event; try { event = doc.createEvent("KeyEvents"); event.initKeyEvent(type, true, true, window, options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.keyCode, options.charCode); } catch (e) { event = h.createBasicStandardEvent(type, options, doc); } event.synthetic = true; return event; } else { var event; try { event = h.createEventObject.apply(this, arguments); h.extend(event, options) } catch (e) {} return event; } }
[ "function", "(", "type", ",", "options", ",", "element", ")", "{", "//Everyone Else", "var", "doc", "=", "h", ".", "getWindow", "(", "element", ")", ".", "document", "||", "document", ";", "if", "(", "doc", ".", "createEvent", ")", "{", "var", "event", ";", "try", "{", "event", "=", "doc", ".", "createEvent", "(", "\"KeyEvents\"", ")", ";", "event", ".", "initKeyEvent", "(", "type", ",", "true", ",", "true", ",", "window", ",", "options", ".", "ctrlKey", ",", "options", ".", "altKey", ",", "options", ".", "shiftKey", ",", "options", ".", "metaKey", ",", "options", ".", "keyCode", ",", "options", ".", "charCode", ")", ";", "}", "catch", "(", "e", ")", "{", "event", "=", "h", ".", "createBasicStandardEvent", "(", "type", ",", "options", ",", "doc", ")", ";", "}", "event", ".", "synthetic", "=", "true", ";", "return", "event", ";", "}", "else", "{", "var", "event", ";", "try", "{", "event", "=", "h", ".", "createEventObject", ".", "apply", "(", "this", ",", "arguments", ")", ";", "h", ".", "extend", "(", "event", ",", "options", ")", "}", "catch", "(", "e", ")", "{", "}", "return", "event", ";", "}", "}" ]
creates a key event
[ "creates", "a", "key", "event" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/dist/syn.js#L1927-L1953
17,626
testem/testem
examples/template_stealjs/funcunit/syn/dist/syn.js
function( runDefaults, el ) { var part = parts.shift(); if (!part ) { callback(runDefaults, el); return; } el = el || element; if ( part.length > 1 ) { part = part.substr(1, part.length - 2) } self._key(part, el, runNextPart) }
javascript
function( runDefaults, el ) { var part = parts.shift(); if (!part ) { callback(runDefaults, el); return; } el = el || element; if ( part.length > 1 ) { part = part.substr(1, part.length - 2) } self._key(part, el, runNextPart) }
[ "function", "(", "runDefaults", ",", "el", ")", "{", "var", "part", "=", "parts", ".", "shift", "(", ")", ";", "if", "(", "!", "part", ")", "{", "callback", "(", "runDefaults", ",", "el", ")", ";", "return", ";", "}", "el", "=", "el", "||", "element", ";", "if", "(", "part", ".", "length", ">", "1", ")", "{", "part", "=", "part", ".", "substr", "(", "1", ",", "part", ".", "length", "-", "2", ")", "}", "self", ".", "_key", "(", "part", ",", "el", ",", "runNextPart", ")", "}" ]
break it up into parts ... go through each type and run
[ "break", "it", "up", "into", "parts", "...", "go", "through", "each", "type", "and", "run" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/dist/syn.js#L2076-L2087
17,627
testem/testem
lib/browser_launcher.js
getAvailableBrowsers
function getAvailableBrowsers(config, browsers, cb) { browsers.forEach(function(b) { b.protocol = 'browser'; }); return Bluebird.filter(browsers, function(browser) { return isInstalled(browser, config).then(function(result) { if (!result) { return false; } browser.exe = result; return true; }); }).asCallback(cb); }
javascript
function getAvailableBrowsers(config, browsers, cb) { browsers.forEach(function(b) { b.protocol = 'browser'; }); return Bluebird.filter(browsers, function(browser) { return isInstalled(browser, config).then(function(result) { if (!result) { return false; } browser.exe = result; return true; }); }).asCallback(cb); }
[ "function", "getAvailableBrowsers", "(", "config", ",", "browsers", ",", "cb", ")", "{", "browsers", ".", "forEach", "(", "function", "(", "b", ")", "{", "b", ".", "protocol", "=", "'browser'", ";", "}", ")", ";", "return", "Bluebird", ".", "filter", "(", "browsers", ",", "function", "(", "browser", ")", "{", "return", "isInstalled", "(", "browser", ",", "config", ")", ".", "then", "(", "function", "(", "result", ")", "{", "if", "(", "!", "result", ")", "{", "return", "false", ";", "}", "browser", ".", "exe", "=", "result", ";", "return", "true", ";", "}", ")", ";", "}", ")", ".", "asCallback", "(", "cb", ")", ";", "}" ]
Returns the available browsers on the current machine.
[ "Returns", "the", "available", "browsers", "on", "the", "current", "machine", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/lib/browser_launcher.js#L22-L37
17,628
testem/testem
examples/template_stealjs/funcunit/browser/actions.js
function( direction, amount, success ) { this._addExists(); var selector = this.selector, context = this.context, direction; if (direction == "left" || direction == "right") { direction = "Left"; } else if (direction == "top" || direction == "bottom") { direction = "Top"; } FuncUnit.add({ method: function(success, error){ steal.dev.log("setting " + selector + " scroll" + direction + " " + amount + " pixels") this.bind.each(function(i, el){ this["scroll" + direction] = amount; }) success(); }, success: success, error: "Could not scroll " + this.selector, bind: this, type: "action" }); return this; }
javascript
function( direction, amount, success ) { this._addExists(); var selector = this.selector, context = this.context, direction; if (direction == "left" || direction == "right") { direction = "Left"; } else if (direction == "top" || direction == "bottom") { direction = "Top"; } FuncUnit.add({ method: function(success, error){ steal.dev.log("setting " + selector + " scroll" + direction + " " + amount + " pixels") this.bind.each(function(i, el){ this["scroll" + direction] = amount; }) success(); }, success: success, error: "Could not scroll " + this.selector, bind: this, type: "action" }); return this; }
[ "function", "(", "direction", ",", "amount", ",", "success", ")", "{", "this", ".", "_addExists", "(", ")", ";", "var", "selector", "=", "this", ".", "selector", ",", "context", "=", "this", ".", "context", ",", "direction", ";", "if", "(", "direction", "==", "\"left\"", "||", "direction", "==", "\"right\"", ")", "{", "direction", "=", "\"Left\"", ";", "}", "else", "if", "(", "direction", "==", "\"top\"", "||", "direction", "==", "\"bottom\"", ")", "{", "direction", "=", "\"Top\"", ";", "}", "FuncUnit", ".", "add", "(", "{", "method", ":", "function", "(", "success", ",", "error", ")", "{", "steal", ".", "dev", ".", "log", "(", "\"setting \"", "+", "selector", "+", "\" scroll\"", "+", "direction", "+", "\" \"", "+", "amount", "+", "\" pixels\"", ")", "this", ".", "bind", ".", "each", "(", "function", "(", "i", ",", "el", ")", "{", "this", "[", "\"scroll\"", "+", "direction", "]", "=", "amount", ";", "}", ")", "success", "(", ")", ";", "}", ",", "success", ":", "success", ",", "error", ":", "\"Could not scroll \"", "+", "this", ".", "selector", ",", "bind", ":", "this", ",", "type", ":", "\"action\"", "}", ")", ";", "return", "this", ";", "}" ]
Scrolls an element in a particular direction by setting the scrollTop or srollLeft. @param {String} direction "left" or "top" @param {Number} amount number of pixels to scroll @param {Function} success
[ "Scrolls", "an", "element", "in", "a", "particular", "direction", "by", "setting", "the", "scrollTop", "or", "srollLeft", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/browser/actions.js#L277-L301
17,629
testem/testem
examples/template_stealjs/funcunit/syn/demo/record.js
function( target ) { var selector = target.nodeName.toLowerCase(); if(target.id){ return "#"+target.id }else{ var parent = target.parentNode; while(parent){ if(parent.id){ selector = "#"+parent.id+" "+selector; break; }else{ parent = parent.parentNode } } } if(target.className){ selector += "."+target.className.split(" ")[0] } var others = jQuery(selector, Syn.helpers.getWindow(target).document) if(others.length > 1){ return selector+":eq("+others.index(target)+")"; }else{ return selector; } }
javascript
function( target ) { var selector = target.nodeName.toLowerCase(); if(target.id){ return "#"+target.id }else{ var parent = target.parentNode; while(parent){ if(parent.id){ selector = "#"+parent.id+" "+selector; break; }else{ parent = parent.parentNode } } } if(target.className){ selector += "."+target.className.split(" ")[0] } var others = jQuery(selector, Syn.helpers.getWindow(target).document) if(others.length > 1){ return selector+":eq("+others.index(target)+")"; }else{ return selector; } }
[ "function", "(", "target", ")", "{", "var", "selector", "=", "target", ".", "nodeName", ".", "toLowerCase", "(", ")", ";", "if", "(", "target", ".", "id", ")", "{", "return", "\"#\"", "+", "target", ".", "id", "}", "else", "{", "var", "parent", "=", "target", ".", "parentNode", ";", "while", "(", "parent", ")", "{", "if", "(", "parent", ".", "id", ")", "{", "selector", "=", "\"#\"", "+", "parent", ".", "id", "+", "\" \"", "+", "selector", ";", "break", ";", "}", "else", "{", "parent", "=", "parent", ".", "parentNode", "}", "}", "}", "if", "(", "target", ".", "className", ")", "{", "selector", "+=", "\".\"", "+", "target", ".", "className", ".", "split", "(", "\" \"", ")", "[", "0", "]", "}", "var", "others", "=", "jQuery", "(", "selector", ",", "Syn", ".", "helpers", ".", "getWindow", "(", "target", ")", ".", "document", ")", "if", "(", "others", ".", "length", ">", "1", ")", "{", "return", "selector", "+", "\":eq(\"", "+", "others", ".", "index", "(", "target", ")", "+", "\")\"", ";", "}", "else", "{", "return", "selector", ";", "}", "}" ]
returns a selector
[ "returns", "a", "selector" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/demo/record.js#L132-L158
17,630
testem/testem
examples/template_stealjs/funcunit/browser/waits.js
function( timeout, success, message ) { var logMessage = "Waiting for '"+this.selector+"' to exist"; if(timeout === false){ // pass false to suppress this wait (make it not print any logMessage) logMessage = false } return this.size({ condition: function(size){ return size > 0; }, timeout: timeout, success: success, message: message, errorMessage: "Exist failed: element with selector '"+this.selector+"' not found", logMessage: logMessage }) }
javascript
function( timeout, success, message ) { var logMessage = "Waiting for '"+this.selector+"' to exist"; if(timeout === false){ // pass false to suppress this wait (make it not print any logMessage) logMessage = false } return this.size({ condition: function(size){ return size > 0; }, timeout: timeout, success: success, message: message, errorMessage: "Exist failed: element with selector '"+this.selector+"' not found", logMessage: logMessage }) }
[ "function", "(", "timeout", ",", "success", ",", "message", ")", "{", "var", "logMessage", "=", "\"Waiting for '\"", "+", "this", ".", "selector", "+", "\"' to exist\"", ";", "if", "(", "timeout", "===", "false", ")", "{", "// pass false to suppress this wait (make it not print any logMessage)", "logMessage", "=", "false", "}", "return", "this", ".", "size", "(", "{", "condition", ":", "function", "(", "size", ")", "{", "return", "size", ">", "0", ";", "}", ",", "timeout", ":", "timeout", ",", "success", ":", "success", ",", "message", ":", "message", ",", "errorMessage", ":", "\"Exist failed: element with selector '\"", "+", "this", ".", "selector", "+", "\"' not found\"", ",", "logMessage", ":", "logMessage", "}", ")", "}" ]
Waits until an element exists before running the next action. @codestart //waits until #foo exists before clicking it. S("#foo").exists().click() @codeend @param {Number} [timeout] overrides FuncUnit.timeout. If provided, the wait will fail if not completed before this timeout. @param {Function} [success] a success that is run after the selector exists, but before the next action. @param {String} [message] if provided, an assertion will be passed when this wait condition completes successfully @return {FuncUnit} returns the funcUnit for chaining.
[ "Waits", "until", "an", "element", "exists", "before", "running", "the", "next", "action", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/browser/waits.js#L162-L177
17,631
testem/testem
examples/template_stealjs/funcunit/browser/waits.js
function( timeout, success, message ) { var self = this, sel = this.selector, ret; return this.size(function(size){ return this.is(":visible") === true; }, timeout, success, message) }
javascript
function( timeout, success, message ) { var self = this, sel = this.selector, ret; return this.size(function(size){ return this.is(":visible") === true; }, timeout, success, message) }
[ "function", "(", "timeout", ",", "success", ",", "message", ")", "{", "var", "self", "=", "this", ",", "sel", "=", "this", ".", "selector", ",", "ret", ";", "return", "this", ".", "size", "(", "function", "(", "size", ")", "{", "return", "this", ".", "is", "(", "\":visible\"", ")", "===", "true", ";", "}", ",", "timeout", ",", "success", ",", "message", ")", "}" ]
Waits until the funcUnit selector is visible. @codestart //waits until #foo is visible. S("#foo").visible() @codeend @param {Number} [timeout] overrides FuncUnit.timeout. If provided, the wait will fail if not completed before this timeout. @param {Function} [success] a callback that runs after the funcUnit is visible, but before the next action. @param {String} [message] if provided, an assertion will be passed when this wait condition completes successfully @return [funcUnit] returns the funcUnit for chaining.
[ "Waits", "until", "the", "funcUnit", "selector", "is", "visible", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/browser/waits.js#L204-L211
17,632
testem/testem
examples/template_stealjs/funcunit/browser/open.js
function(){ var loaded = FuncUnit.win.document.readyState === "complete" && FuncUnit.win.location.href != "about:blank" && FuncUnit.win.document.body; return loaded; }
javascript
function(){ var loaded = FuncUnit.win.document.readyState === "complete" && FuncUnit.win.location.href != "about:blank" && FuncUnit.win.document.body; return loaded; }
[ "function", "(", ")", "{", "var", "loaded", "=", "FuncUnit", ".", "win", ".", "document", ".", "readyState", "===", "\"complete\"", "&&", "FuncUnit", ".", "win", ".", "location", ".", "href", "!=", "\"about:blank\"", "&&", "FuncUnit", ".", "win", ".", "document", ".", "body", ";", "return", "loaded", ";", "}" ]
return true if document is currently loaded, false if its loading actions check this
[ "return", "true", "if", "document", "is", "currently", "loaded", "false", "if", "its", "loading", "actions", "check", "this" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/browser/open.js#L249-L254
17,633
testem/testem
examples/template_stealjs/steal/dev/dev.js
function( out ) { if(steal.options.logLevel < 2){ Array.prototype.unshift.call(arguments, 'steal.js WARN:'); if ( window.console && console.warn ) { this._logger( "warn", Array.prototype.slice.call(arguments) ); } else if ( window.console && console.log ) { this._logger( "log", Array.prototype.slice.call(arguments) ); } else if ( window.opera && window.opera.postError ) { opera.postError("steal.js WARNING: " + out); } } }
javascript
function( out ) { if(steal.options.logLevel < 2){ Array.prototype.unshift.call(arguments, 'steal.js WARN:'); if ( window.console && console.warn ) { this._logger( "warn", Array.prototype.slice.call(arguments) ); } else if ( window.console && console.log ) { this._logger( "log", Array.prototype.slice.call(arguments) ); } else if ( window.opera && window.opera.postError ) { opera.postError("steal.js WARNING: " + out); } } }
[ "function", "(", "out", ")", "{", "if", "(", "steal", ".", "options", ".", "logLevel", "<", "2", ")", "{", "Array", ".", "prototype", ".", "unshift", ".", "call", "(", "arguments", ",", "'steal.js WARN:'", ")", ";", "if", "(", "window", ".", "console", "&&", "console", ".", "warn", ")", "{", "this", ".", "_logger", "(", "\"warn\"", ",", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ")", ")", ";", "}", "else", "if", "(", "window", ".", "console", "&&", "console", ".", "log", ")", "{", "this", ".", "_logger", "(", "\"log\"", ",", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ")", ")", ";", "}", "else", "if", "(", "window", ".", "opera", "&&", "window", ".", "opera", ".", "postError", ")", "{", "opera", ".", "postError", "(", "\"steal.js WARNING: \"", "+", "out", ")", ";", "}", "}", "}" ]
Adds a warning message to the console. @codestart steal.dev.warn("something evil"); @codeend @param {String} out the message
[ "Adds", "a", "warning", "message", "to", "the", "console", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/steal/dev/dev.js#L52-L64
17,634
testem/testem
lib/utils/process.js
kill
function kill(p, sig) { if (isWin) { let command = 'taskkill.exe'; let args = ['/t', '/pid', p.pid]; if (sig === 'SIGKILL') { args.push('/f'); } execa(command, args).then(result => { // Processes without windows can't be killed without /F, detect and force // kill them directly if (result.stderr.indexOf('can only be terminated forcefully') !== -1) { kill(p, 'SIGKILL'); } }).catch(err => { log.error(err); }); } else { p.kill(sig); } }
javascript
function kill(p, sig) { if (isWin) { let command = 'taskkill.exe'; let args = ['/t', '/pid', p.pid]; if (sig === 'SIGKILL') { args.push('/f'); } execa(command, args).then(result => { // Processes without windows can't be killed without /F, detect and force // kill them directly if (result.stderr.indexOf('can only be terminated forcefully') !== -1) { kill(p, 'SIGKILL'); } }).catch(err => { log.error(err); }); } else { p.kill(sig); } }
[ "function", "kill", "(", "p", ",", "sig", ")", "{", "if", "(", "isWin", ")", "{", "let", "command", "=", "'taskkill.exe'", ";", "let", "args", "=", "[", "'/t'", ",", "'/pid'", ",", "p", ".", "pid", "]", ";", "if", "(", "sig", "===", "'SIGKILL'", ")", "{", "args", ".", "push", "(", "'/f'", ")", ";", "}", "execa", "(", "command", ",", "args", ")", ".", "then", "(", "result", "=>", "{", "// Processes without windows can't be killed without /F, detect and force", "// kill them directly", "if", "(", "result", ".", "stderr", ".", "indexOf", "(", "'can only be terminated forcefully'", ")", "!==", "-", "1", ")", "{", "kill", "(", "p", ",", "'SIGKILL'", ")", ";", "}", "}", ")", ".", "catch", "(", "err", "=>", "{", "log", ".", "error", "(", "err", ")", ";", "}", ")", ";", "}", "else", "{", "p", ".", "kill", "(", "sig", ")", ";", "}", "}" ]
Kill process and all child processes cross platform
[ "Kill", "process", "and", "all", "child", "processes", "cross", "platform" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/lib/utils/process.js#L119-L139
17,635
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function( f ) { var i, vec, newArr = []; for ( i = 0; i < this.array.length; i++ ) { newArr.push(f(this.array[i])); } vec = new $.Vector(); return vec.update(newArr); }
javascript
function( f ) { var i, vec, newArr = []; for ( i = 0; i < this.array.length; i++ ) { newArr.push(f(this.array[i])); } vec = new $.Vector(); return vec.update(newArr); }
[ "function", "(", "f", ")", "{", "var", "i", ",", "vec", ",", "newArr", "=", "[", "]", ";", "for", "(", "i", "=", "0", ";", "i", "<", "this", ".", "array", ".", "length", ";", "i", "++", ")", "{", "newArr", ".", "push", "(", "f", "(", "this", ".", "array", "[", "i", "]", ")", ")", ";", "}", "vec", "=", "new", "$", ".", "Vector", "(", ")", ";", "return", "vec", ".", "update", "(", "newArr", ")", ";", "}" ]
Applys the function to every item in the vector. Returns the new vector. @param {Function} f @return {jQuery.Vector} new vector class.
[ "Applys", "the", "function", "to", "every", "item", "in", "the", "vector", ".", "Returns", "the", "new", "vector", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L28-L36
17,636
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function() { var i, args = arguments[0] instanceof $.Vector ? arguments[0].array : $.makeArray(arguments), arr = this.array.slice(0), vec = new $.Vector(); for ( i = 0; i < args.length; i++ ) { if ( arr[i] != args[i] ) { return null; } } return vec.update(arr); }
javascript
function() { var i, args = arguments[0] instanceof $.Vector ? arguments[0].array : $.makeArray(arguments), arr = this.array.slice(0), vec = new $.Vector(); for ( i = 0; i < args.length; i++ ) { if ( arr[i] != args[i] ) { return null; } } return vec.update(arr); }
[ "function", "(", ")", "{", "var", "i", ",", "args", "=", "arguments", "[", "0", "]", "instanceof", "$", ".", "Vector", "?", "arguments", "[", "0", "]", ".", "array", ":", "$", ".", "makeArray", "(", "arguments", ")", ",", "arr", "=", "this", ".", "array", ".", "slice", "(", "0", ")", ",", "vec", "=", "new", "$", ".", "Vector", "(", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "if", "(", "arr", "[", "i", "]", "!=", "args", "[", "i", "]", ")", "{", "return", "null", ";", "}", "}", "return", "vec", ".", "update", "(", "arr", ")", ";", "}" ]
Returns the current vector if it is equal to the vector passed in. False if otherwise. @return {jQuery.Vector}
[ "Returns", "the", "current", "vector", "if", "it", "is", "equal", "to", "the", "vector", "passed", "in", ".", "False", "if", "otherwise", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L72-L82
17,637
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function( array ) { var i; if ( this.array ) { for ( i = 0; i < this.array.length; i++ ) { delete this.array[i]; } } this.array = array; for ( i = 0; i < array.length; i++ ) { this[i] = this.array[i]; } return this; }
javascript
function( array ) { var i; if ( this.array ) { for ( i = 0; i < this.array.length; i++ ) { delete this.array[i]; } } this.array = array; for ( i = 0; i < array.length; i++ ) { this[i] = this.array[i]; } return this; }
[ "function", "(", "array", ")", "{", "var", "i", ";", "if", "(", "this", ".", "array", ")", "{", "for", "(", "i", "=", "0", ";", "i", "<", "this", ".", "array", ".", "length", ";", "i", "++", ")", "{", "delete", "this", ".", "array", "[", "i", "]", ";", "}", "}", "this", ".", "array", "=", "array", ";", "for", "(", "i", "=", "0", ";", "i", "<", "array", ".", "length", ";", "i", "++", ")", "{", "this", "[", "i", "]", "=", "this", ".", "array", "[", "i", "]", ";", "}", "return", "this", ";", "}" ]
Replaces the vectors contents @param {Object} array
[ "Replaces", "the", "vectors", "contents" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L116-L128
17,638
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function( ev, element ) { var isLeftButton = ev.button === 0 || ev.button == 1; if (!isLeftButton || this.current ) { return; } //only allows 1 drag at a time, but in future could allow more //ev.preventDefault(); //create Drag var drag = new $.Drag(), delegate = ev.liveFired || element, selector = ev.handleObj.selector, self = this; this.current = drag; drag.setup({ element: element, delegate: ev.liveFired || element, selector: ev.handleObj.selector, moved: false, callbacks: { dragdown: event.find(delegate, ["dragdown"], selector), draginit: event.find(delegate, ["draginit"], selector), dragover: event.find(delegate, ["dragover"], selector), dragmove: event.find(delegate, ["dragmove"], selector), dragout: event.find(delegate, ["dragout"], selector), dragend: event.find(delegate, ["dragend"], selector) }, destroyed: function() { self.current = null; } }, ev); }
javascript
function( ev, element ) { var isLeftButton = ev.button === 0 || ev.button == 1; if (!isLeftButton || this.current ) { return; } //only allows 1 drag at a time, but in future could allow more //ev.preventDefault(); //create Drag var drag = new $.Drag(), delegate = ev.liveFired || element, selector = ev.handleObj.selector, self = this; this.current = drag; drag.setup({ element: element, delegate: ev.liveFired || element, selector: ev.handleObj.selector, moved: false, callbacks: { dragdown: event.find(delegate, ["dragdown"], selector), draginit: event.find(delegate, ["draginit"], selector), dragover: event.find(delegate, ["dragover"], selector), dragmove: event.find(delegate, ["dragmove"], selector), dragout: event.find(delegate, ["dragout"], selector), dragend: event.find(delegate, ["dragend"], selector) }, destroyed: function() { self.current = null; } }, ev); }
[ "function", "(", "ev", ",", "element", ")", "{", "var", "isLeftButton", "=", "ev", ".", "button", "===", "0", "||", "ev", ".", "button", "==", "1", ";", "if", "(", "!", "isLeftButton", "||", "this", ".", "current", ")", "{", "return", ";", "}", "//only allows 1 drag at a time, but in future could allow more", "//ev.preventDefault();", "//create Drag", "var", "drag", "=", "new", "$", ".", "Drag", "(", ")", ",", "delegate", "=", "ev", ".", "liveFired", "||", "element", ",", "selector", "=", "ev", ".", "handleObj", ".", "selector", ",", "self", "=", "this", ";", "this", ".", "current", "=", "drag", ";", "drag", ".", "setup", "(", "{", "element", ":", "element", ",", "delegate", ":", "ev", ".", "liveFired", "||", "element", ",", "selector", ":", "ev", ".", "handleObj", ".", "selector", ",", "moved", ":", "false", ",", "callbacks", ":", "{", "dragdown", ":", "event", ".", "find", "(", "delegate", ",", "[", "\"dragdown\"", "]", ",", "selector", ")", ",", "draginit", ":", "event", ".", "find", "(", "delegate", ",", "[", "\"draginit\"", "]", ",", "selector", ")", ",", "dragover", ":", "event", ".", "find", "(", "delegate", ",", "[", "\"dragover\"", "]", ",", "selector", ")", ",", "dragmove", ":", "event", ".", "find", "(", "delegate", ",", "[", "\"dragmove\"", "]", ",", "selector", ")", ",", "dragout", ":", "event", ".", "find", "(", "delegate", ",", "[", "\"dragout\"", "]", ",", "selector", ")", ",", "dragend", ":", "event", ".", "find", "(", "delegate", ",", "[", "\"dragend\"", "]", ",", "selector", ")", "}", ",", "destroyed", ":", "function", "(", ")", "{", "self", ".", "current", "=", "null", ";", "}", "}", ",", "ev", ")", ";", "}" ]
Called when someone mouses down on a draggable object. Gathers all callback functions and creates a new Draggable. @hide
[ "Called", "when", "someone", "mouses", "down", "on", "a", "draggable", "object", ".", "Gathers", "all", "callback", "functions", "and", "creates", "a", "new", "Draggable", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L412-L442
17,639
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function() { $(document).unbind('mousemove', this._mousemove); $(document).unbind('mouseup', this._mouseup); if (!this.moved ) { this.event = this.element = null; } //this.selection(); this.destroyed(); }
javascript
function() { $(document).unbind('mousemove', this._mousemove); $(document).unbind('mouseup', this._mouseup); if (!this.moved ) { this.event = this.element = null; } //this.selection(); this.destroyed(); }
[ "function", "(", ")", "{", "$", "(", "document", ")", ".", "unbind", "(", "'mousemove'", ",", "this", ".", "_mousemove", ")", ";", "$", "(", "document", ")", ".", "unbind", "(", "'mouseup'", ",", "this", ".", "_mouseup", ")", ";", "if", "(", "!", "this", ".", "moved", ")", "{", "this", ".", "event", "=", "this", ".", "element", "=", "null", ";", "}", "//this.selection();", "this", ".", "destroyed", "(", ")", ";", "}" ]
Unbinds listeners and allows other drags ... @hide
[ "Unbinds", "listeners", "and", "allows", "other", "drags", "..." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L475-L483
17,640
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function( pointer, event ) { // only drag if we haven't been cancelled; if ( this._cancelled ) { return; } /** * @attribute location * The location of where the element should be in the page. This * takes into account the start position of the cursor on the element. */ this.location = pointer.minus(this.mouseElementPosition); // the offset between the mouse pointer and the representative that the user asked for // position = mouse - (dragOffset - dragTopLeft) - mousePosition this.move(event); if ( this._cancelled ) { return; } if (!event.isDefaultPrevented() ) { this.position(this.location); } //fill in if (!this._only && this.constructor.responder ) { this.constructor.responder.show(pointer, this, event); } }
javascript
function( pointer, event ) { // only drag if we haven't been cancelled; if ( this._cancelled ) { return; } /** * @attribute location * The location of where the element should be in the page. This * takes into account the start position of the cursor on the element. */ this.location = pointer.minus(this.mouseElementPosition); // the offset between the mouse pointer and the representative that the user asked for // position = mouse - (dragOffset - dragTopLeft) - mousePosition this.move(event); if ( this._cancelled ) { return; } if (!event.isDefaultPrevented() ) { this.position(this.location); } //fill in if (!this._only && this.constructor.responder ) { this.constructor.responder.show(pointer, this, event); } }
[ "function", "(", "pointer", ",", "event", ")", "{", "// only drag if we haven't been cancelled;", "if", "(", "this", ".", "_cancelled", ")", "{", "return", ";", "}", "/**\n\t\t\t * @attribute location\n\t\t\t * The location of where the element should be in the page. This \n\t\t\t * takes into account the start position of the cursor on the element.\n\t\t\t */", "this", ".", "location", "=", "pointer", ".", "minus", "(", "this", ".", "mouseElementPosition", ")", ";", "// the offset between the mouse pointer and the representative that the user asked for", "// position = mouse - (dragOffset - dragTopLeft) - mousePosition", "this", ".", "move", "(", "event", ")", ";", "if", "(", "this", ".", "_cancelled", ")", "{", "return", ";", "}", "if", "(", "!", "event", ".", "isDefaultPrevented", "(", ")", ")", "{", "this", ".", "position", "(", "this", ".", "location", ")", ";", "}", "//fill in", "if", "(", "!", "this", ".", "_only", "&&", "this", ".", "constructor", ".", "responder", ")", "{", "this", ".", "constructor", ".", "responder", ".", "show", "(", "pointer", ",", "this", ",", "event", ")", ";", "}", "}" ]
draws the position of the dragmove object
[ "draws", "the", "position", "of", "the", "dragmove", "object" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L577-L601
17,641
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function( newOffsetv ) { //should draw it on the page var style, dragged_element_css_offset = this.currentDelta(), // the drag element's current left + top css attributes dragged_element_position_vector = // the vector between the movingElement's page and css positions this.movingElement.offsetv().minus(dragged_element_css_offset); // this can be thought of as the original offset this.required_css_position = newOffsetv.minus(dragged_element_position_vector); this.offsetv = newOffsetv; //dragged_element vector can probably be cached. style = this.movingElement[0].style; if (!this._cancelled && !this._horizontal ) { style.top = this.required_css_position.top() + "px"; } if (!this._cancelled && !this._vertical ) { style.left = this.required_css_position.left() + "px"; } }
javascript
function( newOffsetv ) { //should draw it on the page var style, dragged_element_css_offset = this.currentDelta(), // the drag element's current left + top css attributes dragged_element_position_vector = // the vector between the movingElement's page and css positions this.movingElement.offsetv().minus(dragged_element_css_offset); // this can be thought of as the original offset this.required_css_position = newOffsetv.minus(dragged_element_position_vector); this.offsetv = newOffsetv; //dragged_element vector can probably be cached. style = this.movingElement[0].style; if (!this._cancelled && !this._horizontal ) { style.top = this.required_css_position.top() + "px"; } if (!this._cancelled && !this._vertical ) { style.left = this.required_css_position.left() + "px"; } }
[ "function", "(", "newOffsetv", ")", "{", "//should draw it on the page", "var", "style", ",", "dragged_element_css_offset", "=", "this", ".", "currentDelta", "(", ")", ",", "// the drag element's current left + top css attributes", "dragged_element_position_vector", "=", "// the vector between the movingElement's page and css positions", "this", ".", "movingElement", ".", "offsetv", "(", ")", ".", "minus", "(", "dragged_element_css_offset", ")", ";", "// this can be thought of as the original offset", "this", ".", "required_css_position", "=", "newOffsetv", ".", "minus", "(", "dragged_element_position_vector", ")", ";", "this", ".", "offsetv", "=", "newOffsetv", ";", "//dragged_element vector can probably be cached.", "style", "=", "this", ".", "movingElement", "[", "0", "]", ".", "style", ";", "if", "(", "!", "this", ".", "_cancelled", "&&", "!", "this", ".", "_horizontal", ")", "{", "style", ".", "top", "=", "this", ".", "required_css_position", ".", "top", "(", ")", "+", "\"px\"", ";", "}", "if", "(", "!", "this", ".", "_cancelled", "&&", "!", "this", ".", "_vertical", ")", "{", "style", ".", "left", "=", "this", ".", "required_css_position", ".", "left", "(", ")", "+", "\"px\"", ";", "}", "}" ]
Sets the position of this drag. The limit and scroll plugins overwrite this to make sure the drag follows a particular path. @param {jQuery.Vector} newOffsetv the position of the element (not the mouse)
[ "Sets", "the", "position", "of", "this", "drag", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L610-L626
17,642
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function( event ) { if ( this._cancelled ) { return; } if (!this._only && this.constructor.responder ) { this.constructor.responder.end(event, this); } this.callEvents('end', this.element, event); if ( this._revert ) { var self = this; this.movingElement.animate({ top: this.startPosition.top() + "px", left: this.startPosition.left() + "px" }, function() { self.cleanup.apply(self, arguments); }); } else { this.cleanup(); } this.event = null; }
javascript
function( event ) { if ( this._cancelled ) { return; } if (!this._only && this.constructor.responder ) { this.constructor.responder.end(event, this); } this.callEvents('end', this.element, event); if ( this._revert ) { var self = this; this.movingElement.animate({ top: this.startPosition.top() + "px", left: this.startPosition.left() + "px" }, function() { self.cleanup.apply(self, arguments); }); } else { this.cleanup(); } this.event = null; }
[ "function", "(", "event", ")", "{", "if", "(", "this", ".", "_cancelled", ")", "{", "return", ";", "}", "if", "(", "!", "this", ".", "_only", "&&", "this", ".", "constructor", ".", "responder", ")", "{", "this", ".", "constructor", ".", "responder", ".", "end", "(", "event", ",", "this", ")", ";", "}", "this", ".", "callEvents", "(", "'end'", ",", "this", ".", "element", ",", "event", ")", ";", "if", "(", "this", ".", "_revert", ")", "{", "var", "self", "=", "this", ";", "this", ".", "movingElement", ".", "animate", "(", "{", "top", ":", "this", ".", "startPosition", ".", "top", "(", ")", "+", "\"px\"", ",", "left", ":", "this", ".", "startPosition", ".", "left", "(", ")", "+", "\"px\"", "}", ",", "function", "(", ")", "{", "self", ".", "cleanup", ".", "apply", "(", "self", ",", "arguments", ")", ";", "}", ")", ";", "}", "else", "{", "this", ".", "cleanup", "(", ")", ";", "}", "this", ".", "event", "=", "null", ";", "}" ]
Called on drag up @hide @param {Event} event a mouseup event signalling drag/drop has completed
[ "Called", "on", "drag", "up" ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L641-L664
17,643
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function() { this.movingElement.css({ zIndex: this.oldZIndex }); if ( this.movingElement[0] !== this.element[0] ) { this.movingElement.css({ display: 'none' }); } if ( this._removeMovingElement ) { this.movingElement.remove(); } this.movingElement = this.element = this.event = null; }
javascript
function() { this.movingElement.css({ zIndex: this.oldZIndex }); if ( this.movingElement[0] !== this.element[0] ) { this.movingElement.css({ display: 'none' }); } if ( this._removeMovingElement ) { this.movingElement.remove(); } this.movingElement = this.element = this.event = null; }
[ "function", "(", ")", "{", "this", ".", "movingElement", ".", "css", "(", "{", "zIndex", ":", "this", ".", "oldZIndex", "}", ")", ";", "if", "(", "this", ".", "movingElement", "[", "0", "]", "!==", "this", ".", "element", "[", "0", "]", ")", "{", "this", ".", "movingElement", ".", "css", "(", "{", "display", ":", "'none'", "}", ")", ";", "}", "if", "(", "this", ".", "_removeMovingElement", ")", "{", "this", ".", "movingElement", ".", "remove", "(", ")", ";", "}", "this", ".", "movingElement", "=", "this", ".", "element", "=", "this", ".", "event", "=", "null", ";", "}" ]
Cleans up drag element after drag drop. @hide
[ "Cleans", "up", "drag", "element", "after", "drag", "drop", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L669-L683
17,644
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function() { this._cancelled = true; //this.end(this.event); if (!this._only && this.constructor.responder ) { this.constructor.responder.clear(this.event.vector(), this, this.event); } this.destroy(); }
javascript
function() { this._cancelled = true; //this.end(this.event); if (!this._only && this.constructor.responder ) { this.constructor.responder.clear(this.event.vector(), this, this.event); } this.destroy(); }
[ "function", "(", ")", "{", "this", ".", "_cancelled", "=", "true", ";", "//this.end(this.event);", "if", "(", "!", "this", ".", "_only", "&&", "this", ".", "constructor", ".", "responder", ")", "{", "this", ".", "constructor", ".", "responder", ".", "clear", "(", "this", ".", "event", ".", "vector", "(", ")", ",", "this", ",", "this", ".", "event", ")", ";", "}", "this", ".", "destroy", "(", ")", ";", "}" ]
Stops drag drop from running.
[ "Stops", "drag", "drop", "from", "running", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L687-L695
17,645
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function( loc ) { // create a ghost by cloning the source element and attach the clone to the dom after the source element var ghost = this.movingElement.clone().css('position', 'absolute'); (loc ? $(loc) : this.movingElement).after(ghost); ghost.width(this.movingElement.width()).height(this.movingElement.height()); // store the original element and make the ghost the dragged element this.movingElement = ghost; this._removeMovingElement = true; return ghost; }
javascript
function( loc ) { // create a ghost by cloning the source element and attach the clone to the dom after the source element var ghost = this.movingElement.clone().css('position', 'absolute'); (loc ? $(loc) : this.movingElement).after(ghost); ghost.width(this.movingElement.width()).height(this.movingElement.height()); // store the original element and make the ghost the dragged element this.movingElement = ghost; this._removeMovingElement = true; return ghost; }
[ "function", "(", "loc", ")", "{", "// create a ghost by cloning the source element and attach the clone to the dom after the source element", "var", "ghost", "=", "this", ".", "movingElement", ".", "clone", "(", ")", ".", "css", "(", "'position'", ",", "'absolute'", ")", ";", "(", "loc", "?", "$", "(", "loc", ")", ":", "this", ".", "movingElement", ")", ".", "after", "(", "ghost", ")", ";", "ghost", ".", "width", "(", "this", ".", "movingElement", ".", "width", "(", ")", ")", ".", "height", "(", "this", ".", "movingElement", ".", "height", "(", ")", ")", ";", "// store the original element and make the ghost the dragged element", "this", ".", "movingElement", "=", "ghost", ";", "this", ".", "_removeMovingElement", "=", "true", ";", "return", "ghost", ";", "}" ]
Clones the element and uses it as the moving element. @return {jQuery.fn} the ghost
[ "Clones", "the", "element", "and", "uses", "it", "as", "the", "moving", "element", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L700-L710
17,646
testem/testem
examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js
function( element, offsetX, offsetY ) { this._offsetX = offsetX || 0; this._offsetY = offsetY || 0; var p = this.mouseStartPosition; this.movingElement = $(element); this.movingElement.css({ top: (p.y() - this._offsetY) + "px", left: (p.x() - this._offsetX) + "px", display: 'block', position: 'absolute' }).show(); this.mouseElementPosition = new $.Vector(this._offsetX, this._offsetY); }
javascript
function( element, offsetX, offsetY ) { this._offsetX = offsetX || 0; this._offsetY = offsetY || 0; var p = this.mouseStartPosition; this.movingElement = $(element); this.movingElement.css({ top: (p.y() - this._offsetY) + "px", left: (p.x() - this._offsetX) + "px", display: 'block', position: 'absolute' }).show(); this.mouseElementPosition = new $.Vector(this._offsetX, this._offsetY); }
[ "function", "(", "element", ",", "offsetX", ",", "offsetY", ")", "{", "this", ".", "_offsetX", "=", "offsetX", "||", "0", ";", "this", ".", "_offsetY", "=", "offsetY", "||", "0", ";", "var", "p", "=", "this", ".", "mouseStartPosition", ";", "this", ".", "movingElement", "=", "$", "(", "element", ")", ";", "this", ".", "movingElement", ".", "css", "(", "{", "top", ":", "(", "p", ".", "y", "(", ")", "-", "this", ".", "_offsetY", ")", "+", "\"px\"", ",", "left", ":", "(", "p", ".", "x", "(", ")", "-", "this", ".", "_offsetX", ")", "+", "\"px\"", ",", "display", ":", "'block'", ",", "position", ":", "'absolute'", "}", ")", ".", "show", "(", ")", ";", "this", ".", "mouseElementPosition", "=", "new", "$", ".", "Vector", "(", "this", ".", "_offsetX", ",", "this", ".", "_offsetY", ")", ";", "}" ]
Use a representative element, instead of the movingElement. @param {HTMLElement} element the element you want to actually drag @param {Number} offsetX the x position where you want your mouse on the object @param {Number} offsetY the y position where you want your mouse on the object
[ "Use", "a", "representative", "element", "instead", "of", "the", "movingElement", "." ]
47773ffe85627d7486496e5999082b01b4add222
https://github.com/testem/testem/blob/47773ffe85627d7486496e5999082b01b4add222/examples/template_stealjs/funcunit/syn/resources/jquery.event.drag.js#L717-L732
17,647
liamcurry/passport-steam
lib/passport-steam/strategy.js
getUserProfile
function getUserProfile(key, steamID, callback) { var steam = new SteamWebAPI({ apiKey: key, format: 'json' }); steam.getPlayerSummaries({ steamids: [ steamID ], callback: function(err, result) { if(err) { return callback(err); } var profile = { provider: 'steam', _json: result.response.players[0], id: result.response.players[0].steamid, displayName: result.response.players[0].personaname, photos: [{ value: result.response.players[0].avatar }, { value: result.response.players[0].avatarmedium }, { value: result.response.players[0].avatarfull }] }; callback(null, profile); } }); }
javascript
function getUserProfile(key, steamID, callback) { var steam = new SteamWebAPI({ apiKey: key, format: 'json' }); steam.getPlayerSummaries({ steamids: [ steamID ], callback: function(err, result) { if(err) { return callback(err); } var profile = { provider: 'steam', _json: result.response.players[0], id: result.response.players[0].steamid, displayName: result.response.players[0].personaname, photos: [{ value: result.response.players[0].avatar }, { value: result.response.players[0].avatarmedium }, { value: result.response.players[0].avatarfull }] }; callback(null, profile); } }); }
[ "function", "getUserProfile", "(", "key", ",", "steamID", ",", "callback", ")", "{", "var", "steam", "=", "new", "SteamWebAPI", "(", "{", "apiKey", ":", "key", ",", "format", ":", "'json'", "}", ")", ";", "steam", ".", "getPlayerSummaries", "(", "{", "steamids", ":", "[", "steamID", "]", ",", "callback", ":", "function", "(", "err", ",", "result", ")", "{", "if", "(", "err", ")", "{", "return", "callback", "(", "err", ")", ";", "}", "var", "profile", "=", "{", "provider", ":", "'steam'", ",", "_json", ":", "result", ".", "response", ".", "players", "[", "0", "]", ",", "id", ":", "result", ".", "response", ".", "players", "[", "0", "]", ".", "steamid", ",", "displayName", ":", "result", ".", "response", ".", "players", "[", "0", "]", ".", "personaname", ",", "photos", ":", "[", "{", "value", ":", "result", ".", "response", ".", "players", "[", "0", "]", ".", "avatar", "}", ",", "{", "value", ":", "result", ".", "response", ".", "players", "[", "0", "]", ".", "avatarmedium", "}", ",", "{", "value", ":", "result", ".", "response", ".", "players", "[", "0", "]", ".", "avatarfull", "}", "]", "}", ";", "callback", "(", "null", ",", "profile", ")", ";", "}", "}", ")", ";", "}" ]
Retrieve user's Steam profile information. @param {String} key Steam WebAPI key. @param {String} steamID SteamID64. @return {Object} User's Steam profile.
[ "Retrieve", "user", "s", "Steam", "profile", "information", "." ]
bf2c3cca044a7aa174182b51fede9f72f147012e
https://github.com/liamcurry/passport-steam/blob/bf2c3cca044a7aa174182b51fede9f72f147012e/lib/passport-steam/strategy.js#L15-L42
17,648
liamcurry/passport-steam
lib/passport-steam/strategy.js
verify
function verify(req, identifier, profile, done) { var validOpEndpoint = 'https://steamcommunity.com/openid/login'; var identifierRegex = /^https?:\/\/steamcommunity\.com\/openid\/id\/(\d+)$/; if(req.query['openid.op_endpoint'] !== validOpEndpoint || !identifierRegex.test(identifier)) { return done(null, false, { message: 'Claimed identity is invalid.' }); } var steamID = identifierRegex.exec(identifier)[0]; if(options.profile) { getUserProfile(options.apiKey, steamID, function(err, profile) { if(err) { done(err); } else { if(originalPassReqToCallback) { validate(req, identifier, profile, done); } else { validate(identifier, profile, done); } } }); } else { if(originalPassReqToCallback) { validate(req, identifier, profile, done); } else { validate(identifier, profile, done); } } }
javascript
function verify(req, identifier, profile, done) { var validOpEndpoint = 'https://steamcommunity.com/openid/login'; var identifierRegex = /^https?:\/\/steamcommunity\.com\/openid\/id\/(\d+)$/; if(req.query['openid.op_endpoint'] !== validOpEndpoint || !identifierRegex.test(identifier)) { return done(null, false, { message: 'Claimed identity is invalid.' }); } var steamID = identifierRegex.exec(identifier)[0]; if(options.profile) { getUserProfile(options.apiKey, steamID, function(err, profile) { if(err) { done(err); } else { if(originalPassReqToCallback) { validate(req, identifier, profile, done); } else { validate(identifier, profile, done); } } }); } else { if(originalPassReqToCallback) { validate(req, identifier, profile, done); } else { validate(identifier, profile, done); } } }
[ "function", "verify", "(", "req", ",", "identifier", ",", "profile", ",", "done", ")", "{", "var", "validOpEndpoint", "=", "'https://steamcommunity.com/openid/login'", ";", "var", "identifierRegex", "=", "/", "^https?:\\/\\/steamcommunity\\.com\\/openid\\/id\\/(\\d+)$", "/", ";", "if", "(", "req", ".", "query", "[", "'openid.op_endpoint'", "]", "!==", "validOpEndpoint", "||", "!", "identifierRegex", ".", "test", "(", "identifier", ")", ")", "{", "return", "done", "(", "null", ",", "false", ",", "{", "message", ":", "'Claimed identity is invalid.'", "}", ")", ";", "}", "var", "steamID", "=", "identifierRegex", ".", "exec", "(", "identifier", ")", "[", "0", "]", ";", "if", "(", "options", ".", "profile", ")", "{", "getUserProfile", "(", "options", ".", "apiKey", ",", "steamID", ",", "function", "(", "err", ",", "profile", ")", "{", "if", "(", "err", ")", "{", "done", "(", "err", ")", ";", "}", "else", "{", "if", "(", "originalPassReqToCallback", ")", "{", "validate", "(", "req", ",", "identifier", ",", "profile", ",", "done", ")", ";", "}", "else", "{", "validate", "(", "identifier", ",", "profile", ",", "done", ")", ";", "}", "}", "}", ")", ";", "}", "else", "{", "if", "(", "originalPassReqToCallback", ")", "{", "validate", "(", "req", ",", "identifier", ",", "profile", ",", "done", ")", ";", "}", "else", "{", "validate", "(", "identifier", ",", "profile", ",", "done", ")", ";", "}", "}", "}" ]
Request needs to be verified
[ "Request", "needs", "to", "be", "verified" ]
bf2c3cca044a7aa174182b51fede9f72f147012e
https://github.com/liamcurry/passport-steam/blob/bf2c3cca044a7aa174182b51fede9f72f147012e/lib/passport-steam/strategy.js#L86-L116
17,649
springernature/shunter
bin/serve.js
addLatency
function addLatency(request, response, next) { if (request.path === '/') { return next(); } setTimeout(next, args.latency); }
javascript
function addLatency(request, response, next) { if (request.path === '/') { return next(); } setTimeout(next, args.latency); }
[ "function", "addLatency", "(", "request", ",", "response", ",", "next", ")", "{", "if", "(", "request", ".", "path", "===", "'/'", ")", "{", "return", "next", "(", ")", ";", "}", "setTimeout", "(", "next", ",", "args", ".", "latency", ")", ";", "}" ]
Middleware to add latency to a response
[ "Middleware", "to", "add", "latency", "to", "a", "response" ]
45f6c46a6db83f652dbd4ba0bd945d490f80c2e9
https://github.com/springernature/shunter/blob/45f6c46a6db83f652dbd4ba0bd945d490f80c2e9/bin/serve.js#L95-L100
17,650
springernature/shunter
bin/serve.js
serveRemoteJson
function serveRemoteJson(request, response, next) { if (request.path !== '/remote') { return next(); } var options = { url: request.query.url, headers: request.query.headers }; var error; if (!options.url || typeof options.url !== 'string') { error = new Error('Invalid query parameter: url'); error.status = 400; return next(error); } if (options.headers && typeof options.headers !== 'string') { error = new Error('Invalid query parameter: headers'); error.status = 400; return next(error); } options.headers = parseHeaders(options.headers); loadRemoteJson(options, function (error, json) { if (error) { return next(error); } response.writeHead(200, { 'Content-Type': 'application/x-shunter+json' }); response.end(JSON.stringify(json, null, 4)); }); }
javascript
function serveRemoteJson(request, response, next) { if (request.path !== '/remote') { return next(); } var options = { url: request.query.url, headers: request.query.headers }; var error; if (!options.url || typeof options.url !== 'string') { error = new Error('Invalid query parameter: url'); error.status = 400; return next(error); } if (options.headers && typeof options.headers !== 'string') { error = new Error('Invalid query parameter: headers'); error.status = 400; return next(error); } options.headers = parseHeaders(options.headers); loadRemoteJson(options, function (error, json) { if (error) { return next(error); } response.writeHead(200, { 'Content-Type': 'application/x-shunter+json' }); response.end(JSON.stringify(json, null, 4)); }); }
[ "function", "serveRemoteJson", "(", "request", ",", "response", ",", "next", ")", "{", "if", "(", "request", ".", "path", "!==", "'/remote'", ")", "{", "return", "next", "(", ")", ";", "}", "var", "options", "=", "{", "url", ":", "request", ".", "query", ".", "url", ",", "headers", ":", "request", ".", "query", ".", "headers", "}", ";", "var", "error", ";", "if", "(", "!", "options", ".", "url", "||", "typeof", "options", ".", "url", "!==", "'string'", ")", "{", "error", "=", "new", "Error", "(", "'Invalid query parameter: url'", ")", ";", "error", ".", "status", "=", "400", ";", "return", "next", "(", "error", ")", ";", "}", "if", "(", "options", ".", "headers", "&&", "typeof", "options", ".", "headers", "!==", "'string'", ")", "{", "error", "=", "new", "Error", "(", "'Invalid query parameter: headers'", ")", ";", "error", ".", "status", "=", "400", ";", "return", "next", "(", "error", ")", ";", "}", "options", ".", "headers", "=", "parseHeaders", "(", "options", ".", "headers", ")", ";", "loadRemoteJson", "(", "options", ",", "function", "(", "error", ",", "json", ")", "{", "if", "(", "error", ")", "{", "return", "next", "(", "error", ")", ";", "}", "response", ".", "writeHead", "(", "200", ",", "{", "'Content-Type'", ":", "'application/x-shunter+json'", "}", ")", ";", "response", ".", "end", "(", "JSON", ".", "stringify", "(", "json", ",", "null", ",", "4", ")", ")", ";", "}", ")", ";", "}" ]
Middleware to serve remote JSON
[ "Middleware", "to", "serve", "remote", "JSON" ]
45f6c46a6db83f652dbd4ba0bd945d490f80c2e9
https://github.com/springernature/shunter/blob/45f6c46a6db83f652dbd4ba0bd945d490f80c2e9/bin/serve.js#L103-L136
17,651
springernature/shunter
bin/serve.js
loadRemoteJson
function loadRemoteJson(options, done) { var requestOptions = { url: options.url, headers: options.headers }; var error; request(requestOptions, function (err, response, body) { if (err) { return done(error); } if (response.statusCode < 200 || response.statusCode >= 300) { error = new Error('Remote JSON responded with ' + response.statusCode + ' status'); error.status = response.statusCode; return done(error); } try { body = JSON.parse(body); } catch (err) { return done(err); } done(null, body); }); }
javascript
function loadRemoteJson(options, done) { var requestOptions = { url: options.url, headers: options.headers }; var error; request(requestOptions, function (err, response, body) { if (err) { return done(error); } if (response.statusCode < 200 || response.statusCode >= 300) { error = new Error('Remote JSON responded with ' + response.statusCode + ' status'); error.status = response.statusCode; return done(error); } try { body = JSON.parse(body); } catch (err) { return done(err); } done(null, body); }); }
[ "function", "loadRemoteJson", "(", "options", ",", "done", ")", "{", "var", "requestOptions", "=", "{", "url", ":", "options", ".", "url", ",", "headers", ":", "options", ".", "headers", "}", ";", "var", "error", ";", "request", "(", "requestOptions", ",", "function", "(", "err", ",", "response", ",", "body", ")", "{", "if", "(", "err", ")", "{", "return", "done", "(", "error", ")", ";", "}", "if", "(", "response", ".", "statusCode", "<", "200", "||", "response", ".", "statusCode", ">=", "300", ")", "{", "error", "=", "new", "Error", "(", "'Remote JSON responded with '", "+", "response", ".", "statusCode", "+", "' status'", ")", ";", "error", ".", "status", "=", "response", ".", "statusCode", ";", "return", "done", "(", "error", ")", ";", "}", "try", "{", "body", "=", "JSON", ".", "parse", "(", "body", ")", ";", "}", "catch", "(", "err", ")", "{", "return", "done", "(", "err", ")", ";", "}", "done", "(", "null", ",", "body", ")", ";", "}", ")", ";", "}" ]
Load remote JSON
[ "Load", "remote", "JSON" ]
45f6c46a6db83f652dbd4ba0bd945d490f80c2e9
https://github.com/springernature/shunter/blob/45f6c46a6db83f652dbd4ba0bd945d490f80c2e9/bin/serve.js#L139-L162
17,652
springernature/shunter
bin/serve.js
parseHeaders
function parseHeaders(headerString) { var headers = {}; var headersArray = headerString.split(/[\r\n]+/); headersArray.forEach(function (headerString) { var headerChunks = headerString.split(':'); headers[headerChunks.shift().trim()] = headerChunks.join(':').trim(); }); return headers; }
javascript
function parseHeaders(headerString) { var headers = {}; var headersArray = headerString.split(/[\r\n]+/); headersArray.forEach(function (headerString) { var headerChunks = headerString.split(':'); headers[headerChunks.shift().trim()] = headerChunks.join(':').trim(); }); return headers; }
[ "function", "parseHeaders", "(", "headerString", ")", "{", "var", "headers", "=", "{", "}", ";", "var", "headersArray", "=", "headerString", ".", "split", "(", "/", "[\\r\\n]+", "/", ")", ";", "headersArray", ".", "forEach", "(", "function", "(", "headerString", ")", "{", "var", "headerChunks", "=", "headerString", ".", "split", "(", "':'", ")", ";", "headers", "[", "headerChunks", ".", "shift", "(", ")", ".", "trim", "(", ")", "]", "=", "headerChunks", ".", "join", "(", "':'", ")", ".", "trim", "(", ")", ";", "}", ")", ";", "return", "headers", ";", "}" ]
Parse a HTTP header string
[ "Parse", "a", "HTTP", "header", "string" ]
45f6c46a6db83f652dbd4ba0bd945d490f80c2e9
https://github.com/springernature/shunter/blob/45f6c46a6db83f652dbd4ba0bd945d490f80c2e9/bin/serve.js#L165-L173
17,653
springernature/shunter
bin/compile.js
function (p, cb) { var pth = p.replace(/\\\?/g, '\/'); // Glob must use / as path seperator even on windows glob(pth + '/**/*.*', function (er, files) { if (er) { return cb(er); } return cb(null, files.map(function (f) { return path.relative(p, f); })); }); }
javascript
function (p, cb) { var pth = p.replace(/\\\?/g, '\/'); // Glob must use / as path seperator even on windows glob(pth + '/**/*.*', function (er, files) { if (er) { return cb(er); } return cb(null, files.map(function (f) { return path.relative(p, f); })); }); }
[ "function", "(", "p", ",", "cb", ")", "{", "var", "pth", "=", "p", ".", "replace", "(", "/", "\\\\\\?", "/", "g", ",", "'\\/'", ")", ";", "// Glob must use / as path seperator even on windows", "glob", "(", "pth", "+", "'/**/*.*'", ",", "function", "(", "er", ",", "files", ")", "{", "if", "(", "er", ")", "{", "return", "cb", "(", "er", ")", ";", "}", "return", "cb", "(", "null", ",", "files", ".", "map", "(", "function", "(", "f", ")", "{", "return", "path", ".", "relative", "(", "p", ",", "f", ")", ";", "}", ")", ")", ";", "}", ")", ";", "}" ]
Glob returns absolute path and we need to strip that out
[ "Glob", "returns", "absolute", "path", "and", "we", "need", "to", "strip", "that", "out" ]
45f6c46a6db83f652dbd4ba0bd945d490f80c2e9
https://github.com/springernature/shunter/blob/45f6c46a6db83f652dbd4ba0bd945d490f80c2e9/bin/compile.js#L138-L148
17,654
springernature/shunter
lib/renderer.js
function (name) { var isProduction = config.env.isProduction(); var asset = (isProduction) ? manifest.assets[name] : environment.findAsset(name); if (!asset) { return ''; } var mountPath = config.argv && (config.argv['mount-path'] || ''); return ( isProduction ? path.join(mountPath, config.web.publicResources, asset) : path.join(mountPath, config.web.resources, asset.digestPath) ); }
javascript
function (name) { var isProduction = config.env.isProduction(); var asset = (isProduction) ? manifest.assets[name] : environment.findAsset(name); if (!asset) { return ''; } var mountPath = config.argv && (config.argv['mount-path'] || ''); return ( isProduction ? path.join(mountPath, config.web.publicResources, asset) : path.join(mountPath, config.web.resources, asset.digestPath) ); }
[ "function", "(", "name", ")", "{", "var", "isProduction", "=", "config", ".", "env", ".", "isProduction", "(", ")", ";", "var", "asset", "=", "(", "isProduction", ")", "?", "manifest", ".", "assets", "[", "name", "]", ":", "environment", ".", "findAsset", "(", "name", ")", ";", "if", "(", "!", "asset", ")", "{", "return", "''", ";", "}", "var", "mountPath", "=", "config", ".", "argv", "&&", "(", "config", ".", "argv", "[", "'mount-path'", "]", "||", "''", ")", ";", "return", "(", "isProduction", "?", "path", ".", "join", "(", "mountPath", ",", "config", ".", "web", ".", "publicResources", ",", "asset", ")", ":", "path", ".", "join", "(", "mountPath", ",", "config", ".", "web", ".", "resources", ",", "asset", ".", "digestPath", ")", ")", ";", "}" ]
Host app can be shunter-based app or manifest, so rely on root
[ "Host", "app", "can", "be", "shunter", "-", "based", "app", "or", "manifest", "so", "rely", "on", "root" ]
45f6c46a6db83f652dbd4ba0bd945d490f80c2e9
https://github.com/springernature/shunter/blob/45f6c46a6db83f652dbd4ba0bd945d490f80c2e9/lib/renderer.js#L50-L63
17,655
springernature/shunter
lib/renderer.js
function (paths) { var self = this; if (typeof paths === 'string') { paths = [].slice.call(arguments, 0); } paths.forEach(function (name) { // DEPRECATED: checking both themes and templates folders for the right template file // when updated, should just look for 'self.compileFile(name));' // name will need to be full path, or contain the relevant subfolders e.g. laserwolf/views/subject/foo.dust if (fs.existsSync(path.join(config.path.themes, name))) { // Themes self.compileFile(path.join(config.path.themes, name)); } else if (fs.existsSync(path.join(config.path.templates, name))) { // Old shunter-proxy self.compileFile(path.join(config.path.templates, name)); } else if (fs.existsSync(name)) { // Full path self.compileFile(name); } else { config.log.info('Could not find template ' + name); } // End DEPRECATED }); }
javascript
function (paths) { var self = this; if (typeof paths === 'string') { paths = [].slice.call(arguments, 0); } paths.forEach(function (name) { // DEPRECATED: checking both themes and templates folders for the right template file // when updated, should just look for 'self.compileFile(name));' // name will need to be full path, or contain the relevant subfolders e.g. laserwolf/views/subject/foo.dust if (fs.existsSync(path.join(config.path.themes, name))) { // Themes self.compileFile(path.join(config.path.themes, name)); } else if (fs.existsSync(path.join(config.path.templates, name))) { // Old shunter-proxy self.compileFile(path.join(config.path.templates, name)); } else if (fs.existsSync(name)) { // Full path self.compileFile(name); } else { config.log.info('Could not find template ' + name); } // End DEPRECATED }); }
[ "function", "(", "paths", ")", "{", "var", "self", "=", "this", ";", "if", "(", "typeof", "paths", "===", "'string'", ")", "{", "paths", "=", "[", "]", ".", "slice", ".", "call", "(", "arguments", ",", "0", ")", ";", "}", "paths", ".", "forEach", "(", "function", "(", "name", ")", "{", "// DEPRECATED: checking both themes and templates folders for the right template file", "// when updated, should just look for 'self.compileFile(name));'", "// name will need to be full path, or contain the relevant subfolders e.g. laserwolf/views/subject/foo.dust", "if", "(", "fs", ".", "existsSync", "(", "path", ".", "join", "(", "config", ".", "path", ".", "themes", ",", "name", ")", ")", ")", "{", "// Themes", "self", ".", "compileFile", "(", "path", ".", "join", "(", "config", ".", "path", ".", "themes", ",", "name", ")", ")", ";", "}", "else", "if", "(", "fs", ".", "existsSync", "(", "path", ".", "join", "(", "config", ".", "path", ".", "templates", ",", "name", ")", ")", ")", "{", "// Old shunter-proxy", "self", ".", "compileFile", "(", "path", ".", "join", "(", "config", ".", "path", ".", "templates", ",", "name", ")", ")", ";", "}", "else", "if", "(", "fs", ".", "existsSync", "(", "name", ")", ")", "{", "// Full path", "self", ".", "compileFile", "(", "name", ")", ";", "}", "else", "{", "config", ".", "log", ".", "info", "(", "'Could not find template '", "+", "name", ")", ";", "}", "// End DEPRECATED", "}", ")", ";", "}" ]
Just used for testing?
[ "Just", "used", "for", "testing?" ]
45f6c46a6db83f652dbd4ba0bd945d490f80c2e9
https://github.com/springernature/shunter/blob/45f6c46a6db83f652dbd4ba0bd945d490f80c2e9/lib/renderer.js#L154-L178
17,656
webex/spark-js-sdk
deps.js
findPackages
function findPackages(packagesPath) { return fs.readdirSync(packagesPath).reduce((acc, d) => { const fullpath = path.resolve(packagesPath, d); if (fs.statSync(fullpath).isDirectory()) { try { fs.statSync(path.resolve(fullpath, 'package.json')); acc.push(fullpath); } catch (err) { if (err.code === 'ENOENT') { return acc.concat(findPackages(fullpath)); } throw err; } } return acc; }, []); }
javascript
function findPackages(packagesPath) { return fs.readdirSync(packagesPath).reduce((acc, d) => { const fullpath = path.resolve(packagesPath, d); if (fs.statSync(fullpath).isDirectory()) { try { fs.statSync(path.resolve(fullpath, 'package.json')); acc.push(fullpath); } catch (err) { if (err.code === 'ENOENT') { return acc.concat(findPackages(fullpath)); } throw err; } } return acc; }, []); }
[ "function", "findPackages", "(", "packagesPath", ")", "{", "return", "fs", ".", "readdirSync", "(", "packagesPath", ")", ".", "reduce", "(", "(", "acc", ",", "d", ")", "=>", "{", "const", "fullpath", "=", "path", ".", "resolve", "(", "packagesPath", ",", "d", ")", ";", "if", "(", "fs", ".", "statSync", "(", "fullpath", ")", ".", "isDirectory", "(", ")", ")", "{", "try", "{", "fs", ".", "statSync", "(", "path", ".", "resolve", "(", "fullpath", ",", "'package.json'", ")", ")", ";", "acc", ".", "push", "(", "fullpath", ")", ";", "}", "catch", "(", "err", ")", "{", "if", "(", "err", ".", "code", "===", "'ENOENT'", ")", "{", "return", "acc", ".", "concat", "(", "findPackages", "(", "fullpath", ")", ")", ";", "}", "throw", "err", ";", "}", "}", "return", "acc", ";", "}", ",", "[", "]", ")", ";", "}" ]
Locates all packages below the specified directory @param {string} packagesPath @returns {Array<string>}
[ "Locates", "all", "packages", "below", "the", "specified", "directory" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/deps.js#L264-L283
17,657
webex/spark-js-sdk
deps.js
updateAllPackages
function updateAllPackages(rootPkgPath, packagesPath) { const paths = findPackages(packagesPath); return paths.reduce((promise, pkgPath) => promise.then(() => updateSinglePackage(rootPkgPath, pkgPath)), Promise.resolve()); }
javascript
function updateAllPackages(rootPkgPath, packagesPath) { const paths = findPackages(packagesPath); return paths.reduce((promise, pkgPath) => promise.then(() => updateSinglePackage(rootPkgPath, pkgPath)), Promise.resolve()); }
[ "function", "updateAllPackages", "(", "rootPkgPath", ",", "packagesPath", ")", "{", "const", "paths", "=", "findPackages", "(", "packagesPath", ")", ";", "return", "paths", ".", "reduce", "(", "(", "promise", ",", "pkgPath", ")", "=>", "promise", ".", "then", "(", "(", ")", "=>", "updateSinglePackage", "(", "rootPkgPath", ",", "pkgPath", ")", ")", ",", "Promise", ".", "resolve", "(", ")", ")", ";", "}" ]
Transforms all packages @param {string} rootPkgPath @param {string} packagesPath @returns {Promise}
[ "Transforms", "all", "packages" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/deps.js#L291-L295
17,658
webex/spark-js-sdk
tooling/lib/version.js
checkLastCommit
async function checkLastCommit() { debug('checking if the last commit message has explicit release instructions'); const summary = await git.lastLog(); const re = /^#release v(\d+\.\d+\.\d+)/; const match = summary.match(re); if (match) { const version = match[1]; if (version) { return version; } } return undefined; }
javascript
async function checkLastCommit() { debug('checking if the last commit message has explicit release instructions'); const summary = await git.lastLog(); const re = /^#release v(\d+\.\d+\.\d+)/; const match = summary.match(re); if (match) { const version = match[1]; if (version) { return version; } } return undefined; }
[ "async", "function", "checkLastCommit", "(", ")", "{", "debug", "(", "'checking if the last commit message has explicit release instructions'", ")", ";", "const", "summary", "=", "await", "git", ".", "lastLog", "(", ")", ";", "const", "re", "=", "/", "^#release v(\\d+\\.\\d+\\.\\d+)", "/", ";", "const", "match", "=", "summary", ".", "match", "(", "re", ")", ";", "if", "(", "match", ")", "{", "const", "version", "=", "match", "[", "1", "]", ";", "if", "(", "version", ")", "{", "return", "version", ";", "}", "}", "return", "undefined", ";", "}" ]
Determines if the last commit specified an explicit version to set @returns {Promise<string>}
[ "Determines", "if", "the", "last", "commit", "specified", "an", "explicit", "version", "to", "set" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/version.js#L171-L186
17,659
webex/spark-js-sdk
tooling/lib/version.js
getChangeType
async function getChangeType() { const subjects = await exec('git log upstream/master.. --format=%s'); for (const subject of subjects.split('\n')) { if (subject.startsWith('feat')) { return 'minor'; } if (subject.startsWith('fix') || subject.startsWith('perf') || subject.startsWith('refactor')) { return 'patch'; } } return undefined; }
javascript
async function getChangeType() { const subjects = await exec('git log upstream/master.. --format=%s'); for (const subject of subjects.split('\n')) { if (subject.startsWith('feat')) { return 'minor'; } if (subject.startsWith('fix') || subject.startsWith('perf') || subject.startsWith('refactor')) { return 'patch'; } } return undefined; }
[ "async", "function", "getChangeType", "(", ")", "{", "const", "subjects", "=", "await", "exec", "(", "'git log upstream/master.. --format=%s'", ")", ";", "for", "(", "const", "subject", "of", "subjects", ".", "split", "(", "'\\n'", ")", ")", "{", "if", "(", "subject", ".", "startsWith", "(", "'feat'", ")", ")", "{", "return", "'minor'", ";", "}", "if", "(", "subject", ".", "startsWith", "(", "'fix'", ")", "||", "subject", ".", "startsWith", "(", "'perf'", ")", "||", "subject", ".", "startsWith", "(", "'refactor'", ")", ")", "{", "return", "'patch'", ";", "}", "}", "return", "undefined", ";", "}" ]
Checks commit messages to determine change type @returns {Promise<boolean>}
[ "Checks", "commit", "messages", "to", "determine", "change", "type" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/version.js#L210-L224
17,660
webex/spark-js-sdk
tooling/lib/updated.js
fileToPackage
function fileToPackage(d) { debug(d); if (d.startsWith('packages/node_modules/')) { d = d.replace('packages/node_modules/', ''); d = d.split('/'); if (d[0].startsWith('@')) { return d.slice(0, 2).join('/'); } return d[0]; } if (d.startsWith('docs') || d.startsWith('documentation') || d.startsWith('.github') || d.endsWith('.md')) { return 'docs'; } return 'tooling'; }
javascript
function fileToPackage(d) { debug(d); if (d.startsWith('packages/node_modules/')) { d = d.replace('packages/node_modules/', ''); d = d.split('/'); if (d[0].startsWith('@')) { return d.slice(0, 2).join('/'); } return d[0]; } if (d.startsWith('docs') || d.startsWith('documentation') || d.startsWith('.github') || d.endsWith('.md')) { return 'docs'; } return 'tooling'; }
[ "function", "fileToPackage", "(", "d", ")", "{", "debug", "(", "d", ")", ";", "if", "(", "d", ".", "startsWith", "(", "'packages/node_modules/'", ")", ")", "{", "d", "=", "d", ".", "replace", "(", "'packages/node_modules/'", ",", "''", ")", ";", "d", "=", "d", ".", "split", "(", "'/'", ")", ";", "if", "(", "d", "[", "0", "]", ".", "startsWith", "(", "'@'", ")", ")", "{", "return", "d", ".", "slice", "(", "0", ",", "2", ")", ".", "join", "(", "'/'", ")", ";", "}", "return", "d", "[", "0", "]", ";", "}", "if", "(", "d", ".", "startsWith", "(", "'docs'", ")", "||", "d", ".", "startsWith", "(", "'documentation'", ")", "||", "d", ".", "startsWith", "(", "'.github'", ")", "||", "d", ".", "endsWith", "(", "'.md'", ")", ")", "{", "return", "'docs'", ";", "}", "return", "'tooling'", ";", "}" ]
Determines the package to which a given file belongs. Includes the meta packages "docs" and "tooling" @param {string} d @private @returns {string}
[ "Determines", "the", "package", "to", "which", "a", "given", "file", "belongs", ".", "Includes", "the", "meta", "packages", "docs", "and", "tooling" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/updated.js#L49-L66
17,661
webex/spark-js-sdk
tooling/util/package.js
read
async function read(packageName) { const packagePath = path.join(cwd, packageName, 'package.json'); return JSON.parse(await fs.readFile(packagePath)); }
javascript
async function read(packageName) { const packagePath = path.join(cwd, packageName, 'package.json'); return JSON.parse(await fs.readFile(packagePath)); }
[ "async", "function", "read", "(", "packageName", ")", "{", "const", "packagePath", "=", "path", ".", "join", "(", "cwd", ",", "packageName", ",", "'package.json'", ")", ";", "return", "JSON", ".", "parse", "(", "await", "fs", ".", "readFile", "(", "packagePath", ")", ")", ";", "}" ]
Reads a package.json into an object @param {string} packageName @returns {Promise<Object>}
[ "Reads", "a", "package", ".", "json", "into", "an", "object" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/util/package.js#L30-L34
17,662
webex/spark-js-sdk
tooling/util/package.js
write
async function write(packageName, pkg) { const packagePath = path.join(cwd, packageName, 'package.json'); await fs.writeFile(packagePath, `${JSON.stringify(pkg, null, 2)}\n`); }
javascript
async function write(packageName, pkg) { const packagePath = path.join(cwd, packageName, 'package.json'); await fs.writeFile(packagePath, `${JSON.stringify(pkg, null, 2)}\n`); }
[ "async", "function", "write", "(", "packageName", ",", "pkg", ")", "{", "const", "packagePath", "=", "path", ".", "join", "(", "cwd", ",", "packageName", ",", "'package.json'", ")", ";", "await", "fs", ".", "writeFile", "(", "packagePath", ",", "`", "${", "JSON", ".", "stringify", "(", "pkg", ",", "null", ",", "2", ")", "}", "\\n", "`", ")", ";", "}" ]
Writes an object to a package.json @param {string} packageName @param {Object} pkg
[ "Writes", "an", "object", "to", "a", "package", ".", "json" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/util/package.js#L43-L47
17,663
webex/spark-js-sdk
tooling/lib/openh264.js
encode
function encode(fp) { return new Promise((resolve, reject) => { fp.encode((err, encoded) => { if (err) { reject(err); return; } resolve(encoded); }); }); }
javascript
function encode(fp) { return new Promise((resolve, reject) => { fp.encode((err, encoded) => { if (err) { reject(err); return; } resolve(encoded); }); }); }
[ "function", "encode", "(", "fp", ")", "{", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "fp", ".", "encode", "(", "(", "err", ",", "encoded", ")", "=>", "{", "if", "(", "err", ")", "{", "reject", "(", "err", ")", ";", "return", ";", "}", "resolve", "(", "encoded", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
denodeifies FirefoxProfile.encode @param {FirefoxProfile} fp @returns {Promise<string>}
[ "denodeifies", "FirefoxProfile", ".", "encode" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/openh264.js#L23-L34
17,664
webex/spark-js-sdk
tooling/lib/openh264.js
injectLocal
async function injectLocal(def) { debug(`checking ${def.base} for firefox`); if (def.base.toLowerCase().includes('firefox')) { debug('def is a firefox def'); const platform = platformToShortName(os.platform()); debug(`injecting ${platform} profile into ${def.base}`); const dest = await prepareLocalProfile(platform); def.profile = dest; debug(`injected ${dest} profile into ${def.base}`); } }
javascript
async function injectLocal(def) { debug(`checking ${def.base} for firefox`); if (def.base.toLowerCase().includes('firefox')) { debug('def is a firefox def'); const platform = platformToShortName(os.platform()); debug(`injecting ${platform} profile into ${def.base}`); const dest = await prepareLocalProfile(platform); def.profile = dest; debug(`injected ${dest} profile into ${def.base}`); } }
[ "async", "function", "injectLocal", "(", "def", ")", "{", "debug", "(", "`", "${", "def", ".", "base", "}", "`", ")", ";", "if", "(", "def", ".", "base", ".", "toLowerCase", "(", ")", ".", "includes", "(", "'firefox'", ")", ")", "{", "debug", "(", "'def is a firefox def'", ")", ";", "const", "platform", "=", "platformToShortName", "(", "os", ".", "platform", "(", ")", ")", ";", "debug", "(", "`", "${", "platform", "}", "${", "def", ".", "base", "}", "`", ")", ";", "const", "dest", "=", "await", "prepareLocalProfile", "(", "platform", ")", ";", "def", ".", "profile", "=", "dest", ";", "debug", "(", "`", "${", "dest", "}", "${", "def", ".", "base", "}", "`", ")", ";", "}", "}" ]
Injects a the path of a firefox profile directory into a local browser definition @param {Object} def
[ "Injects", "a", "the", "path", "of", "a", "firefox", "profile", "directory", "into", "a", "local", "browser", "definition" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/openh264.js#L114-L126
17,665
webex/spark-js-sdk
tooling/lib/openh264.js
injectSauce
async function injectSauce(def) { debug(`checking ${def.base} for firefox`); if (def.browserName.toLowerCase().includes('firefox')) { debug('def is a firefox def'); const platform = platformToShortName(def.platform); if (platform !== 'mac') { throw new Error(`No tooling implemented for injecting h264 into ${platform} (${def.platform})`); } debug(`injecting ${platform} profile into ${def.base}`); const dir = path.resolve(process.cwd(), `${PROFILE_DIR}/${platform}`); debug(`profile is at ${dir}`); const profile = await copy(dir); const encoded = await encode(profile); // eslint-disable-next-line camelcase def.firefox_profile = encoded; debug(`injected ${platform} profile into def`); } }
javascript
async function injectSauce(def) { debug(`checking ${def.base} for firefox`); if (def.browserName.toLowerCase().includes('firefox')) { debug('def is a firefox def'); const platform = platformToShortName(def.platform); if (platform !== 'mac') { throw new Error(`No tooling implemented for injecting h264 into ${platform} (${def.platform})`); } debug(`injecting ${platform} profile into ${def.base}`); const dir = path.resolve(process.cwd(), `${PROFILE_DIR}/${platform}`); debug(`profile is at ${dir}`); const profile = await copy(dir); const encoded = await encode(profile); // eslint-disable-next-line camelcase def.firefox_profile = encoded; debug(`injected ${platform} profile into def`); } }
[ "async", "function", "injectSauce", "(", "def", ")", "{", "debug", "(", "`", "${", "def", ".", "base", "}", "`", ")", ";", "if", "(", "def", ".", "browserName", ".", "toLowerCase", "(", ")", ".", "includes", "(", "'firefox'", ")", ")", "{", "debug", "(", "'def is a firefox def'", ")", ";", "const", "platform", "=", "platformToShortName", "(", "def", ".", "platform", ")", ";", "if", "(", "platform", "!==", "'mac'", ")", "{", "throw", "new", "Error", "(", "`", "${", "platform", "}", "${", "def", ".", "platform", "}", "`", ")", ";", "}", "debug", "(", "`", "${", "platform", "}", "${", "def", ".", "base", "}", "`", ")", ";", "const", "dir", "=", "path", ".", "resolve", "(", "process", ".", "cwd", "(", ")", ",", "`", "${", "PROFILE_DIR", "}", "${", "platform", "}", "`", ")", ";", "debug", "(", "`", "${", "dir", "}", "`", ")", ";", "const", "profile", "=", "await", "copy", "(", "dir", ")", ";", "const", "encoded", "=", "await", "encode", "(", "profile", ")", ";", "// eslint-disable-next-line camelcase", "def", ".", "firefox_profile", "=", "encoded", ";", "debug", "(", "`", "${", "platform", "}", "`", ")", ";", "}", "}" ]
Injects a gzipped, base64-encoded firefox profile directory into a Sauce Labs browser definition @param {Object} def
[ "Injects", "a", "gzipped", "base64", "-", "encoded", "firefox", "profile", "directory", "into", "a", "Sauce", "Labs", "browser", "definition" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/openh264.js#L154-L175
17,666
webex/spark-js-sdk
tooling/karma.js
watchSauce
async function watchSauce(server, cfg) { try { debug('reading sauce pid'); const pid = parseInt(await readFile(process.env.SC_PID_FILE), 10); debug(`sauce pid is ${pid}`); let done = false; server.once('run_complete', () => { debug('run complete'); done = true; }); const delay = 1000; // eslint-disable-next-line no-unmodified-loop-condition while (!done) { debug(`waiting ${delay}ms`); await new Promise((resolve) => setTimeout(resolve, delay)); debug(`waited ${delay}ms`); await new Promise((resolve, reject) => { debug(`checking if ${pid} is running`); ps.lookup({ psargs: '-A', pid }, (err, resultList) => { if (err) { debug('ps-node produced an error', err); reject(err); return; } if (resultList.length === 0) { debug(`pid ${pid} is not running`); reject(new Error(`pid ${pid} is not running`)); return; } debug(`pid ${pid} is running`); resolve(); }); }); } } catch (err) { console.error(err); console.error('Sauce Tunnel is not running, stopping server and exiting'); stopper.stop(cfg); // so, this is a bit harsh, but due to karma's api,there's no great way to // communicate back to test.js that karma failed because the tunnel // disappeared. By exiting here, cmd.sh should restart sauce and run the // suite again // eslint-disable-next-line no-process-exit process.exit(65); } }
javascript
async function watchSauce(server, cfg) { try { debug('reading sauce pid'); const pid = parseInt(await readFile(process.env.SC_PID_FILE), 10); debug(`sauce pid is ${pid}`); let done = false; server.once('run_complete', () => { debug('run complete'); done = true; }); const delay = 1000; // eslint-disable-next-line no-unmodified-loop-condition while (!done) { debug(`waiting ${delay}ms`); await new Promise((resolve) => setTimeout(resolve, delay)); debug(`waited ${delay}ms`); await new Promise((resolve, reject) => { debug(`checking if ${pid} is running`); ps.lookup({ psargs: '-A', pid }, (err, resultList) => { if (err) { debug('ps-node produced an error', err); reject(err); return; } if (resultList.length === 0) { debug(`pid ${pid} is not running`); reject(new Error(`pid ${pid} is not running`)); return; } debug(`pid ${pid} is running`); resolve(); }); }); } } catch (err) { console.error(err); console.error('Sauce Tunnel is not running, stopping server and exiting'); stopper.stop(cfg); // so, this is a bit harsh, but due to karma's api,there's no great way to // communicate back to test.js that karma failed because the tunnel // disappeared. By exiting here, cmd.sh should restart sauce and run the // suite again // eslint-disable-next-line no-process-exit process.exit(65); } }
[ "async", "function", "watchSauce", "(", "server", ",", "cfg", ")", "{", "try", "{", "debug", "(", "'reading sauce pid'", ")", ";", "const", "pid", "=", "parseInt", "(", "await", "readFile", "(", "process", ".", "env", ".", "SC_PID_FILE", ")", ",", "10", ")", ";", "debug", "(", "`", "${", "pid", "}", "`", ")", ";", "let", "done", "=", "false", ";", "server", ".", "once", "(", "'run_complete'", ",", "(", ")", "=>", "{", "debug", "(", "'run complete'", ")", ";", "done", "=", "true", ";", "}", ")", ";", "const", "delay", "=", "1000", ";", "// eslint-disable-next-line no-unmodified-loop-condition", "while", "(", "!", "done", ")", "{", "debug", "(", "`", "${", "delay", "}", "`", ")", ";", "await", "new", "Promise", "(", "(", "resolve", ")", "=>", "setTimeout", "(", "resolve", ",", "delay", ")", ")", ";", "debug", "(", "`", "${", "delay", "}", "`", ")", ";", "await", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "debug", "(", "`", "${", "pid", "}", "`", ")", ";", "ps", ".", "lookup", "(", "{", "psargs", ":", "'-A'", ",", "pid", "}", ",", "(", "err", ",", "resultList", ")", "=>", "{", "if", "(", "err", ")", "{", "debug", "(", "'ps-node produced an error'", ",", "err", ")", ";", "reject", "(", "err", ")", ";", "return", ";", "}", "if", "(", "resultList", ".", "length", "===", "0", ")", "{", "debug", "(", "`", "${", "pid", "}", "`", ")", ";", "reject", "(", "new", "Error", "(", "`", "${", "pid", "}", "`", ")", ")", ";", "return", ";", "}", "debug", "(", "`", "${", "pid", "}", "`", ")", ";", "resolve", "(", ")", ";", "}", ")", ";", "}", ")", ";", "}", "}", "catch", "(", "err", ")", "{", "console", ".", "error", "(", "err", ")", ";", "console", ".", "error", "(", "'Sauce Tunnel is not running, stopping server and exiting'", ")", ";", "stopper", ".", "stop", "(", "cfg", ")", ";", "// so, this is a bit harsh, but due to karma's api,there's no great way to", "// communicate back to test.js that karma failed because the tunnel", "// disappeared. By exiting here, cmd.sh should restart sauce and run the", "// suite again", "// eslint-disable-next-line no-process-exit", "process", ".", "exit", "(", "65", ")", ";", "}", "}" ]
Periodically checks that the sauce process is still running and kills the test suite if it is not @param {Object} server @param {Object} cfg
[ "Periodically", "checks", "that", "the", "sauce", "process", "is", "still", "running", "and", "kills", "the", "test", "suite", "if", "it", "is", "not" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/karma.js#L19-L77
17,667
webex/spark-js-sdk
tooling/util/server.js
start
async function start() { if (child) { await stop(); } return new Promise((resolve) => { const serverPath = path.resolve(process.cwd(), 'packages/node_modules/@webex/test-helper-server'); child = spawn(process.argv[0], [serverPath], { env: process.env, stdio: ['ignore', 'pipe', process.stderr] }); child.stdout.on('data', (data) => { const message = `${data}`; const pattern = /.+/gi; if (message.match(pattern)) { resolve(); } }); process.on('exit', stop); }); }
javascript
async function start() { if (child) { await stop(); } return new Promise((resolve) => { const serverPath = path.resolve(process.cwd(), 'packages/node_modules/@webex/test-helper-server'); child = spawn(process.argv[0], [serverPath], { env: process.env, stdio: ['ignore', 'pipe', process.stderr] }); child.stdout.on('data', (data) => { const message = `${data}`; const pattern = /.+/gi; if (message.match(pattern)) { resolve(); } }); process.on('exit', stop); }); }
[ "async", "function", "start", "(", ")", "{", "if", "(", "child", ")", "{", "await", "stop", "(", ")", ";", "}", "return", "new", "Promise", "(", "(", "resolve", ")", "=>", "{", "const", "serverPath", "=", "path", ".", "resolve", "(", "process", ".", "cwd", "(", ")", ",", "'packages/node_modules/@webex/test-helper-server'", ")", ";", "child", "=", "spawn", "(", "process", ".", "argv", "[", "0", "]", ",", "[", "serverPath", "]", ",", "{", "env", ":", "process", ".", "env", ",", "stdio", ":", "[", "'ignore'", ",", "'pipe'", ",", "process", ".", "stderr", "]", "}", ")", ";", "child", ".", "stdout", ".", "on", "(", "'data'", ",", "(", "data", ")", "=>", "{", "const", "message", "=", "`", "${", "data", "}", "`", ";", "const", "pattern", "=", "/", ".+", "/", "gi", ";", "if", "(", "message", ".", "match", "(", "pattern", ")", ")", "{", "resolve", "(", ")", ";", "}", "}", ")", ";", "process", ".", "on", "(", "'exit'", ",", "stop", ")", ";", "}", ")", ";", "}" ]
Starts the test server @returns {Promise}
[ "Starts", "the", "test", "server" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/util/server.js#L15-L39
17,668
webex/spark-js-sdk
tooling/util/server.js
stop
function stop() { return new Promise((resolve) => { if (child && child.kill) { debug('stopping test server'); child.kill('SIGTERM'); process.removeListener('exit', stop); child = null; debug('stopped test server'); } resolve(); }); }
javascript
function stop() { return new Promise((resolve) => { if (child && child.kill) { debug('stopping test server'); child.kill('SIGTERM'); process.removeListener('exit', stop); child = null; debug('stopped test server'); } resolve(); }); }
[ "function", "stop", "(", ")", "{", "return", "new", "Promise", "(", "(", "resolve", ")", "=>", "{", "if", "(", "child", "&&", "child", ".", "kill", ")", "{", "debug", "(", "'stopping test server'", ")", ";", "child", ".", "kill", "(", "'SIGTERM'", ")", ";", "process", ".", "removeListener", "(", "'exit'", ",", "stop", ")", ";", "child", "=", "null", ";", "debug", "(", "'stopped test server'", ")", ";", "}", "resolve", "(", ")", ";", "}", ")", ";", "}" ]
Stops the test server @returns {Promise}
[ "Stops", "the", "test", "server" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/util/server.js#L45-L57
17,669
webex/spark-js-sdk
tooling/babel-plugin-inject-package-version.js
versionFromState
function versionFromState(state) { // eslint-disable-next-line global-require return require(pkgUp.sync(state.file.opts.filename)).version; }
javascript
function versionFromState(state) { // eslint-disable-next-line global-require return require(pkgUp.sync(state.file.opts.filename)).version; }
[ "function", "versionFromState", "(", "state", ")", "{", "// eslint-disable-next-line global-require", "return", "require", "(", "pkgUp", ".", "sync", "(", "state", ".", "file", ".", "opts", ".", "filename", ")", ")", ".", "version", ";", "}" ]
Uses pkgUp to find the appropriate package.json for the specified babel state object @param {Object} state @private @returns {string}
[ "Uses", "pkgUp", "to", "find", "the", "appropriate", "package", ".", "json", "for", "the", "specified", "babel", "state", "object" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/babel-plugin-inject-package-version.js#L15-L18
17,670
webex/spark-js-sdk
tooling/lib/dependencies.js
buildLocalDepTree
async function buildLocalDepTree() { for (const packageName of await _list()) { tree.set(packageName, await exports.list(packageName, { includeTransitive: false, localOnly: true })); } }
javascript
async function buildLocalDepTree() { for (const packageName of await _list()) { tree.set(packageName, await exports.list(packageName, { includeTransitive: false, localOnly: true })); } }
[ "async", "function", "buildLocalDepTree", "(", ")", "{", "for", "(", "const", "packageName", "of", "await", "_list", "(", ")", ")", "{", "tree", ".", "set", "(", "packageName", ",", "await", "exports", ".", "list", "(", "packageName", ",", "{", "includeTransitive", ":", "false", ",", "localOnly", ":", "true", "}", ")", ")", ";", "}", "}" ]
Walks all packages to generate a tree of direct dependencies
[ "Walks", "all", "packages", "to", "generate", "a", "tree", "of", "direct", "dependencies" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/dependencies.js#L52-L59
17,671
webex/spark-js-sdk
tooling/lib/dependencies.js
buildDirectDependentTree
async function buildDirectDependentTree() { const dependents = new Map(); for (const packageName of await _list()) { dependents.set(packageName, new Set()); } for (const packageName of await _list()) { for (const dep of tree.get(packageName)) { dependents.get(dep).add(packageName); } } return dependents; }
javascript
async function buildDirectDependentTree() { const dependents = new Map(); for (const packageName of await _list()) { dependents.set(packageName, new Set()); } for (const packageName of await _list()) { for (const dep of tree.get(packageName)) { dependents.get(dep).add(packageName); } } return dependents; }
[ "async", "function", "buildDirectDependentTree", "(", ")", "{", "const", "dependents", "=", "new", "Map", "(", ")", ";", "for", "(", "const", "packageName", "of", "await", "_list", "(", ")", ")", "{", "dependents", ".", "set", "(", "packageName", ",", "new", "Set", "(", ")", ")", ";", "}", "for", "(", "const", "packageName", "of", "await", "_list", "(", ")", ")", "{", "for", "(", "const", "dep", "of", "tree", ".", "get", "(", "packageName", ")", ")", "{", "dependents", ".", "get", "(", "dep", ")", ".", "add", "(", "packageName", ")", ";", "}", "}", "return", "dependents", ";", "}" ]
Builds a tree of direct dependent packages @returns {Map<string, Set>}
[ "Builds", "a", "tree", "of", "direct", "dependent", "packages" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/dependencies.js#L96-L110
17,672
webex/spark-js-sdk
tooling/lib/dependencies.js
findDeps
function findDeps(entrypoints) { let deps = new Set(); for (const entrypoint of entrypoints) { deps = new Set([...deps, ...walk(entrypoint)]); } return deps; }
javascript
function findDeps(entrypoints) { let deps = new Set(); for (const entrypoint of entrypoints) { deps = new Set([...deps, ...walk(entrypoint)]); } return deps; }
[ "function", "findDeps", "(", "entrypoints", ")", "{", "let", "deps", "=", "new", "Set", "(", ")", ";", "for", "(", "const", "entrypoint", "of", "entrypoints", ")", "{", "deps", "=", "new", "Set", "(", "[", "...", "deps", ",", "...", "walk", "(", "entrypoint", ")", "]", ")", ";", "}", "return", "deps", ";", "}" ]
Finds all the dependencies for a given set of entrypoints @param {Array<string>} entrypoints @returns {Array<string>}
[ "Finds", "all", "the", "dependencies", "for", "a", "given", "set", "of", "entrypoints" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/dependencies.js#L146-L154
17,673
webex/spark-js-sdk
tooling/lib/dependencies.js
requireToPackage
function requireToPackage(d) { d = d.split('/'); if (d[0].startsWith('@')) { return d.slice(0, 2).join('/'); } return d[0]; }
javascript
function requireToPackage(d) { d = d.split('/'); if (d[0].startsWith('@')) { return d.slice(0, 2).join('/'); } return d[0]; }
[ "function", "requireToPackage", "(", "d", ")", "{", "d", "=", "d", ".", "split", "(", "'/'", ")", ";", "if", "(", "d", "[", "0", "]", ".", "startsWith", "(", "'@'", ")", ")", "{", "return", "d", ".", "slice", "(", "0", ",", "2", ")", ".", "join", "(", "'/'", ")", ";", "}", "return", "d", "[", "0", "]", ";", "}" ]
Translates a required filename into a package name @param {strig} d @returns {string}
[ "Translates", "a", "required", "filename", "into", "a", "package", "name" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/dependencies.js#L161-L168
17,674
webex/spark-js-sdk
tooling/lib/dependencies.js
listEntryPoints
function listEntryPoints(pkg) { debug(`listing entrypoints for ${pkg.name}`); if (!pkg.name) { throw new Error('cannot read dependencies for unnamed package'); } let paths = []; if (pkg.main) { debug(`found main path for ${pkg.name}`); paths.push(pkg.main); } if (pkg.bin) { debug(`found bin entry(s) for ${pkg.name}`); paths = paths.concat(values(pkg.bin)); } if (pkg.browser) { debug(`found browser entry(s) for ${pkg.name}`); paths = paths.concat(values(pkg.browser).filter((p) => p && !p.startsWith('@'))); } debug(paths); return paths .map((p) => path.resolve('packages', 'node_modules', pkg.name, p)); }
javascript
function listEntryPoints(pkg) { debug(`listing entrypoints for ${pkg.name}`); if (!pkg.name) { throw new Error('cannot read dependencies for unnamed package'); } let paths = []; if (pkg.main) { debug(`found main path for ${pkg.name}`); paths.push(pkg.main); } if (pkg.bin) { debug(`found bin entry(s) for ${pkg.name}`); paths = paths.concat(values(pkg.bin)); } if (pkg.browser) { debug(`found browser entry(s) for ${pkg.name}`); paths = paths.concat(values(pkg.browser).filter((p) => p && !p.startsWith('@'))); } debug(paths); return paths .map((p) => path.resolve('packages', 'node_modules', pkg.name, p)); }
[ "function", "listEntryPoints", "(", "pkg", ")", "{", "debug", "(", "`", "${", "pkg", ".", "name", "}", "`", ")", ";", "if", "(", "!", "pkg", ".", "name", ")", "{", "throw", "new", "Error", "(", "'cannot read dependencies for unnamed package'", ")", ";", "}", "let", "paths", "=", "[", "]", ";", "if", "(", "pkg", ".", "main", ")", "{", "debug", "(", "`", "${", "pkg", ".", "name", "}", "`", ")", ";", "paths", ".", "push", "(", "pkg", ".", "main", ")", ";", "}", "if", "(", "pkg", ".", "bin", ")", "{", "debug", "(", "`", "${", "pkg", ".", "name", "}", "`", ")", ";", "paths", "=", "paths", ".", "concat", "(", "values", "(", "pkg", ".", "bin", ")", ")", ";", "}", "if", "(", "pkg", ".", "browser", ")", "{", "debug", "(", "`", "${", "pkg", ".", "name", "}", "`", ")", ";", "paths", "=", "paths", ".", "concat", "(", "values", "(", "pkg", ".", "browser", ")", ".", "filter", "(", "(", "p", ")", "=>", "p", "&&", "!", "p", ".", "startsWith", "(", "'@'", ")", ")", ")", ";", "}", "debug", "(", "paths", ")", ";", "return", "paths", ".", "map", "(", "(", "p", ")", "=>", "path", ".", "resolve", "(", "'packages'", ",", "'node_modules'", ",", "pkg", ".", "name", ",", "p", ")", ")", ";", "}" ]
Finds all the entrypoints for the specified package @param {Object} pkg @returns {Array<string>}
[ "Finds", "all", "the", "entrypoints", "for", "the", "specified", "package" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/dependencies.js#L175-L201
17,675
webex/spark-js-sdk
tooling/lib/dependencies.js
walk
function walk(entrypoint) { try { if (!visited.has(entrypoint)) { debug(`finding requires for ${entrypoint}`); // This whole thing is *way* easier if we do it synchronously // eslint-disable-next-line no-sync const requires = detective(fs.readFileSync(entrypoint)); visited.set(entrypoint, requires.reduce((acc, dep) => { debug(`found ${dep}`); if (dep.startsWith('.')) { debug(`${dep} is relative, descending`); const next = walk(path.resolve(path.dirname(entrypoint), dep)); acc = new Set([...acc, ...next]); } else if (!builtins.includes(dep)) { debug(`found dependency ${dep}`); acc.add(requireToPackage(dep)); } return acc; }, new Set())); } return visited.get(entrypoint); } catch (err) { if (err.code === 'EISDIR') { return walk(path.resolve(entrypoint, 'index.js')); } if (err.code === 'ENOENT' && !entrypoint.endsWith('.js')) { return walk(`${entrypoint}.js`); } throw err; } }
javascript
function walk(entrypoint) { try { if (!visited.has(entrypoint)) { debug(`finding requires for ${entrypoint}`); // This whole thing is *way* easier if we do it synchronously // eslint-disable-next-line no-sync const requires = detective(fs.readFileSync(entrypoint)); visited.set(entrypoint, requires.reduce((acc, dep) => { debug(`found ${dep}`); if (dep.startsWith('.')) { debug(`${dep} is relative, descending`); const next = walk(path.resolve(path.dirname(entrypoint), dep)); acc = new Set([...acc, ...next]); } else if (!builtins.includes(dep)) { debug(`found dependency ${dep}`); acc.add(requireToPackage(dep)); } return acc; }, new Set())); } return visited.get(entrypoint); } catch (err) { if (err.code === 'EISDIR') { return walk(path.resolve(entrypoint, 'index.js')); } if (err.code === 'ENOENT' && !entrypoint.endsWith('.js')) { return walk(`${entrypoint}.js`); } throw err; } }
[ "function", "walk", "(", "entrypoint", ")", "{", "try", "{", "if", "(", "!", "visited", ".", "has", "(", "entrypoint", ")", ")", "{", "debug", "(", "`", "${", "entrypoint", "}", "`", ")", ";", "// This whole thing is *way* easier if we do it synchronously", "// eslint-disable-next-line no-sync", "const", "requires", "=", "detective", "(", "fs", ".", "readFileSync", "(", "entrypoint", ")", ")", ";", "visited", ".", "set", "(", "entrypoint", ",", "requires", ".", "reduce", "(", "(", "acc", ",", "dep", ")", "=>", "{", "debug", "(", "`", "${", "dep", "}", "`", ")", ";", "if", "(", "dep", ".", "startsWith", "(", "'.'", ")", ")", "{", "debug", "(", "`", "${", "dep", "}", "`", ")", ";", "const", "next", "=", "walk", "(", "path", ".", "resolve", "(", "path", ".", "dirname", "(", "entrypoint", ")", ",", "dep", ")", ")", ";", "acc", "=", "new", "Set", "(", "[", "...", "acc", ",", "...", "next", "]", ")", ";", "}", "else", "if", "(", "!", "builtins", ".", "includes", "(", "dep", ")", ")", "{", "debug", "(", "`", "${", "dep", "}", "`", ")", ";", "acc", ".", "add", "(", "requireToPackage", "(", "dep", ")", ")", ";", "}", "return", "acc", ";", "}", ",", "new", "Set", "(", ")", ")", ")", ";", "}", "return", "visited", ".", "get", "(", "entrypoint", ")", ";", "}", "catch", "(", "err", ")", "{", "if", "(", "err", ".", "code", "===", "'EISDIR'", ")", "{", "return", "walk", "(", "path", ".", "resolve", "(", "entrypoint", ",", "'index.js'", ")", ")", ";", "}", "if", "(", "err", ".", "code", "===", "'ENOENT'", "&&", "!", "entrypoint", ".", "endsWith", "(", "'.js'", ")", ")", "{", "return", "walk", "(", "`", "${", "entrypoint", "}", "`", ")", ";", "}", "throw", "err", ";", "}", "}" ]
Finds all dependencies of entrypoint @param {string} entrypoint @returns {Set<string>}
[ "Finds", "all", "dependencies", "of", "entrypoint" ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/lib/dependencies.js#L210-L246
17,676
webex/spark-js-sdk
tooling/util/proxies.js
startProxies
async function startProxies() { await Promise.all(services.map((service) => setEnv(service))); return Promise.all(services.map((service) => start(service))); }
javascript
async function startProxies() { await Promise.all(services.map((service) => setEnv(service))); return Promise.all(services.map((service) => start(service))); }
[ "async", "function", "startProxies", "(", ")", "{", "await", "Promise", ".", "all", "(", "services", ".", "map", "(", "(", "service", ")", "=>", "setEnv", "(", "service", ")", ")", ")", ";", "return", "Promise", ".", "all", "(", "services", ".", "map", "(", "(", "service", ")", "=>", "start", "(", "service", ")", ")", ")", ";", "}" ]
Start yakbak proxy servers for each service and return an array of those servers. @returns {Promise}
[ "Start", "yakbak", "proxy", "servers", "for", "each", "service", "and", "return", "an", "array", "of", "those", "servers", "." ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/util/proxies.js#L55-L59
17,677
webex/spark-js-sdk
tooling/util/proxies.js
stopProxies
async function stopProxies() { if (proxies && proxies.length) { return Promise.all(proxies.map((proxy) => stop(proxy))); } return Promise.resolve(); }
javascript
async function stopProxies() { if (proxies && proxies.length) { return Promise.all(proxies.map((proxy) => stop(proxy))); } return Promise.resolve(); }
[ "async", "function", "stopProxies", "(", ")", "{", "if", "(", "proxies", "&&", "proxies", ".", "length", ")", "{", "return", "Promise", ".", "all", "(", "proxies", ".", "map", "(", "(", "proxy", ")", "=>", "stop", "(", "proxy", ")", ")", ")", ";", "}", "return", "Promise", ".", "resolve", "(", ")", ";", "}" ]
Stop each of the proxy servers in the given array. @param {Array} proxies @returns {Promise}
[ "Stop", "each", "of", "the", "proxy", "servers", "in", "the", "given", "array", "." ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/util/proxies.js#L67-L73
17,678
webex/spark-js-sdk
tooling/util/proxies.js
start
async function start(service) { return new Promise((resolve) => { const snapshotsDir = path.join(__dirname, '../../test/services/', service.name, 'snapshots'); const app = yakbak(service.defaultUrl, { dirname: snapshotsDir, hash: customHash }); const proxy = http.createServer(app).listen(service.port, () => { console.log(`Yakbak server listening on port ${service.port}. Proxy for ${service.defaultUrl}`); }); resolve(proxy); }); }
javascript
async function start(service) { return new Promise((resolve) => { const snapshotsDir = path.join(__dirname, '../../test/services/', service.name, 'snapshots'); const app = yakbak(service.defaultUrl, { dirname: snapshotsDir, hash: customHash }); const proxy = http.createServer(app).listen(service.port, () => { console.log(`Yakbak server listening on port ${service.port}. Proxy for ${service.defaultUrl}`); }); resolve(proxy); }); }
[ "async", "function", "start", "(", "service", ")", "{", "return", "new", "Promise", "(", "(", "resolve", ")", "=>", "{", "const", "snapshotsDir", "=", "path", ".", "join", "(", "__dirname", ",", "'../../test/services/'", ",", "service", ".", "name", ",", "'snapshots'", ")", ";", "const", "app", "=", "yakbak", "(", "service", ".", "defaultUrl", ",", "{", "dirname", ":", "snapshotsDir", ",", "hash", ":", "customHash", "}", ")", ";", "const", "proxy", "=", "http", ".", "createServer", "(", "app", ")", ".", "listen", "(", "service", ".", "port", ",", "(", ")", "=>", "{", "console", ".", "log", "(", "`", "${", "service", ".", "port", "}", "${", "service", ".", "defaultUrl", "}", "`", ")", ";", "}", ")", ";", "resolve", "(", "proxy", ")", ";", "}", ")", ";", "}" ]
Starts a proxy server for the given service. @param {Service} service @returns {Promise|http.server} proxy server
[ "Starts", "a", "proxy", "server", "for", "the", "given", "service", "." ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/util/proxies.js#L93-L106
17,679
webex/spark-js-sdk
tooling/util/proxies.js
customHash
function customHash(req, body) { const hash = crypto.createHash('md5'); updateHash(hash, req); hash.write(body); return hash.digest('hex'); }
javascript
function customHash(req, body) { const hash = crypto.createHash('md5'); updateHash(hash, req); hash.write(body); return hash.digest('hex'); }
[ "function", "customHash", "(", "req", ",", "body", ")", "{", "const", "hash", "=", "crypto", ".", "createHash", "(", "'md5'", ")", ";", "updateHash", "(", "hash", ",", "req", ")", ";", "hash", ".", "write", "(", "body", ")", ";", "return", "hash", ".", "digest", "(", "'hex'", ")", ";", "}" ]
Creates a custom hash used as the snapshot's filename. @param {http.ClientRequest} req @param {Object} body @returns {String} hashed filename
[ "Creates", "a", "custom", "hash", "used", "as", "the", "snapshot", "s", "filename", "." ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/util/proxies.js#L126-L133
17,680
webex/spark-js-sdk
tooling/util/proxies.js
pruneHeaders
function pruneHeaders(requestHeaders) { const headers = Object.assign({}, requestHeaders); delete headers.trackingid; delete headers.authorization; return headers; }
javascript
function pruneHeaders(requestHeaders) { const headers = Object.assign({}, requestHeaders); delete headers.trackingid; delete headers.authorization; return headers; }
[ "function", "pruneHeaders", "(", "requestHeaders", ")", "{", "const", "headers", "=", "Object", ".", "assign", "(", "{", "}", ",", "requestHeaders", ")", ";", "delete", "headers", ".", "trackingid", ";", "delete", "headers", ".", "authorization", ";", "return", "headers", ";", "}" ]
Remove headers that are unique for each request from the given headers object. This ensures that certain headers do not "bust" the hash. @param {Object} requestHeaders @returns {Object} a new, pruned headers object
[ "Remove", "headers", "that", "are", "unique", "for", "each", "request", "from", "the", "given", "headers", "object", ".", "This", "ensures", "that", "certain", "headers", "do", "not", "bust", "the", "hash", "." ]
e700847f3430da36140eafe8c51376076f249894
https://github.com/webex/spark-js-sdk/blob/e700847f3430da36140eafe8c51376076f249894/tooling/util/proxies.js#L160-L167
17,681
nobitagit/react-material-floating-button
mfb/src/mfb.js
attachEvt
function attachEvt( elems, evt ){ for( var i = 0, len = elems.length; i < len; i++ ){ mainButton = elems[i].querySelector('.' + mainButtonClass); mainButton.addEventListener( evt , toggleButton, false); } }
javascript
function attachEvt( elems, evt ){ for( var i = 0, len = elems.length; i < len; i++ ){ mainButton = elems[i].querySelector('.' + mainButtonClass); mainButton.addEventListener( evt , toggleButton, false); } }
[ "function", "attachEvt", "(", "elems", ",", "evt", ")", "{", "for", "(", "var", "i", "=", "0", ",", "len", "=", "elems", ".", "length", ";", "i", "<", "len", ";", "i", "++", ")", "{", "mainButton", "=", "elems", "[", "i", "]", ".", "querySelector", "(", "'.'", "+", "mainButtonClass", ")", ";", "mainButton", ".", "addEventListener", "(", "evt", ",", "toggleButton", ",", "false", ")", ";", "}", "}" ]
For every menu we need to get the main button and attach the appropriate evt.
[ "For", "every", "menu", "we", "need", "to", "get", "the", "main", "button", "and", "attach", "the", "appropriate", "evt", "." ]
e735370b70f085b131b54244c9231fa63fe1e126
https://github.com/nobitagit/react-material-floating-button/blob/e735370b70f085b131b54244c9231fa63fe1e126/mfb/src/mfb.js#L36-L41
17,682
nobitagit/react-material-floating-button
mfb/src/mfb.js
replaceAttrs
function replaceAttrs( elems ){ for( var i = 0, len = elems.length; i < len; i++ ){ elems[i].setAttribute( toggleMethod, clickOpt ); elems[i].setAttribute( menuState, isClosed ); } }
javascript
function replaceAttrs( elems ){ for( var i = 0, len = elems.length; i < len; i++ ){ elems[i].setAttribute( toggleMethod, clickOpt ); elems[i].setAttribute( menuState, isClosed ); } }
[ "function", "replaceAttrs", "(", "elems", ")", "{", "for", "(", "var", "i", "=", "0", ",", "len", "=", "elems", ".", "length", ";", "i", "<", "len", ";", "i", "++", ")", "{", "elems", "[", "i", "]", ".", "setAttribute", "(", "toggleMethod", ",", "clickOpt", ")", ";", "elems", "[", "i", "]", ".", "setAttribute", "(", "menuState", ",", "isClosed", ")", ";", "}", "}" ]
Remove the hover option, set a click toggle and a default, initial state of 'closed' to menu that's been targeted.
[ "Remove", "the", "hover", "option", "set", "a", "click", "toggle", "and", "a", "default", "initial", "state", "of", "closed", "to", "menu", "that", "s", "been", "targeted", "." ]
e735370b70f085b131b54244c9231fa63fe1e126
https://github.com/nobitagit/react-material-floating-button/blob/e735370b70f085b131b54244c9231fa63fe1e126/mfb/src/mfb.js#L47-L52
17,683
GoogleChrome/omnitone
src/hoa-renderer.js
HOARenderer
function HOARenderer(context, config) { this._context = Utils.isAudioContext(context) ? context : Utils.throw('HOARenderer: Invalid BaseAudioContext.'); this._config = { ambisonicOrder: 3, renderingMode: RenderingMode.AMBISONIC, }; if (config && config.ambisonicOrder) { if (SupportedAmbisonicOrder.includes(config.ambisonicOrder)) { this._config.ambisonicOrder = config.ambisonicOrder; } else { Utils.log( 'HOARenderer: Invalid ambisonic order. (got ' + config.ambisonicOrder + ') Fallbacks to 3rd-order ambisonic.'); } } this._config.numberOfChannels = (this._config.ambisonicOrder + 1) * (this._config.ambisonicOrder + 1); this._config.numberOfStereoChannels = Math.ceil(this._config.numberOfChannels / 2); if (config && config.hrirPathList) { if (Array.isArray(config.hrirPathList) && config.hrirPathList.length === this._config.numberOfStereoChannels) { this._config.pathList = config.hrirPathList; } else { Utils.throw( 'HOARenderer: Invalid HRIR URLs. It must be an array with ' + this._config.numberOfStereoChannels + ' URLs to HRIR files.' + ' (got ' + config.hrirPathList + ')'); } } if (config && config.renderingMode) { if (Object.values(RenderingMode).includes(config.renderingMode)) { this._config.renderingMode = config.renderingMode; } else { Utils.log( 'HOARenderer: Invalid rendering mode. (got ' + config.renderingMode + ') Fallbacks to "ambisonic".'); } } this._buildAudioGraph(); this._isRendererReady = false; }
javascript
function HOARenderer(context, config) { this._context = Utils.isAudioContext(context) ? context : Utils.throw('HOARenderer: Invalid BaseAudioContext.'); this._config = { ambisonicOrder: 3, renderingMode: RenderingMode.AMBISONIC, }; if (config && config.ambisonicOrder) { if (SupportedAmbisonicOrder.includes(config.ambisonicOrder)) { this._config.ambisonicOrder = config.ambisonicOrder; } else { Utils.log( 'HOARenderer: Invalid ambisonic order. (got ' + config.ambisonicOrder + ') Fallbacks to 3rd-order ambisonic.'); } } this._config.numberOfChannels = (this._config.ambisonicOrder + 1) * (this._config.ambisonicOrder + 1); this._config.numberOfStereoChannels = Math.ceil(this._config.numberOfChannels / 2); if (config && config.hrirPathList) { if (Array.isArray(config.hrirPathList) && config.hrirPathList.length === this._config.numberOfStereoChannels) { this._config.pathList = config.hrirPathList; } else { Utils.throw( 'HOARenderer: Invalid HRIR URLs. It must be an array with ' + this._config.numberOfStereoChannels + ' URLs to HRIR files.' + ' (got ' + config.hrirPathList + ')'); } } if (config && config.renderingMode) { if (Object.values(RenderingMode).includes(config.renderingMode)) { this._config.renderingMode = config.renderingMode; } else { Utils.log( 'HOARenderer: Invalid rendering mode. (got ' + config.renderingMode + ') Fallbacks to "ambisonic".'); } } this._buildAudioGraph(); this._isRendererReady = false; }
[ "function", "HOARenderer", "(", "context", ",", "config", ")", "{", "this", ".", "_context", "=", "Utils", ".", "isAudioContext", "(", "context", ")", "?", "context", ":", "Utils", ".", "throw", "(", "'HOARenderer: Invalid BaseAudioContext.'", ")", ";", "this", ".", "_config", "=", "{", "ambisonicOrder", ":", "3", ",", "renderingMode", ":", "RenderingMode", ".", "AMBISONIC", ",", "}", ";", "if", "(", "config", "&&", "config", ".", "ambisonicOrder", ")", "{", "if", "(", "SupportedAmbisonicOrder", ".", "includes", "(", "config", ".", "ambisonicOrder", ")", ")", "{", "this", ".", "_config", ".", "ambisonicOrder", "=", "config", ".", "ambisonicOrder", ";", "}", "else", "{", "Utils", ".", "log", "(", "'HOARenderer: Invalid ambisonic order. (got '", "+", "config", ".", "ambisonicOrder", "+", "') Fallbacks to 3rd-order ambisonic.'", ")", ";", "}", "}", "this", ".", "_config", ".", "numberOfChannels", "=", "(", "this", ".", "_config", ".", "ambisonicOrder", "+", "1", ")", "*", "(", "this", ".", "_config", ".", "ambisonicOrder", "+", "1", ")", ";", "this", ".", "_config", ".", "numberOfStereoChannels", "=", "Math", ".", "ceil", "(", "this", ".", "_config", ".", "numberOfChannels", "/", "2", ")", ";", "if", "(", "config", "&&", "config", ".", "hrirPathList", ")", "{", "if", "(", "Array", ".", "isArray", "(", "config", ".", "hrirPathList", ")", "&&", "config", ".", "hrirPathList", ".", "length", "===", "this", ".", "_config", ".", "numberOfStereoChannels", ")", "{", "this", ".", "_config", ".", "pathList", "=", "config", ".", "hrirPathList", ";", "}", "else", "{", "Utils", ".", "throw", "(", "'HOARenderer: Invalid HRIR URLs. It must be an array with '", "+", "this", ".", "_config", ".", "numberOfStereoChannels", "+", "' URLs to HRIR files.'", "+", "' (got '", "+", "config", ".", "hrirPathList", "+", "')'", ")", ";", "}", "}", "if", "(", "config", "&&", "config", ".", "renderingMode", ")", "{", "if", "(", "Object", ".", "values", "(", "RenderingMode", ")", ".", "includes", "(", "config", ".", "renderingMode", ")", ")", "{", "this", ".", "_config", ".", "renderingMode", "=", "config", ".", "renderingMode", ";", "}", "else", "{", "Utils", ".", "log", "(", "'HOARenderer: Invalid rendering mode. (got '", "+", "config", ".", "renderingMode", "+", "') Fallbacks to \"ambisonic\".'", ")", ";", "}", "}", "this", ".", "_buildAudioGraph", "(", ")", ";", "this", ".", "_isRendererReady", "=", "false", ";", "}" ]
Omnitone HOA renderer class. Uses the optimized convolution technique. @constructor @param {AudioContext} context - Associated AudioContext. @param {Object} config @param {Number} [config.ambisonicOrder=3] - Ambisonic order. @param {Array} [config.hrirPathList] - A list of paths to HRIR files. It overrides the internal HRIR list if given. @param {RenderingMode} [config.renderingMode='ambisonic'] - Rendering mode.
[ "Omnitone", "HOA", "renderer", "class", ".", "Uses", "the", "optimized", "convolution", "technique", "." ]
891f31ca630622ced5e2413f88d7899144e895f4
https://github.com/GoogleChrome/omnitone/blob/891f31ca630622ced5e2413f88d7899144e895f4/src/hoa-renderer.js#L64-L114
17,684
GoogleChrome/omnitone
src/foa-router.js
FOARouter
function FOARouter(context, channelMap) { this._context = context; this._splitter = this._context.createChannelSplitter(4); this._merger = this._context.createChannelMerger(4); // input/output proxy. this.input = this._splitter; this.output = this._merger; this.setChannelMap(channelMap || ChannelMap.DEFAULT); }
javascript
function FOARouter(context, channelMap) { this._context = context; this._splitter = this._context.createChannelSplitter(4); this._merger = this._context.createChannelMerger(4); // input/output proxy. this.input = this._splitter; this.output = this._merger; this.setChannelMap(channelMap || ChannelMap.DEFAULT); }
[ "function", "FOARouter", "(", "context", ",", "channelMap", ")", "{", "this", ".", "_context", "=", "context", ";", "this", ".", "_splitter", "=", "this", ".", "_context", ".", "createChannelSplitter", "(", "4", ")", ";", "this", ".", "_merger", "=", "this", ".", "_context", ".", "createChannelMerger", "(", "4", ")", ";", "// input/output proxy.", "this", ".", "input", "=", "this", ".", "_splitter", ";", "this", ".", "output", "=", "this", ".", "_merger", ";", "this", ".", "setChannelMap", "(", "channelMap", "||", "ChannelMap", ".", "DEFAULT", ")", ";", "}" ]
Channel router for FOA stream. @constructor @param {AudioContext} context - Associated AudioContext. @param {Number[]} channelMap - Routing destination array.
[ "Channel", "router", "for", "FOA", "stream", "." ]
891f31ca630622ced5e2413f88d7899144e895f4
https://github.com/GoogleChrome/omnitone/blob/891f31ca630622ced5e2413f88d7899144e895f4/src/foa-router.js#L47-L58
17,685
GoogleChrome/omnitone
src/hoa-rotator.js
computeHOAMatrices
function computeHOAMatrices(matrix) { // We start by computing the 2nd-order matrix from the 1st-order matrix. for (let i = 2; i <= matrix.length; i++) { computeBandRotation(matrix, i); } }
javascript
function computeHOAMatrices(matrix) { // We start by computing the 2nd-order matrix from the 1st-order matrix. for (let i = 2; i <= matrix.length; i++) { computeBandRotation(matrix, i); } }
[ "function", "computeHOAMatrices", "(", "matrix", ")", "{", "// We start by computing the 2nd-order matrix from the 1st-order matrix.", "for", "(", "let", "i", "=", "2", ";", "i", "<=", "matrix", ".", "length", ";", "i", "++", ")", "{", "computeBandRotation", "(", "matrix", ",", "i", ")", ";", "}", "}" ]
Compute the HOA rotation matrix after setting the transform matrix. @param {Array} matrix - N matrices of gainNodes, each with (2n+1) x (2n+1) elements, where n=1,2,...,N.
[ "Compute", "the", "HOA", "rotation", "matrix", "after", "setting", "the", "transform", "matrix", "." ]
891f31ca630622ced5e2413f88d7899144e895f4
https://github.com/GoogleChrome/omnitone/blob/891f31ca630622ced5e2413f88d7899144e895f4/src/hoa-rotator.js#L244-L249
17,686
sendgrid/nodejs-http-client
lib/client.js
buildPath
function buildPath (basePath, queryParams) { basePath = basePath.concat('?') var url = basePath.concat(queryString.stringify(queryParams)) return url }
javascript
function buildPath (basePath, queryParams) { basePath = basePath.concat('?') var url = basePath.concat(queryString.stringify(queryParams)) return url }
[ "function", "buildPath", "(", "basePath", ",", "queryParams", ")", "{", "basePath", "=", "basePath", ".", "concat", "(", "'?'", ")", "var", "url", "=", "basePath", ".", "concat", "(", "queryString", ".", "stringify", "(", "queryParams", ")", ")", "return", "url", "}" ]
add query paramaters to a URL
[ "add", "query", "paramaters", "to", "a", "URL" ]
306db085db2818a442ad26a4396522970cc01855
https://github.com/sendgrid/nodejs-http-client/blob/306db085db2818a442ad26a4396522970cc01855/lib/client.js#L58-L62
17,687
monojack/graphql-normalizr
src/pluralize.js
restoreCase
function restoreCase (word, token) { // Tokens are an exact match. if (word === token) return token // Upper cased words. E.g. "HELLO". if (word === word.toUpperCase()) return token.toUpperCase() // Title cased words. E.g. "Title". if (word[0] === word[0].toUpperCase()) { return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase() } // Lower cased words. E.g. "test". return token.toLowerCase() }
javascript
function restoreCase (word, token) { // Tokens are an exact match. if (word === token) return token // Upper cased words. E.g. "HELLO". if (word === word.toUpperCase()) return token.toUpperCase() // Title cased words. E.g. "Title". if (word[0] === word[0].toUpperCase()) { return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase() } // Lower cased words. E.g. "test". return token.toLowerCase() }
[ "function", "restoreCase", "(", "word", ",", "token", ")", "{", "// Tokens are an exact match.", "if", "(", "word", "===", "token", ")", "return", "token", "// Upper cased words. E.g. \"HELLO\".", "if", "(", "word", "===", "word", ".", "toUpperCase", "(", ")", ")", "return", "token", ".", "toUpperCase", "(", ")", "// Title cased words. E.g. \"Title\".", "if", "(", "word", "[", "0", "]", "===", "word", "[", "0", "]", ".", "toUpperCase", "(", ")", ")", "{", "return", "token", ".", "charAt", "(", "0", ")", ".", "toUpperCase", "(", ")", "+", "token", ".", "substr", "(", "1", ")", ".", "toLowerCase", "(", ")", "}", "// Lower cased words. E.g. \"test\".", "return", "token", ".", "toLowerCase", "(", ")", "}" ]
Pass in a word token to produce a function that can replicate the case on another word. @param {string} word @param {string} token @return {Function}
[ "Pass", "in", "a", "word", "token", "to", "produce", "a", "function", "that", "can", "replicate", "the", "case", "on", "another", "word", "." ]
3c456de06978cd3bca97fcab4945bd95bcc53e6f
https://github.com/monojack/graphql-normalizr/blob/3c456de06978cd3bca97fcab4945bd95bcc53e6f/src/pluralize.js#L201-L215
17,688
paypal/glamorous
src/get-glamor-classname.js
extractGlamorStyles
function extractGlamorStyles(className) { const glamorlessClassName = [] const glamorStyles = [] className .toString() .split(' ') .forEach(name => { if (styleSheet.registered[name.substring(4)] === undefined) { glamorlessClassName.push(name) } else { const style = buildGlamorSrcFromClassName(name) glamorStyles.push(style) } }) return {glamorlessClassName, glamorStyles} }
javascript
function extractGlamorStyles(className) { const glamorlessClassName = [] const glamorStyles = [] className .toString() .split(' ') .forEach(name => { if (styleSheet.registered[name.substring(4)] === undefined) { glamorlessClassName.push(name) } else { const style = buildGlamorSrcFromClassName(name) glamorStyles.push(style) } }) return {glamorlessClassName, glamorStyles} }
[ "function", "extractGlamorStyles", "(", "className", ")", "{", "const", "glamorlessClassName", "=", "[", "]", "const", "glamorStyles", "=", "[", "]", "className", ".", "toString", "(", ")", ".", "split", "(", "' '", ")", ".", "forEach", "(", "name", "=>", "{", "if", "(", "styleSheet", ".", "registered", "[", "name", ".", "substring", "(", "4", ")", "]", "===", "undefined", ")", "{", "glamorlessClassName", ".", "push", "(", "name", ")", "}", "else", "{", "const", "style", "=", "buildGlamorSrcFromClassName", "(", "name", ")", "glamorStyles", ".", "push", "(", "style", ")", "}", "}", ")", "return", "{", "glamorlessClassName", ",", "glamorStyles", "}", "}" ]
This function takes a className string and gets all the associated glamor styles. It's used to merge glamor styles from a className to make sure that specificity is not a problem when passing a className to a component. @param {String} [className=''] the className string @return {Object} { glamorStyles, glamorlessClassName } - glamorStyles is an array of all the glamor styles objects - glamorlessClassName is the rest of the className string without the glamor classNames
[ "This", "function", "takes", "a", "className", "string", "and", "gets", "all", "the", "associated", "glamor", "styles", ".", "It", "s", "used", "to", "merge", "glamor", "styles", "from", "a", "className", "to", "make", "sure", "that", "specificity", "is", "not", "a", "problem", "when", "passing", "a", "className", "to", "a", "component", "." ]
031484cd5eff92ff135038200ba49a300859a335
https://github.com/paypal/glamorous/blob/031484cd5eff92ff135038200ba49a300859a335/src/get-glamor-classname.js#L13-L29
17,689
paypal/glamorous
src/get-glamor-classname.js
handleStyles
function handleStyles(styles, props, context) { let current const mappedArgs = [] const nonGlamorClassNames = [] for (let i = 0; i < styles.length; i++) { current = styles[i] while (typeof current === 'function') { current = current(props, context) } if (typeof current === 'string') { const {glamorStyles, glamorlessClassName} = extractGlamorStyles(current) mappedArgs.push(...glamorStyles) nonGlamorClassNames.push(...glamorlessClassName) } else if (Array.isArray(current)) { const recursed = handleStyles(current, props, context) mappedArgs.push(...recursed.mappedArgs) nonGlamorClassNames.push(...recursed.nonGlamorClassNames) } else { mappedArgs.push(current) } } return {mappedArgs, nonGlamorClassNames} }
javascript
function handleStyles(styles, props, context) { let current const mappedArgs = [] const nonGlamorClassNames = [] for (let i = 0; i < styles.length; i++) { current = styles[i] while (typeof current === 'function') { current = current(props, context) } if (typeof current === 'string') { const {glamorStyles, glamorlessClassName} = extractGlamorStyles(current) mappedArgs.push(...glamorStyles) nonGlamorClassNames.push(...glamorlessClassName) } else if (Array.isArray(current)) { const recursed = handleStyles(current, props, context) mappedArgs.push(...recursed.mappedArgs) nonGlamorClassNames.push(...recursed.nonGlamorClassNames) } else { mappedArgs.push(current) } } return {mappedArgs, nonGlamorClassNames} }
[ "function", "handleStyles", "(", "styles", ",", "props", ",", "context", ")", "{", "let", "current", "const", "mappedArgs", "=", "[", "]", "const", "nonGlamorClassNames", "=", "[", "]", "for", "(", "let", "i", "=", "0", ";", "i", "<", "styles", ".", "length", ";", "i", "++", ")", "{", "current", "=", "styles", "[", "i", "]", "while", "(", "typeof", "current", "===", "'function'", ")", "{", "current", "=", "current", "(", "props", ",", "context", ")", "}", "if", "(", "typeof", "current", "===", "'string'", ")", "{", "const", "{", "glamorStyles", ",", "glamorlessClassName", "}", "=", "extractGlamorStyles", "(", "current", ")", "mappedArgs", ".", "push", "(", "...", "glamorStyles", ")", "nonGlamorClassNames", ".", "push", "(", "...", "glamorlessClassName", ")", "}", "else", "if", "(", "Array", ".", "isArray", "(", "current", ")", ")", "{", "const", "recursed", "=", "handleStyles", "(", "current", ",", "props", ",", "context", ")", "mappedArgs", ".", "push", "(", "...", "recursed", ".", "mappedArgs", ")", "nonGlamorClassNames", ".", "push", "(", "...", "recursed", ".", "nonGlamorClassNames", ")", "}", "else", "{", "mappedArgs", ".", "push", "(", "current", ")", "}", "}", "return", "{", "mappedArgs", ",", "nonGlamorClassNames", "}", "}" ]
this next function is on a "hot" code-path so it's pretty complex to make sure it's fast. eslint-disable-next-line complexity
[ "this", "next", "function", "is", "on", "a", "hot", "code", "-", "path", "so", "it", "s", "pretty", "complex", "to", "make", "sure", "it", "s", "fast", ".", "eslint", "-", "disable", "-", "next", "-", "line", "complexity" ]
031484cd5eff92ff135038200ba49a300859a335
https://github.com/paypal/glamorous/blob/031484cd5eff92ff135038200ba49a300859a335/src/get-glamor-classname.js#L73-L95
17,690
paypal/glamorous
src/create-glamorous.js
getPropsToApply
function getPropsToApply(propsToApply, accumulator, props, context) { // using forEach rather than reduce here because the reduce solution // effectively did the same thing because we manipulate the `accumulator` propsToApply.forEach(propsToApplyItem => { if (typeof propsToApplyItem === 'function') { return Object.assign( accumulator, propsToApplyItem(Object.assign({}, accumulator, props), context), ) } else if (Array.isArray(propsToApplyItem)) { return Object.assign( accumulator, getPropsToApply(propsToApplyItem, accumulator, props, context), ) } return Object.assign(accumulator, propsToApplyItem) }) // props wins return Object.assign(accumulator, props) }
javascript
function getPropsToApply(propsToApply, accumulator, props, context) { // using forEach rather than reduce here because the reduce solution // effectively did the same thing because we manipulate the `accumulator` propsToApply.forEach(propsToApplyItem => { if (typeof propsToApplyItem === 'function') { return Object.assign( accumulator, propsToApplyItem(Object.assign({}, accumulator, props), context), ) } else if (Array.isArray(propsToApplyItem)) { return Object.assign( accumulator, getPropsToApply(propsToApplyItem, accumulator, props, context), ) } return Object.assign(accumulator, propsToApplyItem) }) // props wins return Object.assign(accumulator, props) }
[ "function", "getPropsToApply", "(", "propsToApply", ",", "accumulator", ",", "props", ",", "context", ")", "{", "// using forEach rather than reduce here because the reduce solution", "// effectively did the same thing because we manipulate the `accumulator`", "propsToApply", ".", "forEach", "(", "propsToApplyItem", "=>", "{", "if", "(", "typeof", "propsToApplyItem", "===", "'function'", ")", "{", "return", "Object", ".", "assign", "(", "accumulator", ",", "propsToApplyItem", "(", "Object", ".", "assign", "(", "{", "}", ",", "accumulator", ",", "props", ")", ",", "context", ")", ",", ")", "}", "else", "if", "(", "Array", ".", "isArray", "(", "propsToApplyItem", ")", ")", "{", "return", "Object", ".", "assign", "(", "accumulator", ",", "getPropsToApply", "(", "propsToApplyItem", ",", "accumulator", ",", "props", ",", "context", ")", ",", ")", "}", "return", "Object", ".", "assign", "(", "accumulator", ",", "propsToApplyItem", ")", "}", ")", "// props wins", "return", "Object", ".", "assign", "(", "accumulator", ",", "props", ")", "}" ]
reduces the propsToApply given to a single props object @param {Array} propsToApply an array of propsToApply objects: - object - array of propsToApply items - function that accepts the accumulated props and the context @param {Object} accumulator an object to apply props onto @param {Object} props the props that should ultimately take precedence @param {*} context the context object @return {Object} the reduced props
[ "reduces", "the", "propsToApply", "given", "to", "a", "single", "props", "object" ]
031484cd5eff92ff135038200ba49a300859a335
https://github.com/paypal/glamorous/blob/031484cd5eff92ff135038200ba49a300859a335/src/create-glamorous.js#L225-L244
17,691
pbeshai/react-url-query
examples/redux-with-actions/src/MainPage.js
mapDispatchToProps
function mapDispatchToProps(dispatch) { return { onChangeArr: (arr) => dispatch(changeArr(arr)), onChangeFoo: (foo) => dispatch(changeFoo(foo)), onChangeBar: (bar) => dispatch(changeBar(bar)), onChangeBaz: (baz) => dispatch(changeBaz(baz)), onChangeMany: (foo) => dispatch(changeMany({ foo })), }; }
javascript
function mapDispatchToProps(dispatch) { return { onChangeArr: (arr) => dispatch(changeArr(arr)), onChangeFoo: (foo) => dispatch(changeFoo(foo)), onChangeBar: (bar) => dispatch(changeBar(bar)), onChangeBaz: (baz) => dispatch(changeBaz(baz)), onChangeMany: (foo) => dispatch(changeMany({ foo })), }; }
[ "function", "mapDispatchToProps", "(", "dispatch", ")", "{", "return", "{", "onChangeArr", ":", "(", "arr", ")", "=>", "dispatch", "(", "changeArr", "(", "arr", ")", ")", ",", "onChangeFoo", ":", "(", "foo", ")", "=>", "dispatch", "(", "changeFoo", "(", "foo", ")", ")", ",", "onChangeBar", ":", "(", "bar", ")", "=>", "dispatch", "(", "changeBar", "(", "bar", ")", ")", ",", "onChangeBaz", ":", "(", "baz", ")", "=>", "dispatch", "(", "changeBaz", "(", "baz", ")", ")", ",", "onChangeMany", ":", "(", "foo", ")", "=>", "dispatch", "(", "changeMany", "(", "{", "foo", "}", ")", ")", ",", "}", ";", "}" ]
Standard react-redux mapDispatchToProps
[ "Standard", "react", "-", "redux", "mapDispatchToProps" ]
14dde6c9e7f374cc92e13a4ed70a7462d250d073
https://github.com/pbeshai/react-url-query/blob/14dde6c9e7f374cc92e13a4ed70a7462d250d073/examples/redux-with-actions/src/MainPage.js#L37-L45
17,692
pbeshai/react-url-query
examples/basic-mapUrlToProps/src/MainPage.js
mapUrlToProps
function mapUrlToProps(url, props) { return { foo: decode(UrlQueryParamTypes.number, url.fooInUrl), bar: url.bar, }; }
javascript
function mapUrlToProps(url, props) { return { foo: decode(UrlQueryParamTypes.number, url.fooInUrl), bar: url.bar, }; }
[ "function", "mapUrlToProps", "(", "url", ",", "props", ")", "{", "return", "{", "foo", ":", "decode", "(", "UrlQueryParamTypes", ".", "number", ",", "url", ".", "fooInUrl", ")", ",", "bar", ":", "url", ".", "bar", ",", "}", ";", "}" ]
Map from url query params to props. The values in `url` will still be encoded as strings since we did not pass a `urlPropsQueryConfig` to addUrlProps.
[ "Map", "from", "url", "query", "params", "to", "props", ".", "The", "values", "in", "url", "will", "still", "be", "encoded", "as", "strings", "since", "we", "did", "not", "pass", "a", "urlPropsQueryConfig", "to", "addUrlProps", "." ]
14dde6c9e7f374cc92e13a4ed70a7462d250d073
https://github.com/pbeshai/react-url-query/blob/14dde6c9e7f374cc92e13a4ed70a7462d250d073/examples/basic-mapUrlToProps/src/MainPage.js#L9-L14
17,693
pbeshai/react-url-query
examples/basic-mapUrlToProps/src/MainPage.js
mapUrlChangeHandlersToProps
function mapUrlChangeHandlersToProps(props) { return { onChangeFoo: (value) => replaceInUrlQuery('fooInUrl', encode(UrlQueryParamTypes.number, value)), onChangeBar: (value) => replaceInUrlQuery('bar', value), } }
javascript
function mapUrlChangeHandlersToProps(props) { return { onChangeFoo: (value) => replaceInUrlQuery('fooInUrl', encode(UrlQueryParamTypes.number, value)), onChangeBar: (value) => replaceInUrlQuery('bar', value), } }
[ "function", "mapUrlChangeHandlersToProps", "(", "props", ")", "{", "return", "{", "onChangeFoo", ":", "(", "value", ")", "=>", "replaceInUrlQuery", "(", "'fooInUrl'", ",", "encode", "(", "UrlQueryParamTypes", ".", "number", ",", "value", ")", ")", ",", "onChangeBar", ":", "(", "value", ")", "=>", "replaceInUrlQuery", "(", "'bar'", ",", "value", ")", ",", "}", "}" ]
Manually specify how to deal with changes to URL query param props. We do this since we are not using a urlPropsQueryConfig.
[ "Manually", "specify", "how", "to", "deal", "with", "changes", "to", "URL", "query", "param", "props", ".", "We", "do", "this", "since", "we", "are", "not", "using", "a", "urlPropsQueryConfig", "." ]
14dde6c9e7f374cc92e13a4ed70a7462d250d073
https://github.com/pbeshai/react-url-query/blob/14dde6c9e7f374cc92e13a4ed70a7462d250d073/examples/basic-mapUrlToProps/src/MainPage.js#L20-L25
17,694
pbeshai/react-url-query
src/updateUrlQuery.js
multiUpdateInLocation
function multiUpdateInLocation(queryReplacements, location) { location = getLocation(location); // if a query is there, use it, otherwise parse the search string const currQuery = location.query || parseQueryString(location.search); const newQuery = { ...currQuery, ...queryReplacements, }; // remove if it is nully or an empty string when encoded Object.keys(queryReplacements).forEach(queryParam => { const encodedValue = queryReplacements[queryParam]; if (encodedValue == null || encodedValue === '') { delete newQuery[queryParam]; } }); const newLocation = mergeLocationQueryOrSearch(location, newQuery); // remove the key from the location delete newLocation.key; return newLocation; }
javascript
function multiUpdateInLocation(queryReplacements, location) { location = getLocation(location); // if a query is there, use it, otherwise parse the search string const currQuery = location.query || parseQueryString(location.search); const newQuery = { ...currQuery, ...queryReplacements, }; // remove if it is nully or an empty string when encoded Object.keys(queryReplacements).forEach(queryParam => { const encodedValue = queryReplacements[queryParam]; if (encodedValue == null || encodedValue === '') { delete newQuery[queryParam]; } }); const newLocation = mergeLocationQueryOrSearch(location, newQuery); // remove the key from the location delete newLocation.key; return newLocation; }
[ "function", "multiUpdateInLocation", "(", "queryReplacements", ",", "location", ")", "{", "location", "=", "getLocation", "(", "location", ")", ";", "// if a query is there, use it, otherwise parse the search string", "const", "currQuery", "=", "location", ".", "query", "||", "parseQueryString", "(", "location", ".", "search", ")", ";", "const", "newQuery", "=", "{", "...", "currQuery", ",", "...", "queryReplacements", ",", "}", ";", "// remove if it is nully or an empty string when encoded", "Object", ".", "keys", "(", "queryReplacements", ")", ".", "forEach", "(", "queryParam", "=>", "{", "const", "encodedValue", "=", "queryReplacements", "[", "queryParam", "]", ";", "if", "(", "encodedValue", "==", "null", "||", "encodedValue", "===", "''", ")", "{", "delete", "newQuery", "[", "queryParam", "]", ";", "}", "}", ")", ";", "const", "newLocation", "=", "mergeLocationQueryOrSearch", "(", "location", ",", "newQuery", ")", ";", "// remove the key from the location", "delete", "newLocation", ".", "key", ";", "return", "newLocation", ";", "}" ]
Update multiple parts of the location at once
[ "Update", "multiple", "parts", "of", "the", "location", "at", "once" ]
14dde6c9e7f374cc92e13a4ed70a7462d250d073
https://github.com/pbeshai/react-url-query/blob/14dde6c9e7f374cc92e13a4ed70a7462d250d073/src/updateUrlQuery.js#L89-L114
17,695
pbeshai/react-url-query
examples/react-router-v2-and-redux/src/state/rootReducer.js
app
function app(state = {}, action) { switch (action.type) { case CHANGE_BAZ: return { ...state, baz: action.payload, }; default: return state; } }
javascript
function app(state = {}, action) { switch (action.type) { case CHANGE_BAZ: return { ...state, baz: action.payload, }; default: return state; } }
[ "function", "app", "(", "state", "=", "{", "}", ",", "action", ")", "{", "switch", "(", "action", ".", "type", ")", "{", "case", "CHANGE_BAZ", ":", "return", "{", "...", "state", ",", "baz", ":", "action", ".", "payload", ",", "}", ";", "default", ":", "return", "state", ";", "}", "}" ]
Simple redux reducer that handles the CHANGE_BAZ action, updating the redux store to have the new value of baz.
[ "Simple", "redux", "reducer", "that", "handles", "the", "CHANGE_BAZ", "action", "updating", "the", "redux", "store", "to", "have", "the", "new", "value", "of", "baz", "." ]
14dde6c9e7f374cc92e13a4ed70a7462d250d073
https://github.com/pbeshai/react-url-query/blob/14dde6c9e7f374cc92e13a4ed70a7462d250d073/examples/react-router-v2-and-redux/src/state/rootReducer.js#L9-L19
17,696
google/tracing-framework
bin/dump.js
runTool
function runTool(platform, args_, done) { var args = optimist.argv; var allzones = args['allzones']; var inputFile = args['_'][0]; if (!inputFile) { console.log('usage: dump.js [--allzones] file.wtf-trace'); done(1); return; } console.log('Dumping ' + inputFile + '...'); console.log(''); wtf.db.load(inputFile, function(db) { if (db instanceof Error) { console.log('ERROR: unable to open ' + inputFile, db, db.stack); done(1); } else { done(dumpDatabase(db, allzones)); } }); }
javascript
function runTool(platform, args_, done) { var args = optimist.argv; var allzones = args['allzones']; var inputFile = args['_'][0]; if (!inputFile) { console.log('usage: dump.js [--allzones] file.wtf-trace'); done(1); return; } console.log('Dumping ' + inputFile + '...'); console.log(''); wtf.db.load(inputFile, function(db) { if (db instanceof Error) { console.log('ERROR: unable to open ' + inputFile, db, db.stack); done(1); } else { done(dumpDatabase(db, allzones)); } }); }
[ "function", "runTool", "(", "platform", ",", "args_", ",", "done", ")", "{", "var", "args", "=", "optimist", ".", "argv", ";", "var", "allzones", "=", "args", "[", "'allzones'", "]", ";", "var", "inputFile", "=", "args", "[", "'_'", "]", "[", "0", "]", ";", "if", "(", "!", "inputFile", ")", "{", "console", ".", "log", "(", "'usage: dump.js [--allzones] file.wtf-trace'", ")", ";", "done", "(", "1", ")", ";", "return", ";", "}", "console", ".", "log", "(", "'Dumping '", "+", "inputFile", "+", "'...'", ")", ";", "console", ".", "log", "(", "''", ")", ";", "wtf", ".", "db", ".", "load", "(", "inputFile", ",", "function", "(", "db", ")", "{", "if", "(", "db", "instanceof", "Error", ")", "{", "console", ".", "log", "(", "'ERROR: unable to open '", "+", "inputFile", ",", "db", ",", "db", ".", "stack", ")", ";", "done", "(", "1", ")", ";", "}", "else", "{", "done", "(", "dumpDatabase", "(", "db", ",", "allzones", ")", ")", ";", "}", "}", ")", ";", "}" ]
Dump tool. @param {!wtf.pal.IPlatform} platform Platform abstraction layer. @param {!Array.<string>} args Command line arguments. @param {function(number)} done Call to end the program with a return code.
[ "Dump", "tool", "." ]
495ced98de99a5895e484b2e09771edb42d3c7ab
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/dump.js#L28-L49
17,697
google/tracing-framework
bin/dump.js
dumpDatabase
function dumpDatabase(db, allzones) { var sources = db.getSources(); for (var n = 0; n < sources.length; n++) { util.logContextInfo(sources[n].getContextInfo()); } var zones = db.getZones(); if (!zones.length) { console.log('No zones'); return 0; } var count = allzones ? zones.length : 1; for (var i = 0; i < count; ++i) { var zone = zones[i]; var eventList = zone.getEventList(); var it = eventList.begin(); for (; !it.done(); it.next()) { util.logEvent(it, zone); } } return 0; }
javascript
function dumpDatabase(db, allzones) { var sources = db.getSources(); for (var n = 0; n < sources.length; n++) { util.logContextInfo(sources[n].getContextInfo()); } var zones = db.getZones(); if (!zones.length) { console.log('No zones'); return 0; } var count = allzones ? zones.length : 1; for (var i = 0; i < count; ++i) { var zone = zones[i]; var eventList = zone.getEventList(); var it = eventList.begin(); for (; !it.done(); it.next()) { util.logEvent(it, zone); } } return 0; }
[ "function", "dumpDatabase", "(", "db", ",", "allzones", ")", "{", "var", "sources", "=", "db", ".", "getSources", "(", ")", ";", "for", "(", "var", "n", "=", "0", ";", "n", "<", "sources", ".", "length", ";", "n", "++", ")", "{", "util", ".", "logContextInfo", "(", "sources", "[", "n", "]", ".", "getContextInfo", "(", ")", ")", ";", "}", "var", "zones", "=", "db", ".", "getZones", "(", ")", ";", "if", "(", "!", "zones", ".", "length", ")", "{", "console", ".", "log", "(", "'No zones'", ")", ";", "return", "0", ";", "}", "var", "count", "=", "allzones", "?", "zones", ".", "length", ":", "1", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "count", ";", "++", "i", ")", "{", "var", "zone", "=", "zones", "[", "i", "]", ";", "var", "eventList", "=", "zone", ".", "getEventList", "(", ")", ";", "var", "it", "=", "eventList", ".", "begin", "(", ")", ";", "for", "(", ";", "!", "it", ".", "done", "(", ")", ";", "it", ".", "next", "(", ")", ")", "{", "util", ".", "logEvent", "(", "it", ",", "zone", ")", ";", "}", "}", "return", "0", ";", "}" ]
Dump the database. @param {!wtf.db.Database} db Database. @param {!boolean} allzones Whether it's needed to dump all the zones or just the first one @return {number} Return code.
[ "Dump", "the", "database", "." ]
495ced98de99a5895e484b2e09771edb42d3c7ab
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/dump.js#L58-L81
17,698
google/tracing-framework
src/wtf/app/loader.js
finishLoad
function finishLoad() { // Pick a title, unless one was specified. var title = opt_title || this.generateTitleFromEntries_(entries); this.mainDisplay_.setTitle(title); // Show the document. var documentView = this.mainDisplay_.openDocument(doc); goog.asserts.assert(documentView); // Zoom to fit. // TODO(benvanik): remove setTimeout when zoomToFit is based on view. wtf.timing.setTimeout(50, function() { documentView.zoomToFit(); }, this); }
javascript
function finishLoad() { // Pick a title, unless one was specified. var title = opt_title || this.generateTitleFromEntries_(entries); this.mainDisplay_.setTitle(title); // Show the document. var documentView = this.mainDisplay_.openDocument(doc); goog.asserts.assert(documentView); // Zoom to fit. // TODO(benvanik): remove setTimeout when zoomToFit is based on view. wtf.timing.setTimeout(50, function() { documentView.zoomToFit(); }, this); }
[ "function", "finishLoad", "(", ")", "{", "// Pick a title, unless one was specified.", "var", "title", "=", "opt_title", "||", "this", ".", "generateTitleFromEntries_", "(", "entries", ")", ";", "this", ".", "mainDisplay_", ".", "setTitle", "(", "title", ")", ";", "// Show the document.", "var", "documentView", "=", "this", ".", "mainDisplay_", ".", "openDocument", "(", "doc", ")", ";", "goog", ".", "asserts", ".", "assert", "(", "documentView", ")", ";", "// Zoom to fit.", "// TODO(benvanik): remove setTimeout when zoomToFit is based on view.", "wtf", ".", "timing", ".", "setTimeout", "(", "50", ",", "function", "(", ")", "{", "documentView", ".", "zoomToFit", "(", ")", ";", "}", ",", "this", ")", ";", "}" ]
This is called after the dialog has closed to give it a chance to animate out.
[ "This", "is", "called", "after", "the", "dialog", "has", "closed", "to", "give", "it", "a", "chance", "to", "animate", "out", "." ]
495ced98de99a5895e484b2e09771edb42d3c7ab
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/app/loader.js#L428-L442
17,699
google/tracing-framework
extensions/wtf-injector-firefox/lib/main.js
acquireMemoryObserver
function acquireMemoryObserver() { // Only enable on first use. ++memoryObservationCount; if (memoryObservationCount > 1) { return; } // Enable memory notification. setTemporaryPreference('javascript.options.mem.notify', true); // Listen for events. Services.obs.addObserver( handleMemoryEvent, 'garbage-collection-statistics', false); }
javascript
function acquireMemoryObserver() { // Only enable on first use. ++memoryObservationCount; if (memoryObservationCount > 1) { return; } // Enable memory notification. setTemporaryPreference('javascript.options.mem.notify', true); // Listen for events. Services.obs.addObserver( handleMemoryEvent, 'garbage-collection-statistics', false); }
[ "function", "acquireMemoryObserver", "(", ")", "{", "// Only enable on first use.", "++", "memoryObservationCount", ";", "if", "(", "memoryObservationCount", ">", "1", ")", "{", "return", ";", "}", "// Enable memory notification.", "setTemporaryPreference", "(", "'javascript.options.mem.notify'", ",", "true", ")", ";", "// Listen for events.", "Services", ".", "obs", ".", "addObserver", "(", "handleMemoryEvent", ",", "'garbage-collection-statistics'", ",", "false", ")", ";", "}" ]
Acquires a reference to the memory observer, starting it if this is the first reference.
[ "Acquires", "a", "reference", "to", "the", "memory", "observer", "starting", "it", "if", "this", "is", "the", "first", "reference", "." ]
495ced98de99a5895e484b2e09771edb42d3c7ab
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L148-L161