id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
sequence
docstring
stringlengths
4
11.8k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
86
226
51,200
noblesamurai/noblerecord
src/migration.js
columnToSQL
function columnToSQL(col) { var sql = "`" + col.name + "` "; sql += nrutil.typeToSQL(col.type); if (col['additional']) { sql += ' ' + col['additional']; } if (!col['allow_null']) { sql += " NOT NULL"; } if (col['default_value'] !== undefined) { var def = col['default_value'] sql += " DEFAULT " + nrutil.serialize(def); } if (col.type == 'primary_key') { sql += " PRIMARY KEY AUTO_INCREMENT"; } return sql; }
javascript
function columnToSQL(col) { var sql = "`" + col.name + "` "; sql += nrutil.typeToSQL(col.type); if (col['additional']) { sql += ' ' + col['additional']; } if (!col['allow_null']) { sql += " NOT NULL"; } if (col['default_value'] !== undefined) { var def = col['default_value'] sql += " DEFAULT " + nrutil.serialize(def); } if (col.type == 'primary_key') { sql += " PRIMARY KEY AUTO_INCREMENT"; } return sql; }
[ "function", "columnToSQL", "(", "col", ")", "{", "var", "sql", "=", "\"`\"", "+", "col", ".", "name", "+", "\"` \"", ";", "sql", "+=", "nrutil", ".", "typeToSQL", "(", "col", ".", "type", ")", ";", "if", "(", "col", "[", "'additional'", "]", ")", "{", "sql", "+=", "' '", "+", "col", "[", "'additional'", "]", ";", "}", "if", "(", "!", "col", "[", "'allow_null'", "]", ")", "{", "sql", "+=", "\" NOT NULL\"", ";", "}", "if", "(", "col", "[", "'default_value'", "]", "!==", "undefined", ")", "{", "var", "def", "=", "col", "[", "'default_value'", "]", "sql", "+=", "\" DEFAULT \"", "+", "nrutil", ".", "serialize", "(", "def", ")", ";", "}", "if", "(", "col", ".", "type", "==", "'primary_key'", ")", "{", "sql", "+=", "\" PRIMARY KEY AUTO_INCREMENT\"", ";", "}", "return", "sql", ";", "}" ]
Generates the SQL fragment defining a given column.
[ "Generates", "the", "SQL", "fragment", "defining", "a", "given", "column", "." ]
fc7d3aac186598c4c7023f5448979d4162ab5e38
https://github.com/noblesamurai/noblerecord/blob/fc7d3aac186598c4c7023f5448979d4162ab5e38/src/migration.js#L26-L50
51,201
noblesamurai/noblerecord
src/migration.js
function(name, newname) { var act = new NobleMachine(function() { act.toNext(db.query("SHOW COLUMNS FROM `" + tablename + "`;")); }); act.next(function(result) { var sql = "ALTER TABLE `" + tablename + "` CHANGE `" + name + "` `" + newname + "`"; result.forEach(function(coldatum) { if (coldatum['Field'] == name) { sql += " " + coldatum['Type']; if (coldatum['Null'] == 'NO') { sql += " NOT NULL"; } if (coldatum['Key'] == 'PRI') { sql += " PRIMARY KEY"; } sql += coldatum['Extra']; if (coldatum['Default'] != 'NULL') { sql += " DEFAULT " + coldatum['Default']; } } }); sql += ";"; act.toNext(db.query(sql)); }); me.act.next(act); }
javascript
function(name, newname) { var act = new NobleMachine(function() { act.toNext(db.query("SHOW COLUMNS FROM `" + tablename + "`;")); }); act.next(function(result) { var sql = "ALTER TABLE `" + tablename + "` CHANGE `" + name + "` `" + newname + "`"; result.forEach(function(coldatum) { if (coldatum['Field'] == name) { sql += " " + coldatum['Type']; if (coldatum['Null'] == 'NO') { sql += " NOT NULL"; } if (coldatum['Key'] == 'PRI') { sql += " PRIMARY KEY"; } sql += coldatum['Extra']; if (coldatum['Default'] != 'NULL') { sql += " DEFAULT " + coldatum['Default']; } } }); sql += ";"; act.toNext(db.query(sql)); }); me.act.next(act); }
[ "function", "(", "name", ",", "newname", ")", "{", "var", "act", "=", "new", "NobleMachine", "(", "function", "(", ")", "{", "act", ".", "toNext", "(", "db", ".", "query", "(", "\"SHOW COLUMNS FROM `\"", "+", "tablename", "+", "\"`;\"", ")", ")", ";", "}", ")", ";", "act", ".", "next", "(", "function", "(", "result", ")", "{", "var", "sql", "=", "\"ALTER TABLE `\"", "+", "tablename", "+", "\"` CHANGE `\"", "+", "name", "+", "\"` `\"", "+", "newname", "+", "\"`\"", ";", "result", ".", "forEach", "(", "function", "(", "coldatum", ")", "{", "if", "(", "coldatum", "[", "'Field'", "]", "==", "name", ")", "{", "sql", "+=", "\" \"", "+", "coldatum", "[", "'Type'", "]", ";", "if", "(", "coldatum", "[", "'Null'", "]", "==", "'NO'", ")", "{", "sql", "+=", "\" NOT NULL\"", ";", "}", "if", "(", "coldatum", "[", "'Key'", "]", "==", "'PRI'", ")", "{", "sql", "+=", "\" PRIMARY KEY\"", ";", "}", "sql", "+=", "coldatum", "[", "'Extra'", "]", ";", "if", "(", "coldatum", "[", "'Default'", "]", "!=", "'NULL'", ")", "{", "sql", "+=", "\" DEFAULT \"", "+", "coldatum", "[", "'Default'", "]", ";", "}", "}", "}", ")", ";", "sql", "+=", "\";\"", ";", "act", ".", "toNext", "(", "db", ".", "query", "(", "sql", ")", ")", ";", "}", ")", ";", "me", ".", "act", ".", "next", "(", "act", ")", ";", "}" ]
There doesn't seem to be a proper RENAME COLUMN statement in MySQL. As such, it is necessary to use CHANGE after extracting the current column definition.
[ "There", "doesn", "t", "seem", "to", "be", "a", "proper", "RENAME", "COLUMN", "statement", "in", "MySQL", ".", "As", "such", "it", "is", "necessary", "to", "use", "CHANGE", "after", "extracting", "the", "current", "column", "definition", "." ]
fc7d3aac186598c4c7023f5448979d4162ab5e38
https://github.com/noblesamurai/noblerecord/blob/fc7d3aac186598c4c7023f5448979d4162ab5e38/src/migration.js#L109-L142
51,202
noblesamurai/noblerecord
src/migration.js
function() { var me = {}; var db = common.config.database; me.act = new NobleMachine(); return _.extend(me, { create_table: function(name, definer) { var t = new TableDefinition(name, 'create', definer); me.act.next(t.act); }, change_table: function(name, definer) { var t = new TableDefinition(name, 'alter', definer); me.act.next(t.act); }, drop_table: function(name) { me.act.next(db.query(" DROP TABLE `" + name + "`;")); }, rename_table: function(name, newname) { me.act.next(db.query(" ALTER TABLE `" + name + "` RENAME `" + newname + "`")); }, }); }
javascript
function() { var me = {}; var db = common.config.database; me.act = new NobleMachine(); return _.extend(me, { create_table: function(name, definer) { var t = new TableDefinition(name, 'create', definer); me.act.next(t.act); }, change_table: function(name, definer) { var t = new TableDefinition(name, 'alter', definer); me.act.next(t.act); }, drop_table: function(name) { me.act.next(db.query(" DROP TABLE `" + name + "`;")); }, rename_table: function(name, newname) { me.act.next(db.query(" ALTER TABLE `" + name + "` RENAME `" + newname + "`")); }, }); }
[ "function", "(", ")", "{", "var", "me", "=", "{", "}", ";", "var", "db", "=", "common", ".", "config", ".", "database", ";", "me", ".", "act", "=", "new", "NobleMachine", "(", ")", ";", "return", "_", ".", "extend", "(", "me", ",", "{", "create_table", ":", "function", "(", "name", ",", "definer", ")", "{", "var", "t", "=", "new", "TableDefinition", "(", "name", ",", "'create'", ",", "definer", ")", ";", "me", ".", "act", ".", "next", "(", "t", ".", "act", ")", ";", "}", ",", "change_table", ":", "function", "(", "name", ",", "definer", ")", "{", "var", "t", "=", "new", "TableDefinition", "(", "name", ",", "'alter'", ",", "definer", ")", ";", "me", ".", "act", ".", "next", "(", "t", ".", "act", ")", ";", "}", ",", "drop_table", ":", "function", "(", "name", ")", "{", "me", ".", "act", ".", "next", "(", "db", ".", "query", "(", "\" DROP TABLE `\"", "+", "name", "+", "\"`;\"", ")", ")", ";", "}", ",", "rename_table", ":", "function", "(", "name", ",", "newname", ")", "{", "me", ".", "act", ".", "next", "(", "db", ".", "query", "(", "\" ALTER TABLE `\"", "+", "name", "+", "\"` RENAME `\"", "+", "newname", "+", "\"`\"", ")", ")", ";", "}", ",", "}", ")", ";", "}" ]
Database definition class. Conglomerates TableDefinitions and SQL actions corresponding to friendly definition calls.
[ "Database", "definition", "class", ".", "Conglomerates", "TableDefinitions", "and", "SQL", "actions", "corresponding", "to", "friendly", "definition", "calls", "." ]
fc7d3aac186598c4c7023f5448979d4162ab5e38
https://github.com/noblesamurai/noblerecord/blob/fc7d3aac186598c4c7023f5448979d4162ab5e38/src/migration.js#L175-L200
51,203
jonschlinkert/verbalize
examples/index.js
helpPlugin
function helpPlugin() { return function(app) { // style to turn `[ ]` strings into // colored strings with backticks app.style('codify', function(msg) { var re = /\[([^\]]*\[?[^\]]*\]?[^[]*)\]/g; return msg.replace(re, function(str, code) { return this.red('`' + code + '`'); }.bind(this)); }); // style and format a single help command app.style('helpCommand', function(command) { var msg = ''; msg += this.bold(command.name.substr(0, 1).toUpperCase() + command.name.substr(1) + ': '); msg += this.bold(command.description); return msg; }); // style and format an array of help commands app.style('helpCommands', function(commands) { return commands .map(this.helpCommand) .join('\n\n'); }); // style and format a single example app.style('helpExample', function(example) { var msg = ''; msg += ' ' + this.gray('# ' + example.description) + '\n'; msg += ' ' + this.white('$ ' + example.command); return msg; }); // style and format an array of examples app.style('helpExamples', function(examples) { return examples .map(this.helpExample) .join('\n\n'); }); // style and format a single option app.style('helpOption', function(option) { var msg = ''; msg += ' ' + (option.flag ? this.bold(option.flag) : ' '); msg += ' ' + this.bold(option.name); msg += ' ' + this.bold(this.codify(option.description)); return msg; }); // style and format an array of options app.style('helpOptions', function(options) { return options .map(this.helpOption) .join('\n'); }); // style and formation a help text object using // other styles to break up responibilities app.emitter('help', function(help) { var msg = '\n'; msg += this.bold('Usage: ') + this.cyan(help.usage) + '\n\n'; msg += this.helpCommands(help.commands); if (help.examples && help.examples.length) { msg += this.bold('Examples:\n\n'); msg += this.helpExamples(help.examples); } if (help.options && help.options.length) { msg += this.bold('Options:\n\n'); msg += this.helpOptions(help.options); } return msg + '\n'; }); }; }
javascript
function helpPlugin() { return function(app) { // style to turn `[ ]` strings into // colored strings with backticks app.style('codify', function(msg) { var re = /\[([^\]]*\[?[^\]]*\]?[^[]*)\]/g; return msg.replace(re, function(str, code) { return this.red('`' + code + '`'); }.bind(this)); }); // style and format a single help command app.style('helpCommand', function(command) { var msg = ''; msg += this.bold(command.name.substr(0, 1).toUpperCase() + command.name.substr(1) + ': '); msg += this.bold(command.description); return msg; }); // style and format an array of help commands app.style('helpCommands', function(commands) { return commands .map(this.helpCommand) .join('\n\n'); }); // style and format a single example app.style('helpExample', function(example) { var msg = ''; msg += ' ' + this.gray('# ' + example.description) + '\n'; msg += ' ' + this.white('$ ' + example.command); return msg; }); // style and format an array of examples app.style('helpExamples', function(examples) { return examples .map(this.helpExample) .join('\n\n'); }); // style and format a single option app.style('helpOption', function(option) { var msg = ''; msg += ' ' + (option.flag ? this.bold(option.flag) : ' '); msg += ' ' + this.bold(option.name); msg += ' ' + this.bold(this.codify(option.description)); return msg; }); // style and format an array of options app.style('helpOptions', function(options) { return options .map(this.helpOption) .join('\n'); }); // style and formation a help text object using // other styles to break up responibilities app.emitter('help', function(help) { var msg = '\n'; msg += this.bold('Usage: ') + this.cyan(help.usage) + '\n\n'; msg += this.helpCommands(help.commands); if (help.examples && help.examples.length) { msg += this.bold('Examples:\n\n'); msg += this.helpExamples(help.examples); } if (help.options && help.options.length) { msg += this.bold('Options:\n\n'); msg += this.helpOptions(help.options); } return msg + '\n'; }); }; }
[ "function", "helpPlugin", "(", ")", "{", "return", "function", "(", "app", ")", "{", "// style to turn `[ ]` strings into", "// colored strings with backticks", "app", ".", "style", "(", "'codify'", ",", "function", "(", "msg", ")", "{", "var", "re", "=", "/", "\\[([^\\]]*\\[?[^\\]]*\\]?[^[]*)\\]", "/", "g", ";", "return", "msg", ".", "replace", "(", "re", ",", "function", "(", "str", ",", "code", ")", "{", "return", "this", ".", "red", "(", "'`'", "+", "code", "+", "'`'", ")", ";", "}", ".", "bind", "(", "this", ")", ")", ";", "}", ")", ";", "// style and format a single help command", "app", ".", "style", "(", "'helpCommand'", ",", "function", "(", "command", ")", "{", "var", "msg", "=", "''", ";", "msg", "+=", "this", ".", "bold", "(", "command", ".", "name", ".", "substr", "(", "0", ",", "1", ")", ".", "toUpperCase", "(", ")", "+", "command", ".", "name", ".", "substr", "(", "1", ")", "+", "': '", ")", ";", "msg", "+=", "this", ".", "bold", "(", "command", ".", "description", ")", ";", "return", "msg", ";", "}", ")", ";", "// style and format an array of help commands", "app", ".", "style", "(", "'helpCommands'", ",", "function", "(", "commands", ")", "{", "return", "commands", ".", "map", "(", "this", ".", "helpCommand", ")", ".", "join", "(", "'\\n\\n'", ")", ";", "}", ")", ";", "// style and format a single example", "app", ".", "style", "(", "'helpExample'", ",", "function", "(", "example", ")", "{", "var", "msg", "=", "''", ";", "msg", "+=", "' '", "+", "this", ".", "gray", "(", "'# '", "+", "example", ".", "description", ")", "+", "'\\n'", ";", "msg", "+=", "' '", "+", "this", ".", "white", "(", "'$ '", "+", "example", ".", "command", ")", ";", "return", "msg", ";", "}", ")", ";", "// style and format an array of examples", "app", ".", "style", "(", "'helpExamples'", ",", "function", "(", "examples", ")", "{", "return", "examples", ".", "map", "(", "this", ".", "helpExample", ")", ".", "join", "(", "'\\n\\n'", ")", ";", "}", ")", ";", "// style and format a single option", "app", ".", "style", "(", "'helpOption'", ",", "function", "(", "option", ")", "{", "var", "msg", "=", "''", ";", "msg", "+=", "' '", "+", "(", "option", ".", "flag", "?", "this", ".", "bold", "(", "option", ".", "flag", ")", ":", "' '", ")", ";", "msg", "+=", "' '", "+", "this", ".", "bold", "(", "option", ".", "name", ")", ";", "msg", "+=", "' '", "+", "this", ".", "bold", "(", "this", ".", "codify", "(", "option", ".", "description", ")", ")", ";", "return", "msg", ";", "}", ")", ";", "// style and format an array of options", "app", ".", "style", "(", "'helpOptions'", ",", "function", "(", "options", ")", "{", "return", "options", ".", "map", "(", "this", ".", "helpOption", ")", ".", "join", "(", "'\\n'", ")", ";", "}", ")", ";", "// style and formation a help text object using", "// other styles to break up responibilities", "app", ".", "emitter", "(", "'help'", ",", "function", "(", "help", ")", "{", "var", "msg", "=", "'\\n'", ";", "msg", "+=", "this", ".", "bold", "(", "'Usage: '", ")", "+", "this", ".", "cyan", "(", "help", ".", "usage", ")", "+", "'\\n\\n'", ";", "msg", "+=", "this", ".", "helpCommands", "(", "help", ".", "commands", ")", ";", "if", "(", "help", ".", "examples", "&&", "help", ".", "examples", ".", "length", ")", "{", "msg", "+=", "this", ".", "bold", "(", "'Examples:\\n\\n'", ")", ";", "msg", "+=", "this", ".", "helpExamples", "(", "help", ".", "examples", ")", ";", "}", "if", "(", "help", ".", "options", "&&", "help", ".", "options", ".", "length", ")", "{", "msg", "+=", "this", ".", "bold", "(", "'Options:\\n\\n'", ")", ";", "msg", "+=", "this", ".", "helpOptions", "(", "help", ".", "options", ")", ";", "}", "return", "msg", "+", "'\\n'", ";", "}", ")", ";", "}", ";", "}" ]
This plugin adds styles and emitters to make it easier to log out help text
[ "This", "plugin", "adds", "styles", "and", "emitters", "to", "make", "it", "easier", "to", "log", "out", "help", "text" ]
3d590602fde6a13682d0eebc180c731ea386b64f
https://github.com/jonschlinkert/verbalize/blob/3d590602fde6a13682d0eebc180c731ea386b64f/examples/index.js#L20-L98
51,204
tolokoban/ToloFrameWork
lib/util.js
removeDoubles
function removeDoubles( arrInput ) { const arrOutput = [], map = {}; arrInput.forEach( function forEachItem( itm ) { if ( itm in map ) return; map[ itm ] = 1; arrOutput.push( itm ); } ); return arrOutput; }
javascript
function removeDoubles( arrInput ) { const arrOutput = [], map = {}; arrInput.forEach( function forEachItem( itm ) { if ( itm in map ) return; map[ itm ] = 1; arrOutput.push( itm ); } ); return arrOutput; }
[ "function", "removeDoubles", "(", "arrInput", ")", "{", "const", "arrOutput", "=", "[", "]", ",", "map", "=", "{", "}", ";", "arrInput", ".", "forEach", "(", "function", "forEachItem", "(", "itm", ")", "{", "if", "(", "itm", "in", "map", ")", "return", ";", "map", "[", "itm", "]", "=", "1", ";", "arrOutput", ".", "push", "(", "itm", ")", ";", "}", ")", ";", "return", "arrOutput", ";", "}" ]
Return a copy of an array after removing all doubles. @param {array} arrInput array of any comparable object. @returns {array} A copy of the input array without doubles.
[ "Return", "a", "copy", "of", "an", "array", "after", "removing", "all", "doubles", "." ]
730845a833a9660ebfdb60ad027ebaab5ac871b6
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/util.js#L307-L317
51,205
tolokoban/ToloFrameWork
lib/util.js
cleanDir
function cleanDir( path, _preserveGit ) { const preserveGit = typeof _preserveGit !== 'undefined' ? _preserveGit : false, fullPath = Path.resolve( path ); // If the pah does not exist, everything is fine! if ( !FS.existsSync( fullPath ) ) return; if ( preserveGit ) { /* * We must delete the content of this folder but preserve `.git`. * The `www` dir, for instance, can be used as a `gh-pages` branch. */ const files = FS.readdirSync( path ); files.forEach( function forEachFile( filename ) { if ( filename === '.git' ) return; const filepath = Path.join( path, filename ), stat = FS.statSync( filepath ); if ( stat.isDirectory() ) { if ( filepath !== '.' && filepath !== '..' ) PathUtils.rmdir( filepath ); } else FS.unlinkSync( filepath ); } ); } else { // Brutal clean: remove dir and recreate it. PathUtils.rmdir( path ); PathUtils.mkdir( path ); } }
javascript
function cleanDir( path, _preserveGit ) { const preserveGit = typeof _preserveGit !== 'undefined' ? _preserveGit : false, fullPath = Path.resolve( path ); // If the pah does not exist, everything is fine! if ( !FS.existsSync( fullPath ) ) return; if ( preserveGit ) { /* * We must delete the content of this folder but preserve `.git`. * The `www` dir, for instance, can be used as a `gh-pages` branch. */ const files = FS.readdirSync( path ); files.forEach( function forEachFile( filename ) { if ( filename === '.git' ) return; const filepath = Path.join( path, filename ), stat = FS.statSync( filepath ); if ( stat.isDirectory() ) { if ( filepath !== '.' && filepath !== '..' ) PathUtils.rmdir( filepath ); } else FS.unlinkSync( filepath ); } ); } else { // Brutal clean: remove dir and recreate it. PathUtils.rmdir( path ); PathUtils.mkdir( path ); } }
[ "function", "cleanDir", "(", "path", ",", "_preserveGit", ")", "{", "const", "preserveGit", "=", "typeof", "_preserveGit", "!==", "'undefined'", "?", "_preserveGit", ":", "false", ",", "fullPath", "=", "Path", ".", "resolve", "(", "path", ")", ";", "// If the pah does not exist, everything is fine!", "if", "(", "!", "FS", ".", "existsSync", "(", "fullPath", ")", ")", "return", ";", "if", "(", "preserveGit", ")", "{", "/*\n * We must delete the content of this folder but preserve `.git`.\n * The `www` dir, for instance, can be used as a `gh-pages` branch.\n */", "const", "files", "=", "FS", ".", "readdirSync", "(", "path", ")", ";", "files", ".", "forEach", "(", "function", "forEachFile", "(", "filename", ")", "{", "if", "(", "filename", "===", "'.git'", ")", "return", ";", "const", "filepath", "=", "Path", ".", "join", "(", "path", ",", "filename", ")", ",", "stat", "=", "FS", ".", "statSync", "(", "filepath", ")", ";", "if", "(", "stat", ".", "isDirectory", "(", ")", ")", "{", "if", "(", "filepath", "!==", "'.'", "&&", "filepath", "!==", "'..'", ")", "PathUtils", ".", "rmdir", "(", "filepath", ")", ";", "}", "else", "FS", ".", "unlinkSync", "(", "filepath", ")", ";", "}", ")", ";", "}", "else", "{", "// Brutal clean: remove dir and recreate it.", "PathUtils", ".", "rmdir", "(", "path", ")", ";", "PathUtils", ".", "mkdir", "(", "path", ")", ";", "}", "}" ]
Remove all files and directories found in `path`, but not `path` itself. @param {string} path - The folder we want to clean the content. @param {boolean} _preserveGit [false] - If `true`, the folder ".git" is not deleted. @returns {undefined}
[ "Remove", "all", "files", "and", "directories", "found", "in", "path", "but", "not", "path", "itself", "." ]
730845a833a9660ebfdb60ad027ebaab5ac871b6
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/util.js#L325-L353
51,206
tolokoban/ToloFrameWork
lib/util.js
isNewerThan
function isNewerThan( inputs, target ) { if ( !FS.existsSync( target ) ) return true; const files = Array.isArray( inputs ) ? inputs : [ inputs ], statTarget = FS.statSync( target ), targetTime = statTarget.mtime; for ( const file of files ) { if ( !FS.existsSync( file ) ) continue; const stat = FS.statSync( file ); if ( stat.mtime > targetTime ) { return true; } } return false; }
javascript
function isNewerThan( inputs, target ) { if ( !FS.existsSync( target ) ) return true; const files = Array.isArray( inputs ) ? inputs : [ inputs ], statTarget = FS.statSync( target ), targetTime = statTarget.mtime; for ( const file of files ) { if ( !FS.existsSync( file ) ) continue; const stat = FS.statSync( file ); if ( stat.mtime > targetTime ) { return true; } } return false; }
[ "function", "isNewerThan", "(", "inputs", ",", "target", ")", "{", "if", "(", "!", "FS", ".", "existsSync", "(", "target", ")", ")", "return", "true", ";", "const", "files", "=", "Array", ".", "isArray", "(", "inputs", ")", "?", "inputs", ":", "[", "inputs", "]", ",", "statTarget", "=", "FS", ".", "statSync", "(", "target", ")", ",", "targetTime", "=", "statTarget", ".", "mtime", ";", "for", "(", "const", "file", "of", "files", ")", "{", "if", "(", "!", "FS", ".", "existsSync", "(", "file", ")", ")", "continue", ";", "const", "stat", "=", "FS", ".", "statSync", "(", "file", ")", ";", "if", "(", "stat", ".", "mtime", ">", "targetTime", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check if at least one file is newer than the target one. @param {array} inputs - Array of files (with full path) to compare to `target`. @param {string} target - Full path of the reference file. @returns {Boolean} `true` if `target` does not exist, or if at leat one input is newer than `target`.
[ "Check", "if", "at", "least", "one", "file", "is", "newer", "than", "the", "target", "one", "." ]
730845a833a9660ebfdb60ad027ebaab5ac871b6
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/util.js#L467-L483
51,207
keleko34/KObservableData
KObservableData/KObservableData.js
addData
function addData(a) { if(isObject(a.event.value) || isArray(a.event.value)) { if(!isObservable(a.event.value)) { a.preventDefault(); var local = a.event.local, str = local.__kbscopeString+(local.__kbscopeString.length !== 0 ? '.' : '')+a.key, builder = (isObject(a.event.value) ? KObject : KArray)(local.__kbname,local,str); overwrite(builder).parseData(a.event.value); if(local[a.key] === undefined) { local.add(a.key,builder); } else if(isArray(local)) { local.splice(a.key,0,builder); } else if(isObject(local)) { local.set(a.key,builder); } } } }
javascript
function addData(a) { if(isObject(a.event.value) || isArray(a.event.value)) { if(!isObservable(a.event.value)) { a.preventDefault(); var local = a.event.local, str = local.__kbscopeString+(local.__kbscopeString.length !== 0 ? '.' : '')+a.key, builder = (isObject(a.event.value) ? KObject : KArray)(local.__kbname,local,str); overwrite(builder).parseData(a.event.value); if(local[a.key] === undefined) { local.add(a.key,builder); } else if(isArray(local)) { local.splice(a.key,0,builder); } else if(isObject(local)) { local.set(a.key,builder); } } } }
[ "function", "addData", "(", "a", ")", "{", "if", "(", "isObject", "(", "a", ".", "event", ".", "value", ")", "||", "isArray", "(", "a", ".", "event", ".", "value", ")", ")", "{", "if", "(", "!", "isObservable", "(", "a", ".", "event", ".", "value", ")", ")", "{", "a", ".", "preventDefault", "(", ")", ";", "var", "local", "=", "a", ".", "event", ".", "local", ",", "str", "=", "local", ".", "__kbscopeString", "+", "(", "local", ".", "__kbscopeString", ".", "length", "!==", "0", "?", "'.'", ":", "''", ")", "+", "a", ".", "key", ",", "builder", "=", "(", "isObject", "(", "a", ".", "event", ".", "value", ")", "?", "KObject", ":", "KArray", ")", "(", "local", ".", "__kbname", ",", "local", ",", "str", ")", ";", "overwrite", "(", "builder", ")", ".", "parseData", "(", "a", ".", "event", ".", "value", ")", ";", "if", "(", "local", "[", "a", ".", "key", "]", "===", "undefined", ")", "{", "local", ".", "add", "(", "a", ".", "key", ",", "builder", ")", ";", "}", "else", "if", "(", "isArray", "(", "local", ")", ")", "{", "local", ".", "splice", "(", "a", ".", "key", ",", "0", ",", "builder", ")", ";", "}", "else", "if", "(", "isObject", "(", "local", ")", ")", "{", "local", ".", "set", "(", "a", ".", "key", ",", "builder", ")", ";", "}", "}", "}", "}" ]
these take care of recursion for us
[ "these", "take", "care", "of", "recursion", "for", "us" ]
22a3637cba73be7533a76141803644472443b606
https://github.com/keleko34/KObservableData/blob/22a3637cba73be7533a76141803644472443b606/KObservableData/KObservableData.js#L269-L295
51,208
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
SyntaxUnit
function SyntaxUnit(text, line, col){ /** * The column of text on which the unit resides. * @type int * @property col */ this.col = col; /** * The line of text on which the unit resides. * @type int * @property line */ this.line = line; /** * The text representation of the unit. * @type String * @property text */ this.text = text; }
javascript
function SyntaxUnit(text, line, col){ /** * The column of text on which the unit resides. * @type int * @property col */ this.col = col; /** * The line of text on which the unit resides. * @type int * @property line */ this.line = line; /** * The text representation of the unit. * @type String * @property text */ this.text = text; }
[ "function", "SyntaxUnit", "(", "text", ",", "line", ",", "col", ")", "{", "/**\n * The column of text on which the unit resides.\n * @type int\n * @property col\n */", "this", ".", "col", "=", "col", ";", "/**\n * The line of text on which the unit resides.\n * @type int\n * @property line\n */", "this", ".", "line", "=", "line", ";", "/**\n * The text representation of the unit.\n * @type String\n * @property text\n */", "this", ".", "text", "=", "text", ";", "}" ]
Base type to represent a single syntactic unit. @class SyntaxUnit @namespace parserlib.util @constructor @param {String} text The text of the unit. @param {int} line The line of text on which the unit resides. @param {int} col The column of text on which the unit resides.
[ "Base", "type", "to", "represent", "a", "single", "syntactic", "unit", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L452-L476
51,209
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function(type, listener){ if (this._handlers[type] instanceof Array){ var handlers = this._handlers[type]; for (var i=0, len=handlers.length; i < len; i++){ if (handlers[i] === listener){ handlers.splice(i, 1); break; } } } }
javascript
function(type, listener){ if (this._handlers[type] instanceof Array){ var handlers = this._handlers[type]; for (var i=0, len=handlers.length; i < len; i++){ if (handlers[i] === listener){ handlers.splice(i, 1); break; } } } }
[ "function", "(", "type", ",", "listener", ")", "{", "if", "(", "this", ".", "_handlers", "[", "type", "]", "instanceof", "Array", ")", "{", "var", "handlers", "=", "this", ".", "_handlers", "[", "type", "]", ";", "for", "(", "var", "i", "=", "0", ",", "len", "=", "handlers", ".", "length", ";", "i", "<", "len", ";", "i", "++", ")", "{", "if", "(", "handlers", "[", "i", "]", "===", "listener", ")", "{", "handlers", ".", "splice", "(", "i", ",", "1", ")", ";", "break", ";", "}", "}", "}", "}" ]
Removes a listener for a given event type. @param {String} type The type of event to remove a listener from. @param {Function} listener The function to remove from the event. @return {void} @method detach
[ "Removes", "a", "listener", "for", "a", "given", "event", "type", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L4912-L4922
51,210
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function(receiver, supplier){ for (var prop in supplier){ if (supplier.hasOwnProperty(prop)){ receiver[prop] = supplier[prop]; } } return receiver; }
javascript
function(receiver, supplier){ for (var prop in supplier){ if (supplier.hasOwnProperty(prop)){ receiver[prop] = supplier[prop]; } } return receiver; }
[ "function", "(", "receiver", ",", "supplier", ")", "{", "for", "(", "var", "prop", "in", "supplier", ")", "{", "if", "(", "supplier", ".", "hasOwnProperty", "(", "prop", ")", ")", "{", "receiver", "[", "prop", "]", "=", "supplier", "[", "prop", "]", ";", "}", "}", "return", "receiver", ";", "}" ]
Mixes the own properties from the supplier onto the receiver. @param {Object} receiver The object to receive the properties. @param {Object} supplier The object to supply the properties. @return {Object} The receiver that was passed in. @method mix @static
[ "Mixes", "the", "own", "properties", "from", "the", "supplier", "onto", "the", "receiver", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L4956-L4965
51,211
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (expected, actual, message) { YUITest.Assert._increment(); if (expected !== actual) { throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Values should be the same."), expected, actual); } }
javascript
function (expected, actual, message) { YUITest.Assert._increment(); if (expected !== actual) { throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Values should be the same."), expected, actual); } }
[ "function", "(", "expected", ",", "actual", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "expected", "!==", "actual", ")", "{", "throw", "new", "YUITest", ".", "ComparisonFailure", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Values should be the same.\"", ")", ",", "expected", ",", "actual", ")", ";", "}", "}" ]
Asserts that a value is the same as another. This uses the triple equals sign so no type cohersion may occur. @param {Object} expected The expected value. @param {Object} actual The actual value to test. @param {String} message (Optional) The message to display if the assertion fails. @method areSame @static
[ "Asserts", "that", "a", "value", "is", "the", "same", "as", "another", ".", "This", "uses", "the", "triple", "equals", "sign", "so", "no", "type", "cohersion", "may", "occur", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L5429-L5434
51,212
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (actual, message) { YUITest.Assert._increment(); if (true !== actual) { throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Value should be true."), true, actual); } }
javascript
function (actual, message) { YUITest.Assert._increment(); if (true !== actual) { throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Value should be true."), true, actual); } }
[ "function", "(", "actual", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "true", "!==", "actual", ")", "{", "throw", "new", "YUITest", ".", "ComparisonFailure", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Value should be true.\"", ")", ",", "true", ",", "actual", ")", ";", "}", "}" ]
Asserts that a value is true. This uses the triple equals sign so no type cohersion may occur. @param {Object} actual The actual value to test. @param {String} message (Optional) The message to display if the assertion fails. @method isTrue @static
[ "Asserts", "that", "a", "value", "is", "true", ".", "This", "uses", "the", "triple", "equals", "sign", "so", "no", "type", "cohersion", "may", "occur", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L5463-L5469
51,213
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (actual, message) { YUITest.Assert._increment(); if (actual !== null) { throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Value should be null."), null, actual); } }
javascript
function (actual, message) { YUITest.Assert._increment(); if (actual !== null) { throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Value should be null."), null, actual); } }
[ "function", "(", "actual", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "actual", "!==", "null", ")", "{", "throw", "new", "YUITest", ".", "ComparisonFailure", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Value should be null.\"", ")", ",", "null", ",", "actual", ")", ";", "}", "}" ]
Asserts that a value is null. This uses the triple equals sign so no type cohersion may occur. @param {Object} actual The actual value to test. @param {String} message (Optional) The message to display if the assertion fails. @method isNull @static
[ "Asserts", "that", "a", "value", "is", "null", ".", "This", "uses", "the", "triple", "equals", "sign", "so", "no", "type", "cohersion", "may", "occur", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L5541-L5546
51,214
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (actual, message) { YUITest.Assert._increment(); if (typeof actual != "undefined") { throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Value should be undefined."), undefined, actual); } }
javascript
function (actual, message) { YUITest.Assert._increment(); if (typeof actual != "undefined") { throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Value should be undefined."), undefined, actual); } }
[ "function", "(", "actual", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "typeof", "actual", "!=", "\"undefined\"", ")", "{", "throw", "new", "YUITest", ".", "ComparisonFailure", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Value should be undefined.\"", ")", ",", "undefined", ",", "actual", ")", ";", "}", "}" ]
Asserts that a value is undefined. This uses the triple equals sign so no type cohersion may occur. @param {Object} actual The actual value to test. @param {String} message (Optional) The message to display if the assertion fails. @method isUndefined @static
[ "Asserts", "that", "a", "value", "is", "undefined", ".", "This", "uses", "the", "triple", "equals", "sign", "so", "no", "type", "cohersion", "may", "occur", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L5556-L5561
51,215
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (actual, message) { YUITest.Assert._increment(); if (typeof actual != "boolean"){ throw new YUITest.UnexpectedValue(YUITest.Assert._formatMessage(message, "Value should be a Boolean."), actual); } }
javascript
function (actual, message) { YUITest.Assert._increment(); if (typeof actual != "boolean"){ throw new YUITest.UnexpectedValue(YUITest.Assert._formatMessage(message, "Value should be a Boolean."), actual); } }
[ "function", "(", "actual", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "typeof", "actual", "!=", "\"boolean\"", ")", "{", "throw", "new", "YUITest", ".", "UnexpectedValue", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Value should be a Boolean.\"", ")", ",", "actual", ")", ";", "}", "}" ]
Asserts that a value is a Boolean. @param {Object} actual The value to test. @param {String} message (Optional) The message to display if the assertion fails. @method isBoolean @static
[ "Asserts", "that", "a", "value", "is", "a", "Boolean", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L5594-L5599
51,216
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (expectedType, actualValue, message){ YUITest.Assert._increment(); if (typeof actualValue != expectedType){ throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Value should be of type " + expectedType + "."), expectedType, typeof actualValue); } }
javascript
function (expectedType, actualValue, message){ YUITest.Assert._increment(); if (typeof actualValue != expectedType){ throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Value should be of type " + expectedType + "."), expectedType, typeof actualValue); } }
[ "function", "(", "expectedType", ",", "actualValue", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "typeof", "actualValue", "!=", "expectedType", ")", "{", "throw", "new", "YUITest", ".", "ComparisonFailure", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Value should be of type \"", "+", "expectedType", "+", "\".\"", ")", ",", "expectedType", ",", "typeof", "actualValue", ")", ";", "}", "}" ]
Asserts that a value is of a particular type. @param {String} expectedType The expected type of the variable. @param {Object} actualValue The actual value to test. @param {String} message (Optional) The message to display if the assertion fails. @method isTypeOf @static
[ "Asserts", "that", "a", "value", "is", "of", "a", "particular", "type", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L5682-L5687
51,217
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (needle, haystack, message) { YUITest.Assert._increment(); if (this._indexOf(haystack, needle) == -1){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Value " + needle + " (" + (typeof needle) + ") not found in array [" + haystack + "].")); } }
javascript
function (needle, haystack, message) { YUITest.Assert._increment(); if (this._indexOf(haystack, needle) == -1){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Value " + needle + " (" + (typeof needle) + ") not found in array [" + haystack + "].")); } }
[ "function", "(", "needle", ",", "haystack", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "this", ".", "_indexOf", "(", "haystack", ",", "needle", ")", "==", "-", "1", ")", "{", "YUITest", ".", "Assert", ".", "fail", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Value \"", "+", "needle", "+", "\" (\"", "+", "(", "typeof", "needle", ")", "+", "\") not found in array [\"", "+", "haystack", "+", "\"].\"", ")", ")", ";", "}", "}" ]
Asserts that a value is present in an array. This uses the triple equals sign so no type cohersion may occur. @param {Object} needle The value that is expected in the array. @param {Array} haystack An array of values. @param {String} message (Optional) The message to display if the assertion fails. @method contains @static
[ "Asserts", "that", "a", "value", "is", "present", "in", "an", "array", ".", "This", "uses", "the", "triple", "equals", "sign", "so", "no", "type", "cohersion", "may", "occur", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L5824-L5832
51,218
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (needles, haystack, message) { YUITest.Assert._increment(); for (var i=0; i < needles.length; i++){ if (this._indexOf(haystack, needles[i]) > -1){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Value found in array [" + haystack + "].")); } } }
javascript
function (needles, haystack, message) { YUITest.Assert._increment(); for (var i=0; i < needles.length; i++){ if (this._indexOf(haystack, needles[i]) > -1){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Value found in array [" + haystack + "].")); } } }
[ "function", "(", "needles", ",", "haystack", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "needles", ".", "length", ";", "i", "++", ")", "{", "if", "(", "this", ".", "_indexOf", "(", "haystack", ",", "needles", "[", "i", "]", ")", ">", "-", "1", ")", "{", "YUITest", ".", "Assert", ".", "fail", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Value found in array [\"", "+", "haystack", "+", "\"].\"", ")", ")", ";", "}", "}", "}" ]
Asserts that a set of values are not present in an array. This uses the triple equals sign so no type cohersion may occur. For this assertion to pass, all values must not be found. @param {Object[]} needles An array of values that are not expected in the array. @param {Array} haystack An array of values to check. @param {String} message (Optional) The message to display if the assertion fails. @method doesNotContainItems @static
[ "Asserts", "that", "a", "set", "of", "values", "are", "not", "present", "in", "an", "array", ".", "This", "uses", "the", "triple", "equals", "sign", "so", "no", "type", "cohersion", "may", "occur", ".", "For", "this", "assertion", "to", "pass", "all", "values", "must", "not", "be", "found", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L5909-L5920
51,219
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (matcher, haystack, message) { YUITest.Assert._increment(); //check for valid matcher if (typeof matcher != "function"){ throw new TypeError("ArrayAssert.doesNotContainMatch(): First argument must be a function."); } if (this._some(haystack, matcher)){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Value found in array [" + haystack + "].")); } }
javascript
function (matcher, haystack, message) { YUITest.Assert._increment(); //check for valid matcher if (typeof matcher != "function"){ throw new TypeError("ArrayAssert.doesNotContainMatch(): First argument must be a function."); } if (this._some(haystack, matcher)){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Value found in array [" + haystack + "].")); } }
[ "function", "(", "matcher", ",", "haystack", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "//check for valid matcher", "if", "(", "typeof", "matcher", "!=", "\"function\"", ")", "{", "throw", "new", "TypeError", "(", "\"ArrayAssert.doesNotContainMatch(): First argument must be a function.\"", ")", ";", "}", "if", "(", "this", ".", "_some", "(", "haystack", ",", "matcher", ")", ")", "{", "YUITest", ".", "Assert", ".", "fail", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Value found in array [\"", "+", "haystack", "+", "\"].\"", ")", ")", ";", "}", "}" ]
Asserts that no values matching a condition are present in an array. This uses a function to determine a match. @param {Function} matcher A function that returns true if the item matches or false if not. @param {Array} haystack An array of values. @param {String} message (Optional) The message to display if the assertion fails. @method doesNotContainMatch @static
[ "Asserts", "that", "no", "values", "matching", "a", "condition", "are", "present", "in", "an", "array", ".", "This", "uses", "a", "function", "to", "determine", "a", "match", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L5931-L5944
51,220
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (expected, actual, message) { YUITest.Assert._increment(); //first check array length if (expected.length != actual.length){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Array should have a length of " + expected.length + " but has a length of " + actual.length)); } //begin checking values for (var i=0; i < expected.length; i++){ if (expected[i] != actual[i]){ throw new YUITest.Assert.ComparisonFailure(YUITest.Assert._formatMessage(message, "Values in position " + i + " are not equal."), expected[i], actual[i]); } } }
javascript
function (expected, actual, message) { YUITest.Assert._increment(); //first check array length if (expected.length != actual.length){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Array should have a length of " + expected.length + " but has a length of " + actual.length)); } //begin checking values for (var i=0; i < expected.length; i++){ if (expected[i] != actual[i]){ throw new YUITest.Assert.ComparisonFailure(YUITest.Assert._formatMessage(message, "Values in position " + i + " are not equal."), expected[i], actual[i]); } } }
[ "function", "(", "expected", ",", "actual", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "//first check array length", "if", "(", "expected", ".", "length", "!=", "actual", ".", "length", ")", "{", "YUITest", ".", "Assert", ".", "fail", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Array should have a length of \"", "+", "expected", ".", "length", "+", "\" but has a length of \"", "+", "actual", ".", "length", ")", ")", ";", "}", "//begin checking values", "for", "(", "var", "i", "=", "0", ";", "i", "<", "expected", ".", "length", ";", "i", "++", ")", "{", "if", "(", "expected", "[", "i", "]", "!=", "actual", "[", "i", "]", ")", "{", "throw", "new", "YUITest", ".", "Assert", ".", "ComparisonFailure", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Values in position \"", "+", "i", "+", "\" are not equal.\"", ")", ",", "expected", "[", "i", "]", ",", "actual", "[", "i", "]", ")", ";", "}", "}", "}" ]
Asserts that the values in an array are equal, and in the same position, as values in another array. This uses the double equals sign so type cohersion may occur. Note that the array objects themselves need not be the same for this test to pass. @param {Array} expected An array of the expected values. @param {Array} actual Any array of the actual values. @param {String} message (Optional) The message to display if the assertion fails. @method itemsAreEqual @static
[ "Asserts", "that", "the", "values", "in", "an", "array", "are", "equal", "and", "in", "the", "same", "position", "as", "values", "in", "another", "array", ".", "This", "uses", "the", "double", "equals", "sign", "so", "type", "cohersion", "may", "occur", ".", "Note", "that", "the", "array", "objects", "themselves", "need", "not", "be", "the", "same", "for", "this", "test", "to", "pass", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L5985-L6001
51,221
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (actual, message) { YUITest.Assert._increment(); if (actual.length > 0){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Array should be empty.")); } }
javascript
function (actual, message) { YUITest.Assert._increment(); if (actual.length > 0){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Array should be empty.")); } }
[ "function", "(", "actual", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "actual", ".", "length", ">", "0", ")", "{", "YUITest", ".", "Assert", ".", "fail", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Array should be empty.\"", ")", ")", ";", "}", "}" ]
Asserts that an array is empty. @param {Array} actual The array to test. @param {String} message (Optional) The message to display if the assertion fails. @method isEmpty @static
[ "Asserts", "that", "an", "array", "is", "empty", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6047-L6052
51,222
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (needle, haystack, index, message) { //try to find the value in the array for (var i=haystack.length; i >= 0; i--){ if (haystack[i] === needle){ if (index != i){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Value exists at index " + i + " but should be at index " + index + ".")); } return; } } //if it makes it here, it wasn't found at all YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Value doesn't exist in array.")); }
javascript
function (needle, haystack, index, message) { //try to find the value in the array for (var i=haystack.length; i >= 0; i--){ if (haystack[i] === needle){ if (index != i){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Value exists at index " + i + " but should be at index " + index + ".")); } return; } } //if it makes it here, it wasn't found at all YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Value doesn't exist in array.")); }
[ "function", "(", "needle", ",", "haystack", ",", "index", ",", "message", ")", "{", "//try to find the value in the array", "for", "(", "var", "i", "=", "haystack", ".", "length", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "if", "(", "haystack", "[", "i", "]", "===", "needle", ")", "{", "if", "(", "index", "!=", "i", ")", "{", "YUITest", ".", "Assert", ".", "fail", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Value exists at index \"", "+", "i", "+", "\" but should be at index \"", "+", "index", "+", "\".\"", ")", ")", ";", "}", "return", ";", "}", "}", "//if it makes it here, it wasn't found at all", "YUITest", ".", "Assert", ".", "fail", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Value doesn't exist in array.\"", ")", ")", ";", "}" ]
Asserts that the given value is contained in an array at the specified index, starting from the back of the array. This uses the triple equals sign so no type cohersion will occur. @param {Object} needle The value to look for. @param {Array} haystack The array to search in. @param {int} index The index at which the value should exist. @param {String} message (Optional) The message to display if the assertion fails. @method lastIndexOf @static
[ "Asserts", "that", "the", "given", "value", "is", "contained", "in", "an", "array", "at", "the", "specified", "index", "starting", "from", "the", "back", "of", "the", "array", ".", "This", "uses", "the", "triple", "equals", "sign", "so", "no", "type", "cohersion", "will", "occur", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6108-L6122
51,223
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function(expected, actual, message) { YUITest.Assert._increment(); for (var name in expected){ if (expected.hasOwnProperty(name)){ if (expected[name] != actual[name]){ throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Values should be equal for property " + name), expected[name], actual[name]); } } } }
javascript
function(expected, actual, message) { YUITest.Assert._increment(); for (var name in expected){ if (expected.hasOwnProperty(name)){ if (expected[name] != actual[name]){ throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Values should be equal for property " + name), expected[name], actual[name]); } } } }
[ "function", "(", "expected", ",", "actual", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "for", "(", "var", "name", "in", "expected", ")", "{", "if", "(", "expected", ".", "hasOwnProperty", "(", "name", ")", ")", "{", "if", "(", "expected", "[", "name", "]", "!=", "actual", "[", "name", "]", ")", "{", "throw", "new", "YUITest", ".", "ComparisonFailure", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Values should be equal for property \"", "+", "name", ")", ",", "expected", "[", "name", "]", ",", "actual", "[", "name", "]", ")", ";", "}", "}", "}", "}" ]
Asserts that an object has all of the same properties and property values as the other. @param {Object} expected The object with all expected properties and values. @param {Object} actual The object to inspect. @param {String} message (Optional) The message to display if the assertion fails. @method areEqual @static @deprecated
[ "Asserts", "that", "an", "object", "has", "all", "of", "the", "same", "properties", "and", "property", "values", "as", "the", "other", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6146-L6156
51,224
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (object, message) { YUITest.Assert._increment(); var count = 0, name; for (name in object){ if (object.hasOwnProperty(name)){ count++; } } if (count !== 0){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Object owns " + count + " properties but should own none.")); } }
javascript
function (object, message) { YUITest.Assert._increment(); var count = 0, name; for (name in object){ if (object.hasOwnProperty(name)){ count++; } } if (count !== 0){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Object owns " + count + " properties but should own none.")); } }
[ "function", "(", "object", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "var", "count", "=", "0", ",", "name", ";", "for", "(", "name", "in", "object", ")", "{", "if", "(", "object", ".", "hasOwnProperty", "(", "name", ")", ")", "{", "count", "++", ";", "}", "}", "if", "(", "count", "!==", "0", ")", "{", "YUITest", ".", "Assert", ".", "fail", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Object owns \"", "+", "count", "+", "\" properties but should own none.\"", ")", ")", ";", "}", "}" ]
Asserts that an object owns no properties. @param {Object} object The object to check. @param {String} message (Optional) The message to display if the assertion fails. @method ownsNoKeys @static
[ "Asserts", "that", "an", "object", "owns", "no", "properties", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6255-L6269
51,225
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (propertyName, object, message) { YUITest.Assert._increment(); if (!(propertyName in object)){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Property '" + propertyName + "' not found on object.")); } }
javascript
function (propertyName, object, message) { YUITest.Assert._increment(); if (!(propertyName in object)){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Property '" + propertyName + "' not found on object.")); } }
[ "function", "(", "propertyName", ",", "object", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "!", "(", "propertyName", "in", "object", ")", ")", "{", "YUITest", ".", "Assert", ".", "fail", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Property '\"", "+", "propertyName", "+", "\"' not found on object.\"", ")", ")", ";", "}", "}" ]
Asserts that an object has a property with the given name. @param {String} propertyName The name of the property to test. @param {Object} object The object to search. @param {String} message (Optional) The message to display if the assertion fails. @method ownsOrInheritsKey @static
[ "Asserts", "that", "an", "object", "has", "a", "property", "with", "the", "given", "name", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6279-L6284
51,226
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (properties, object, message) { YUITest.Assert._increment(); for (var i=0; i < properties.length; i++){ if (!(properties[i] in object)){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Property '" + properties[i] + "' not found on object.")); } } }
javascript
function (properties, object, message) { YUITest.Assert._increment(); for (var i=0; i < properties.length; i++){ if (!(properties[i] in object)){ YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Property '" + properties[i] + "' not found on object.")); } } }
[ "function", "(", "properties", ",", "object", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "properties", ".", "length", ";", "i", "++", ")", "{", "if", "(", "!", "(", "properties", "[", "i", "]", "in", "object", ")", ")", "{", "YUITest", ".", "Assert", ".", "fail", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "\"Property '\"", "+", "properties", "[", "i", "]", "+", "\"' not found on object.\"", ")", ")", ";", "}", "}", "}" ]
Asserts that an object has all properties of a reference object. @param {Array} properties An array of property names that should be on the object. @param {Object} object The object to search. @param {String} message (Optional) The message to display if the assertion fails. @method ownsOrInheritsKeys @static
[ "Asserts", "that", "an", "object", "has", "all", "properties", "of", "a", "reference", "object", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6294-L6301
51,227
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (expected, actual, message){ YUITest.Assert._increment(); if (expected instanceof Date && actual instanceof Date){ var msg = ""; //check years first if (expected.getFullYear() != actual.getFullYear()){ msg = "Years should be equal."; } //now check months if (expected.getMonth() != actual.getMonth()){ msg = "Months should be equal."; } //last, check the day of the month if (expected.getDate() != actual.getDate()){ msg = "Days of month should be equal."; } if (msg.length){ throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, msg), expected, actual); } } else { throw new TypeError("YUITest.DateAssert.datesAreEqual(): Expected and actual values must be Date objects."); } }
javascript
function (expected, actual, message){ YUITest.Assert._increment(); if (expected instanceof Date && actual instanceof Date){ var msg = ""; //check years first if (expected.getFullYear() != actual.getFullYear()){ msg = "Years should be equal."; } //now check months if (expected.getMonth() != actual.getMonth()){ msg = "Months should be equal."; } //last, check the day of the month if (expected.getDate() != actual.getDate()){ msg = "Days of month should be equal."; } if (msg.length){ throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, msg), expected, actual); } } else { throw new TypeError("YUITest.DateAssert.datesAreEqual(): Expected and actual values must be Date objects."); } }
[ "function", "(", "expected", ",", "actual", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "expected", "instanceof", "Date", "&&", "actual", "instanceof", "Date", ")", "{", "var", "msg", "=", "\"\"", ";", "//check years first", "if", "(", "expected", ".", "getFullYear", "(", ")", "!=", "actual", ".", "getFullYear", "(", ")", ")", "{", "msg", "=", "\"Years should be equal.\"", ";", "}", "//now check months", "if", "(", "expected", ".", "getMonth", "(", ")", "!=", "actual", ".", "getMonth", "(", ")", ")", "{", "msg", "=", "\"Months should be equal.\"", ";", "}", "//last, check the day of the month", "if", "(", "expected", ".", "getDate", "(", ")", "!=", "actual", ".", "getDate", "(", ")", ")", "{", "msg", "=", "\"Days of month should be equal.\"", ";", "}", "if", "(", "msg", ".", "length", ")", "{", "throw", "new", "YUITest", ".", "ComparisonFailure", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "msg", ")", ",", "expected", ",", "actual", ")", ";", "}", "}", "else", "{", "throw", "new", "TypeError", "(", "\"YUITest.DateAssert.datesAreEqual(): Expected and actual values must be Date objects.\"", ")", ";", "}", "}" ]
Asserts that a date's month, day, and year are equal to another date's. @param {Date} expected The expected date. @param {Date} actual The actual date to test. @param {String} message (Optional) The message to display if the assertion fails. @method datesAreEqual @static
[ "Asserts", "that", "a", "date", "s", "month", "day", "and", "year", "are", "equal", "to", "another", "date", "s", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6324-L6350
51,228
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (expected, actual, message){ YUITest.Assert._increment(); if (expected instanceof Date && actual instanceof Date){ var msg = ""; //check hours first if (expected.getHours() != actual.getHours()){ msg = "Hours should be equal."; } //now check minutes if (expected.getMinutes() != actual.getMinutes()){ msg = "Minutes should be equal."; } //last, check the seconds if (expected.getSeconds() != actual.getSeconds()){ msg = "Seconds should be equal."; } if (msg.length){ throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, msg), expected, actual); } } else { throw new TypeError("YUITest.DateAssert.timesAreEqual(): Expected and actual values must be Date objects."); } }
javascript
function (expected, actual, message){ YUITest.Assert._increment(); if (expected instanceof Date && actual instanceof Date){ var msg = ""; //check hours first if (expected.getHours() != actual.getHours()){ msg = "Hours should be equal."; } //now check minutes if (expected.getMinutes() != actual.getMinutes()){ msg = "Minutes should be equal."; } //last, check the seconds if (expected.getSeconds() != actual.getSeconds()){ msg = "Seconds should be equal."; } if (msg.length){ throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, msg), expected, actual); } } else { throw new TypeError("YUITest.DateAssert.timesAreEqual(): Expected and actual values must be Date objects."); } }
[ "function", "(", "expected", ",", "actual", ",", "message", ")", "{", "YUITest", ".", "Assert", ".", "_increment", "(", ")", ";", "if", "(", "expected", "instanceof", "Date", "&&", "actual", "instanceof", "Date", ")", "{", "var", "msg", "=", "\"\"", ";", "//check hours first", "if", "(", "expected", ".", "getHours", "(", ")", "!=", "actual", ".", "getHours", "(", ")", ")", "{", "msg", "=", "\"Hours should be equal.\"", ";", "}", "//now check minutes", "if", "(", "expected", ".", "getMinutes", "(", ")", "!=", "actual", ".", "getMinutes", "(", ")", ")", "{", "msg", "=", "\"Minutes should be equal.\"", ";", "}", "//last, check the seconds", "if", "(", "expected", ".", "getSeconds", "(", ")", "!=", "actual", ".", "getSeconds", "(", ")", ")", "{", "msg", "=", "\"Seconds should be equal.\"", ";", "}", "if", "(", "msg", ".", "length", ")", "{", "throw", "new", "YUITest", ".", "ComparisonFailure", "(", "YUITest", ".", "Assert", ".", "_formatMessage", "(", "message", ",", "msg", ")", ",", "expected", ",", "actual", ")", ";", "}", "}", "else", "{", "throw", "new", "TypeError", "(", "\"YUITest.DateAssert.timesAreEqual(): Expected and actual values must be Date objects.\"", ")", ";", "}", "}" ]
Asserts that a date's hour, minutes, and seconds are equal to another date's. @param {Date} expected The expected date. @param {Date} actual The actual date to test. @param {String} message (Optional) The message to display if the assertion fails. @method timesAreEqual @static
[ "Asserts", "that", "a", "date", "s", "hour", "minutes", "and", "seconds", "are", "equal", "to", "another", "date", "s", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6360-L6386
51,229
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (segment, delay){ var actualDelay = (typeof segment == "number" ? segment : delay); actualDelay = (typeof actualDelay == "number" ? actualDelay : 10000); if (typeof segment == "function"){ throw new YUITest.Wait(segment, actualDelay); } else { throw new YUITest.Wait(function(){ YUITest.Assert.fail("Timeout: wait() called but resume() never called."); }, actualDelay); } }
javascript
function (segment, delay){ var actualDelay = (typeof segment == "number" ? segment : delay); actualDelay = (typeof actualDelay == "number" ? actualDelay : 10000); if (typeof segment == "function"){ throw new YUITest.Wait(segment, actualDelay); } else { throw new YUITest.Wait(function(){ YUITest.Assert.fail("Timeout: wait() called but resume() never called."); }, actualDelay); } }
[ "function", "(", "segment", ",", "delay", ")", "{", "var", "actualDelay", "=", "(", "typeof", "segment", "==", "\"number\"", "?", "segment", ":", "delay", ")", ";", "actualDelay", "=", "(", "typeof", "actualDelay", "==", "\"number\"", "?", "actualDelay", ":", "10000", ")", ";", "if", "(", "typeof", "segment", "==", "\"function\"", ")", "{", "throw", "new", "YUITest", ".", "Wait", "(", "segment", ",", "actualDelay", ")", ";", "}", "else", "{", "throw", "new", "YUITest", ".", "Wait", "(", "function", "(", ")", "{", "YUITest", ".", "Assert", ".", "fail", "(", "\"Timeout: wait() called but resume() never called.\"", ")", ";", "}", ",", "actualDelay", ")", ";", "}", "}" ]
Causes the test case to wait a specified amount of time and then continue executing the given code. @param {Function} segment (Optional) The function to run after the delay. If omitted, the TestRunner will wait until resume() is called. @param {int} delay (Optional) The number of milliseconds to wait before running the function. If omitted, defaults to zero. @return {Void} @method wait
[ "Causes", "the", "test", "case", "to", "wait", "a", "specified", "amount", "of", "time", "and", "then", "continue", "executing", "the", "given", "code", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6754-L6766
51,230
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (testObject) { if (testObject instanceof YUITest.TestSuite || testObject instanceof YUITest.TestCase) { this.items.push(testObject); } return this; }
javascript
function (testObject) { if (testObject instanceof YUITest.TestSuite || testObject instanceof YUITest.TestCase) { this.items.push(testObject); } return this; }
[ "function", "(", "testObject", ")", "{", "if", "(", "testObject", "instanceof", "YUITest", ".", "TestSuite", "||", "testObject", "instanceof", "YUITest", ".", "TestCase", ")", "{", "this", ".", "items", ".", "push", "(", "testObject", ")", ";", "}", "return", "this", ";", "}" ]
Adds a test suite or test case to the test suite. @param {YUITest.TestSuite||YUITest.TestCase} testObject The test suite or test case to add. @return {Void} @method add
[ "Adds", "a", "test", "suite", "or", "test", "case", "to", "the", "test", "suite", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6890-L6895
51,231
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function(results) { function serializeToXML(results){ var xml = "<" + results.type + " name=\"" + xmlEscape(results.name) + "\""; if (typeof(results.duration)=="number"){ xml += " duration=\"" + results.duration + "\""; } if (results.type == "test"){ xml += " result=\"" + results.result + "\" message=\"" + xmlEscape(results.message) + "\">"; } else { xml += " passed=\"" + results.passed + "\" failed=\"" + results.failed + "\" ignored=\"" + results.ignored + "\" total=\"" + results.total + "\">"; for (var prop in results){ if (results.hasOwnProperty(prop)){ if (results[prop] && typeof results[prop] == "object" && !(results[prop] instanceof Array)){ xml += serializeToXML(results[prop]); } } } } xml += "</" + results.type + ">"; return xml; } return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + serializeToXML(results); }
javascript
function(results) { function serializeToXML(results){ var xml = "<" + results.type + " name=\"" + xmlEscape(results.name) + "\""; if (typeof(results.duration)=="number"){ xml += " duration=\"" + results.duration + "\""; } if (results.type == "test"){ xml += " result=\"" + results.result + "\" message=\"" + xmlEscape(results.message) + "\">"; } else { xml += " passed=\"" + results.passed + "\" failed=\"" + results.failed + "\" ignored=\"" + results.ignored + "\" total=\"" + results.total + "\">"; for (var prop in results){ if (results.hasOwnProperty(prop)){ if (results[prop] && typeof results[prop] == "object" && !(results[prop] instanceof Array)){ xml += serializeToXML(results[prop]); } } } } xml += "</" + results.type + ">"; return xml; } return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + serializeToXML(results); }
[ "function", "(", "results", ")", "{", "function", "serializeToXML", "(", "results", ")", "{", "var", "xml", "=", "\"<\"", "+", "results", ".", "type", "+", "\" name=\\\"\"", "+", "xmlEscape", "(", "results", ".", "name", ")", "+", "\"\\\"\"", ";", "if", "(", "typeof", "(", "results", ".", "duration", ")", "==", "\"number\"", ")", "{", "xml", "+=", "\" duration=\\\"\"", "+", "results", ".", "duration", "+", "\"\\\"\"", ";", "}", "if", "(", "results", ".", "type", "==", "\"test\"", ")", "{", "xml", "+=", "\" result=\\\"\"", "+", "results", ".", "result", "+", "\"\\\" message=\\\"\"", "+", "xmlEscape", "(", "results", ".", "message", ")", "+", "\"\\\">\"", ";", "}", "else", "{", "xml", "+=", "\" passed=\\\"\"", "+", "results", ".", "passed", "+", "\"\\\" failed=\\\"\"", "+", "results", ".", "failed", "+", "\"\\\" ignored=\\\"\"", "+", "results", ".", "ignored", "+", "\"\\\" total=\\\"\"", "+", "results", ".", "total", "+", "\"\\\">\"", ";", "for", "(", "var", "prop", "in", "results", ")", "{", "if", "(", "results", ".", "hasOwnProperty", "(", "prop", ")", ")", "{", "if", "(", "results", "[", "prop", "]", "&&", "typeof", "results", "[", "prop", "]", "==", "\"object\"", "&&", "!", "(", "results", "[", "prop", "]", "instanceof", "Array", ")", ")", "{", "xml", "+=", "serializeToXML", "(", "results", "[", "prop", "]", ")", ";", "}", "}", "}", "}", "xml", "+=", "\"</\"", "+", "results", ".", "type", "+", "\">\"", ";", "return", "xml", ";", "}", "return", "\"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\"", "+", "serializeToXML", "(", "results", ")", ";", "}" ]
Returns test results formatted as an XML string. @param {Object} result The results object created by TestRunner. @return {String} An XML-formatted string of results. @method XML @static
[ "Returns", "test", "results", "formatted", "as", "an", "XML", "string", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L6968-L6997
51,232
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function() { if (this._form){ this._form.parentNode.removeChild(this._form); this._form = null; } if (this._iframe){ this._iframe.parentNode.removeChild(this._iframe); this._iframe = null; } this._fields = null; }
javascript
function() { if (this._form){ this._form.parentNode.removeChild(this._form); this._form = null; } if (this._iframe){ this._iframe.parentNode.removeChild(this._iframe); this._iframe = null; } this._fields = null; }
[ "function", "(", ")", "{", "if", "(", "this", ".", "_form", ")", "{", "this", ".", "_form", ".", "parentNode", ".", "removeChild", "(", "this", ".", "_form", ")", ";", "this", ".", "_form", "=", "null", ";", "}", "if", "(", "this", ".", "_iframe", ")", "{", "this", ".", "_iframe", ".", "parentNode", ".", "removeChild", "(", "this", ".", "_iframe", ")", ";", "this", ".", "_iframe", "=", "null", ";", "}", "this", ".", "_fields", "=", "null", ";", "}" ]
Cleans up the memory associated with the TestReporter, removing DOM elements that were created. @return {Void} @method destroy
[ "Cleans", "up", "the", "memory", "associated", "with", "the", "TestReporter", "removing", "DOM", "elements", "that", "were", "created", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L7959-L7969
51,233
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function(results){ //if the form hasn't been created yet, create it if (!this._form){ this._form = document.createElement("form"); this._form.method = "post"; this._form.style.visibility = "hidden"; this._form.style.position = "absolute"; this._form.style.top = 0; document.body.appendChild(this._form); //IE won't let you assign a name using the DOM, must do it the hacky way try { this._iframe = document.createElement("<iframe name=\"yuiTestTarget\" />"); } catch (ex){ this._iframe = document.createElement("iframe"); this._iframe.name = "yuiTestTarget"; } this._iframe.src = "javascript:false"; this._iframe.style.visibility = "hidden"; this._iframe.style.position = "absolute"; this._iframe.style.top = 0; document.body.appendChild(this._iframe); this._form.target = "yuiTestTarget"; } //set the form's action this._form.action = this.url; //remove any existing fields while(this._form.hasChildNodes()){ this._form.removeChild(this._form.lastChild); } //create default fields this._fields.results = this.format(results); this._fields.useragent = navigator.userAgent; this._fields.timestamp = (new Date()).toLocaleString(); //add fields to the form for (var prop in this._fields){ var value = this._fields[prop]; if (this._fields.hasOwnProperty(prop) && (typeof value != "function")){ var input = document.createElement("input"); input.type = "hidden"; input.name = prop; input.value = value; this._form.appendChild(input); } } //remove default fields delete this._fields.results; delete this._fields.useragent; delete this._fields.timestamp; if (arguments[1] !== false){ this._form.submit(); } }
javascript
function(results){ //if the form hasn't been created yet, create it if (!this._form){ this._form = document.createElement("form"); this._form.method = "post"; this._form.style.visibility = "hidden"; this._form.style.position = "absolute"; this._form.style.top = 0; document.body.appendChild(this._form); //IE won't let you assign a name using the DOM, must do it the hacky way try { this._iframe = document.createElement("<iframe name=\"yuiTestTarget\" />"); } catch (ex){ this._iframe = document.createElement("iframe"); this._iframe.name = "yuiTestTarget"; } this._iframe.src = "javascript:false"; this._iframe.style.visibility = "hidden"; this._iframe.style.position = "absolute"; this._iframe.style.top = 0; document.body.appendChild(this._iframe); this._form.target = "yuiTestTarget"; } //set the form's action this._form.action = this.url; //remove any existing fields while(this._form.hasChildNodes()){ this._form.removeChild(this._form.lastChild); } //create default fields this._fields.results = this.format(results); this._fields.useragent = navigator.userAgent; this._fields.timestamp = (new Date()).toLocaleString(); //add fields to the form for (var prop in this._fields){ var value = this._fields[prop]; if (this._fields.hasOwnProperty(prop) && (typeof value != "function")){ var input = document.createElement("input"); input.type = "hidden"; input.name = prop; input.value = value; this._form.appendChild(input); } } //remove default fields delete this._fields.results; delete this._fields.useragent; delete this._fields.timestamp; if (arguments[1] !== false){ this._form.submit(); } }
[ "function", "(", "results", ")", "{", "//if the form hasn't been created yet, create it", "if", "(", "!", "this", ".", "_form", ")", "{", "this", ".", "_form", "=", "document", ".", "createElement", "(", "\"form\"", ")", ";", "this", ".", "_form", ".", "method", "=", "\"post\"", ";", "this", ".", "_form", ".", "style", ".", "visibility", "=", "\"hidden\"", ";", "this", ".", "_form", ".", "style", ".", "position", "=", "\"absolute\"", ";", "this", ".", "_form", ".", "style", ".", "top", "=", "0", ";", "document", ".", "body", ".", "appendChild", "(", "this", ".", "_form", ")", ";", "//IE won't let you assign a name using the DOM, must do it the hacky way", "try", "{", "this", ".", "_iframe", "=", "document", ".", "createElement", "(", "\"<iframe name=\\\"yuiTestTarget\\\" />\"", ")", ";", "}", "catch", "(", "ex", ")", "{", "this", ".", "_iframe", "=", "document", ".", "createElement", "(", "\"iframe\"", ")", ";", "this", ".", "_iframe", ".", "name", "=", "\"yuiTestTarget\"", ";", "}", "this", ".", "_iframe", ".", "src", "=", "\"javascript:false\"", ";", "this", ".", "_iframe", ".", "style", ".", "visibility", "=", "\"hidden\"", ";", "this", ".", "_iframe", ".", "style", ".", "position", "=", "\"absolute\"", ";", "this", ".", "_iframe", ".", "style", ".", "top", "=", "0", ";", "document", ".", "body", ".", "appendChild", "(", "this", ".", "_iframe", ")", ";", "this", ".", "_form", ".", "target", "=", "\"yuiTestTarget\"", ";", "}", "//set the form's action", "this", ".", "_form", ".", "action", "=", "this", ".", "url", ";", "//remove any existing fields", "while", "(", "this", ".", "_form", ".", "hasChildNodes", "(", ")", ")", "{", "this", ".", "_form", ".", "removeChild", "(", "this", ".", "_form", ".", "lastChild", ")", ";", "}", "//create default fields", "this", ".", "_fields", ".", "results", "=", "this", ".", "format", "(", "results", ")", ";", "this", ".", "_fields", ".", "useragent", "=", "navigator", ".", "userAgent", ";", "this", ".", "_fields", ".", "timestamp", "=", "(", "new", "Date", "(", ")", ")", ".", "toLocaleString", "(", ")", ";", "//add fields to the form", "for", "(", "var", "prop", "in", "this", ".", "_fields", ")", "{", "var", "value", "=", "this", ".", "_fields", "[", "prop", "]", ";", "if", "(", "this", ".", "_fields", ".", "hasOwnProperty", "(", "prop", ")", "&&", "(", "typeof", "value", "!=", "\"function\"", ")", ")", "{", "var", "input", "=", "document", ".", "createElement", "(", "\"input\"", ")", ";", "input", ".", "type", "=", "\"hidden\"", ";", "input", ".", "name", "=", "prop", ";", "input", ".", "value", "=", "value", ";", "this", ".", "_form", ".", "appendChild", "(", "input", ")", ";", "}", "}", "//remove default fields", "delete", "this", ".", "_fields", ".", "results", ";", "delete", "this", ".", "_fields", ".", "useragent", ";", "delete", "this", ".", "_fields", ".", "timestamp", ";", "if", "(", "arguments", "[", "1", "]", "!==", "false", ")", "{", "this", ".", "_form", ".", "submit", "(", ")", ";", "}", "}" ]
Sends the report to the server. @param {Object} results The results object created by TestRunner. @return {Void} @method report
[ "Sends", "the", "report", "to", "the", "server", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L7977-L8039
51,234
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (page, results){ var r = this._results; r.passed += results.passed; r.failed += results.failed; r.ignored += results.ignored; r.total += results.total; r.duration += results.duration; if (results.failed){ r.failedPages.push(page); } else { r.passedPages.push(page); } results.name = page; results.type = "page"; r[page] = results; }
javascript
function (page, results){ var r = this._results; r.passed += results.passed; r.failed += results.failed; r.ignored += results.ignored; r.total += results.total; r.duration += results.duration; if (results.failed){ r.failedPages.push(page); } else { r.passedPages.push(page); } results.name = page; results.type = "page"; r[page] = results; }
[ "function", "(", "page", ",", "results", ")", "{", "var", "r", "=", "this", ".", "_results", ";", "r", ".", "passed", "+=", "results", ".", "passed", ";", "r", ".", "failed", "+=", "results", ".", "failed", ";", "r", ".", "ignored", "+=", "results", ".", "ignored", ";", "r", ".", "total", "+=", "results", ".", "total", ";", "r", ".", "duration", "+=", "results", ".", "duration", ";", "if", "(", "results", ".", "failed", ")", "{", "r", ".", "failedPages", ".", "push", "(", "page", ")", ";", "}", "else", "{", "r", ".", "passedPages", ".", "push", "(", "page", ")", ";", "}", "results", ".", "name", "=", "page", ";", "results", ".", "type", "=", "\"page\"", ";", "r", "[", "page", "]", "=", "results", ";", "}" ]
Processes the results of a test page run, outputting log messages for failed tests. @return {Void} @method _processResults @private @static
[ "Processes", "the", "results", "of", "a", "test", "page", "run", "outputting", "log", "messages", "for", "failed", "tests", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L8183-L8203
51,235
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function () /*:Void*/ { //set the current page this._curPage = this._pages.shift(); this.fire(this.TEST_PAGE_BEGIN_EVENT, this._curPage); //load the frame - destroy history in case there are other iframes that //need testing this._frame.location.replace(this._curPage); }
javascript
function () /*:Void*/ { //set the current page this._curPage = this._pages.shift(); this.fire(this.TEST_PAGE_BEGIN_EVENT, this._curPage); //load the frame - destroy history in case there are other iframes that //need testing this._frame.location.replace(this._curPage); }
[ "function", "(", ")", "/*:Void*/", "{", "//set the current page", "this", ".", "_curPage", "=", "this", ".", "_pages", ".", "shift", "(", ")", ";", "this", ".", "fire", "(", "this", ".", "TEST_PAGE_BEGIN_EVENT", ",", "this", ".", "_curPage", ")", ";", "//load the frame - destroy history in case there are other iframes that", "//need testing", "this", ".", "_frame", ".", "location", ".", "replace", "(", "this", ".", "_curPage", ")", ";", "}" ]
Loads the next test page into the iframe. @return {Void} @method _run @static @private
[ "Loads", "the", "next", "test", "page", "into", "the", "iframe", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L8212-L8223
51,236
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function () /*:Void*/ { if (!this._initialized) { /** * Fires when loading a test page * @event testpagebegin * @param curPage {string} the page being loaded * @static */ /** * Fires when a test page is complete * @event testpagecomplete * @param obj {page: string, results: object} the name of the * page that was loaded, and the test suite results * @static */ /** * Fires when the test manager starts running all test pages * @event testmanagerbegin * @static */ /** * Fires when the test manager finishes running all test pages. External * test runners should subscribe to this event in order to get the * aggregated test results. * @event testmanagercomplete * @param obj { pages_passed: int, pages_failed: int, tests_passed: int * tests_failed: int, passed: string[], failed: string[], * page_results: {} } * @static */ //create iframe if not already available if (!this._frame){ var frame /*:HTMLElement*/ = document.createElement("iframe"); frame.style.visibility = "hidden"; frame.style.position = "absolute"; document.body.appendChild(frame); this._frame = frame.contentWindow || frame.contentDocument.parentWindow; } this._initialized = true; } // reset the results cache this._results = { passed: 0, failed: 0, ignored: 0, total: 0, type: "report", name: "YUI Test Results", duration: 0, failedPages:[], passedPages:[] /* // number of pages that pass pages_passed: 0, // number of pages that fail pages_failed: 0, // total number of tests passed tests_passed: 0, // total number of tests failed tests_failed: 0, // array of pages that passed passed: [], // array of pages that failed failed: [], // map of full results for each page page_results: {}*/ }; this.fire(this.TEST_MANAGER_BEGIN_EVENT, null); this._run(); }
javascript
function () /*:Void*/ { if (!this._initialized) { /** * Fires when loading a test page * @event testpagebegin * @param curPage {string} the page being loaded * @static */ /** * Fires when a test page is complete * @event testpagecomplete * @param obj {page: string, results: object} the name of the * page that was loaded, and the test suite results * @static */ /** * Fires when the test manager starts running all test pages * @event testmanagerbegin * @static */ /** * Fires when the test manager finishes running all test pages. External * test runners should subscribe to this event in order to get the * aggregated test results. * @event testmanagercomplete * @param obj { pages_passed: int, pages_failed: int, tests_passed: int * tests_failed: int, passed: string[], failed: string[], * page_results: {} } * @static */ //create iframe if not already available if (!this._frame){ var frame /*:HTMLElement*/ = document.createElement("iframe"); frame.style.visibility = "hidden"; frame.style.position = "absolute"; document.body.appendChild(frame); this._frame = frame.contentWindow || frame.contentDocument.parentWindow; } this._initialized = true; } // reset the results cache this._results = { passed: 0, failed: 0, ignored: 0, total: 0, type: "report", name: "YUI Test Results", duration: 0, failedPages:[], passedPages:[] /* // number of pages that pass pages_passed: 0, // number of pages that fail pages_failed: 0, // total number of tests passed tests_passed: 0, // total number of tests failed tests_failed: 0, // array of pages that passed passed: [], // array of pages that failed failed: [], // map of full results for each page page_results: {}*/ }; this.fire(this.TEST_MANAGER_BEGIN_EVENT, null); this._run(); }
[ "function", "(", ")", "/*:Void*/", "{", "if", "(", "!", "this", ".", "_initialized", ")", "{", "/**\n * Fires when loading a test page\n * @event testpagebegin\n * @param curPage {string} the page being loaded\n * @static\n */", "/**\n * Fires when a test page is complete\n * @event testpagecomplete\n * @param obj {page: string, results: object} the name of the\n * page that was loaded, and the test suite results\n * @static\n */", "/**\n * Fires when the test manager starts running all test pages\n * @event testmanagerbegin\n * @static\n */", "/**\n * Fires when the test manager finishes running all test pages. External\n * test runners should subscribe to this event in order to get the\n * aggregated test results.\n * @event testmanagercomplete\n * @param obj { pages_passed: int, pages_failed: int, tests_passed: int\n * tests_failed: int, passed: string[], failed: string[],\n * page_results: {} }\n * @static\n */", "//create iframe if not already available", "if", "(", "!", "this", ".", "_frame", ")", "{", "var", "frame", "/*:HTMLElement*/", "=", "document", ".", "createElement", "(", "\"iframe\"", ")", ";", "frame", ".", "style", ".", "visibility", "=", "\"hidden\"", ";", "frame", ".", "style", ".", "position", "=", "\"absolute\"", ";", "document", ".", "body", ".", "appendChild", "(", "frame", ")", ";", "this", ".", "_frame", "=", "frame", ".", "contentWindow", "||", "frame", ".", "contentDocument", ".", "parentWindow", ";", "}", "this", ".", "_initialized", "=", "true", ";", "}", "// reset the results cache", "this", ".", "_results", "=", "{", "passed", ":", "0", ",", "failed", ":", "0", ",", "ignored", ":", "0", ",", "total", ":", "0", ",", "type", ":", "\"report\"", ",", "name", ":", "\"YUI Test Results\"", ",", "duration", ":", "0", ",", "failedPages", ":", "[", "]", ",", "passedPages", ":", "[", "]", "/*\n // number of pages that pass\n pages_passed: 0,\n // number of pages that fail\n pages_failed: 0,\n // total number of tests passed\n tests_passed: 0,\n // total number of tests failed\n tests_failed: 0,\n // array of pages that passed\n passed: [],\n // array of pages that failed\n failed: [],\n // map of full results for each page\n page_results: {}*/", "}", ";", "this", ".", "fire", "(", "this", ".", "TEST_MANAGER_BEGIN_EVENT", ",", "null", ")", ";", "this", ".", "_run", "(", ")", ";", "}" ]
Begins the process of running the tests. @return {Void} @method start @static
[ "Begins", "the", "process", "of", "running", "the", "tests", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L8270-L8351
51,237
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (parentNode, testSuite) { //add the test suite var node = parentNode.appendChild(testSuite); //iterate over the items in the master suite for (var i=0; i < testSuite.items.length; i++){ if (testSuite.items[i] instanceof YUITest.TestSuite) { this._addTestSuiteToTestTree(node, testSuite.items[i]); } else if (testSuite.items[i] instanceof YUITest.TestCase) { this._addTestCaseToTestTree(node, testSuite.items[i]); } } }
javascript
function (parentNode, testSuite) { //add the test suite var node = parentNode.appendChild(testSuite); //iterate over the items in the master suite for (var i=0; i < testSuite.items.length; i++){ if (testSuite.items[i] instanceof YUITest.TestSuite) { this._addTestSuiteToTestTree(node, testSuite.items[i]); } else if (testSuite.items[i] instanceof YUITest.TestCase) { this._addTestCaseToTestTree(node, testSuite.items[i]); } } }
[ "function", "(", "parentNode", ",", "testSuite", ")", "{", "//add the test suite", "var", "node", "=", "parentNode", ".", "appendChild", "(", "testSuite", ")", ";", "//iterate over the items in the master suite", "for", "(", "var", "i", "=", "0", ";", "i", "<", "testSuite", ".", "items", ".", "length", ";", "i", "++", ")", "{", "if", "(", "testSuite", ".", "items", "[", "i", "]", "instanceof", "YUITest", ".", "TestSuite", ")", "{", "this", ".", "_addTestSuiteToTestTree", "(", "node", ",", "testSuite", ".", "items", "[", "i", "]", ")", ";", "}", "else", "if", "(", "testSuite", ".", "items", "[", "i", "]", "instanceof", "YUITest", ".", "TestCase", ")", "{", "this", ".", "_addTestCaseToTestTree", "(", "node", ",", "testSuite", ".", "items", "[", "i", "]", ")", ";", "}", "}", "}" ]
Adds a test suite to the test tree as a child of the specified node. @param {TestNode} parentNode The node to add the test suite to as a child. @param {YUITest.TestSuite} testSuite The test suite to add. @return {Void} @static @private @method _addTestSuiteToTestTree
[ "Adds", "a", "test", "suite", "to", "the", "test", "tree", "as", "a", "child", "of", "the", "specified", "node", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L8699-L8712
51,238
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function () { this._root = new TestNode(this.masterSuite); //this._cur = this._root; //iterate over the items in the master suite for (var i=0; i < this.masterSuite.items.length; i++){ if (this.masterSuite.items[i] instanceof YUITest.TestSuite) { this._addTestSuiteToTestTree(this._root, this.masterSuite.items[i]); } else if (this.masterSuite.items[i] instanceof YUITest.TestCase) { this._addTestCaseToTestTree(this._root, this.masterSuite.items[i]); } } }
javascript
function () { this._root = new TestNode(this.masterSuite); //this._cur = this._root; //iterate over the items in the master suite for (var i=0; i < this.masterSuite.items.length; i++){ if (this.masterSuite.items[i] instanceof YUITest.TestSuite) { this._addTestSuiteToTestTree(this._root, this.masterSuite.items[i]); } else if (this.masterSuite.items[i] instanceof YUITest.TestCase) { this._addTestCaseToTestTree(this._root, this.masterSuite.items[i]); } } }
[ "function", "(", ")", "{", "this", ".", "_root", "=", "new", "TestNode", "(", "this", ".", "masterSuite", ")", ";", "//this._cur = this._root;", "//iterate over the items in the master suite", "for", "(", "var", "i", "=", "0", ";", "i", "<", "this", ".", "masterSuite", ".", "items", ".", "length", ";", "i", "++", ")", "{", "if", "(", "this", ".", "masterSuite", ".", "items", "[", "i", "]", "instanceof", "YUITest", ".", "TestSuite", ")", "{", "this", ".", "_addTestSuiteToTestTree", "(", "this", ".", "_root", ",", "this", ".", "masterSuite", ".", "items", "[", "i", "]", ")", ";", "}", "else", "if", "(", "this", ".", "masterSuite", ".", "items", "[", "i", "]", "instanceof", "YUITest", ".", "TestCase", ")", "{", "this", ".", "_addTestCaseToTestTree", "(", "this", ".", "_root", ",", "this", ".", "masterSuite", ".", "items", "[", "i", "]", ")", ";", "}", "}", "}" ]
Builds the test tree based on items in the master suite. The tree is a hierarchical representation of the test suites, test cases, and test functions. The resulting tree is stored in _root and the pointer _cur is set to the root initially. @return {Void} @static @private @method _buildTestTree
[ "Builds", "the", "test", "tree", "based", "on", "items", "in", "the", "master", "suite", ".", "The", "tree", "is", "a", "hierarchical", "representation", "of", "the", "test", "suites", "test", "cases", "and", "test", "functions", ".", "The", "resulting", "tree", "is", "stored", "in", "_root", "and", "the", "pointer", "_cur", "is", "set", "to", "the", "root", "initially", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L8723-L8737
51,239
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function () { //flag to indicate if the TestRunner should wait before continuing var shouldWait = false; //get the next test node var node = this._next(); if (node !== null) { //set flag to say the testrunner is running this._running = true; //eliminate last results this._lastResult = null; var testObject = node.testObject; //figure out what to do if (typeof testObject == "object" && testObject !== null){ if (testObject instanceof YUITest.TestSuite){ this.fire({ type: this.TEST_SUITE_BEGIN_EVENT, testSuite: testObject }); node._start = new Date(); this._execNonTestMethod(node, "setUp" ,false); } else if (testObject instanceof YUITest.TestCase){ this.fire({ type: this.TEST_CASE_BEGIN_EVENT, testCase: testObject }); node._start = new Date(); //regular or async init /*try { if (testObject["async:init"]){ testObject["async:init"](this._context); return; } else { testObject.init(this._context); } } catch (ex){ node.results.errors++; this.fire({ type: this.ERROR_EVENT, error: ex, testCase: testObject, methodName: "init" }); }*/ if(this._execNonTestMethod(node, "init", true)){ return; } } //some environments don't support setTimeout if (typeof setTimeout != "undefined"){ setTimeout(function(){ YUITest.TestRunner._run(); }, 0); } else { this._run(); } } else { this._runTest(node); } } }
javascript
function () { //flag to indicate if the TestRunner should wait before continuing var shouldWait = false; //get the next test node var node = this._next(); if (node !== null) { //set flag to say the testrunner is running this._running = true; //eliminate last results this._lastResult = null; var testObject = node.testObject; //figure out what to do if (typeof testObject == "object" && testObject !== null){ if (testObject instanceof YUITest.TestSuite){ this.fire({ type: this.TEST_SUITE_BEGIN_EVENT, testSuite: testObject }); node._start = new Date(); this._execNonTestMethod(node, "setUp" ,false); } else if (testObject instanceof YUITest.TestCase){ this.fire({ type: this.TEST_CASE_BEGIN_EVENT, testCase: testObject }); node._start = new Date(); //regular or async init /*try { if (testObject["async:init"]){ testObject["async:init"](this._context); return; } else { testObject.init(this._context); } } catch (ex){ node.results.errors++; this.fire({ type: this.ERROR_EVENT, error: ex, testCase: testObject, methodName: "init" }); }*/ if(this._execNonTestMethod(node, "init", true)){ return; } } //some environments don't support setTimeout if (typeof setTimeout != "undefined"){ setTimeout(function(){ YUITest.TestRunner._run(); }, 0); } else { this._run(); } } else { this._runTest(node); } } }
[ "function", "(", ")", "{", "//flag to indicate if the TestRunner should wait before continuing", "var", "shouldWait", "=", "false", ";", "//get the next test node", "var", "node", "=", "this", ".", "_next", "(", ")", ";", "if", "(", "node", "!==", "null", ")", "{", "//set flag to say the testrunner is running", "this", ".", "_running", "=", "true", ";", "//eliminate last results", "this", ".", "_lastResult", "=", "null", ";", "var", "testObject", "=", "node", ".", "testObject", ";", "//figure out what to do", "if", "(", "typeof", "testObject", "==", "\"object\"", "&&", "testObject", "!==", "null", ")", "{", "if", "(", "testObject", "instanceof", "YUITest", ".", "TestSuite", ")", "{", "this", ".", "fire", "(", "{", "type", ":", "this", ".", "TEST_SUITE_BEGIN_EVENT", ",", "testSuite", ":", "testObject", "}", ")", ";", "node", ".", "_start", "=", "new", "Date", "(", ")", ";", "this", ".", "_execNonTestMethod", "(", "node", ",", "\"setUp\"", ",", "false", ")", ";", "}", "else", "if", "(", "testObject", "instanceof", "YUITest", ".", "TestCase", ")", "{", "this", ".", "fire", "(", "{", "type", ":", "this", ".", "TEST_CASE_BEGIN_EVENT", ",", "testCase", ":", "testObject", "}", ")", ";", "node", ".", "_start", "=", "new", "Date", "(", ")", ";", "//regular or async init", "/*try {\n if (testObject[\"async:init\"]){\n testObject[\"async:init\"](this._context);\n return;\n } else {\n testObject.init(this._context);\n }\n } catch (ex){\n node.results.errors++;\n this.fire({ type: this.ERROR_EVENT, error: ex, testCase: testObject, methodName: \"init\" });\n }*/", "if", "(", "this", ".", "_execNonTestMethod", "(", "node", ",", "\"init\"", ",", "true", ")", ")", "{", "return", ";", "}", "}", "//some environments don't support setTimeout", "if", "(", "typeof", "setTimeout", "!=", "\"undefined\"", ")", "{", "setTimeout", "(", "function", "(", ")", "{", "YUITest", ".", "TestRunner", ".", "_run", "(", ")", ";", "}", ",", "0", ")", ";", "}", "else", "{", "this", ".", "_run", "(", ")", ";", "}", "}", "else", "{", "this", ".", "_runTest", "(", "node", ")", ";", "}", "}", "}" ]
Runs a test case or test suite, returning the results. @param {YUITest.TestCase|YUITest.TestSuite} testObject The test case or test suite to run. @return {Object} Results of the execution with properties passed, failed, and total. @private @method _run @static
[ "Runs", "a", "test", "case", "or", "test", "suite", "returning", "the", "results", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L8862-L8920
51,240
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (node) { //get relevant information var testName = node.testObject, testCase = node.parent.testObject, test = testCase[testName], //get the "should" test cases shouldIgnore = testName.indexOf("ignore:") === 0 || !inGroups(testCase.groups, this._groups) || (testCase._should.ignore || {})[testName]; //deprecated //figure out if the test should be ignored or not if (shouldIgnore){ //update results node.parent.results[testName] = { result: "ignore", message: "Test ignored", type: "test", name: testName.indexOf("ignore:") === 0 ? testName.substring(7) : testName }; node.parent.results.ignored++; node.parent.results.total++; this.fire({ type: this.TEST_IGNORE_EVENT, testCase: testCase, testName: testName }); //some environments don't support setTimeout if (typeof setTimeout != "undefined"){ setTimeout(function(){ YUITest.TestRunner._run(); }, 0); } else { this._run(); } } else { //mark the start time node._start = new Date(); //run the setup this._execNonTestMethod(node.parent, "setUp", false); //now call the body of the test this._resumeTest(test); } }
javascript
function (node) { //get relevant information var testName = node.testObject, testCase = node.parent.testObject, test = testCase[testName], //get the "should" test cases shouldIgnore = testName.indexOf("ignore:") === 0 || !inGroups(testCase.groups, this._groups) || (testCase._should.ignore || {})[testName]; //deprecated //figure out if the test should be ignored or not if (shouldIgnore){ //update results node.parent.results[testName] = { result: "ignore", message: "Test ignored", type: "test", name: testName.indexOf("ignore:") === 0 ? testName.substring(7) : testName }; node.parent.results.ignored++; node.parent.results.total++; this.fire({ type: this.TEST_IGNORE_EVENT, testCase: testCase, testName: testName }); //some environments don't support setTimeout if (typeof setTimeout != "undefined"){ setTimeout(function(){ YUITest.TestRunner._run(); }, 0); } else { this._run(); } } else { //mark the start time node._start = new Date(); //run the setup this._execNonTestMethod(node.parent, "setUp", false); //now call the body of the test this._resumeTest(test); } }
[ "function", "(", "node", ")", "{", "//get relevant information", "var", "testName", "=", "node", ".", "testObject", ",", "testCase", "=", "node", ".", "parent", ".", "testObject", ",", "test", "=", "testCase", "[", "testName", "]", ",", "//get the \"should\" test cases", "shouldIgnore", "=", "testName", ".", "indexOf", "(", "\"ignore:\"", ")", "===", "0", "||", "!", "inGroups", "(", "testCase", ".", "groups", ",", "this", ".", "_groups", ")", "||", "(", "testCase", ".", "_should", ".", "ignore", "||", "{", "}", ")", "[", "testName", "]", ";", "//deprecated", "//figure out if the test should be ignored or not", "if", "(", "shouldIgnore", ")", "{", "//update results", "node", ".", "parent", ".", "results", "[", "testName", "]", "=", "{", "result", ":", "\"ignore\"", ",", "message", ":", "\"Test ignored\"", ",", "type", ":", "\"test\"", ",", "name", ":", "testName", ".", "indexOf", "(", "\"ignore:\"", ")", "===", "0", "?", "testName", ".", "substring", "(", "7", ")", ":", "testName", "}", ";", "node", ".", "parent", ".", "results", ".", "ignored", "++", ";", "node", ".", "parent", ".", "results", ".", "total", "++", ";", "this", ".", "fire", "(", "{", "type", ":", "this", ".", "TEST_IGNORE_EVENT", ",", "testCase", ":", "testCase", ",", "testName", ":", "testName", "}", ")", ";", "//some environments don't support setTimeout", "if", "(", "typeof", "setTimeout", "!=", "\"undefined\"", ")", "{", "setTimeout", "(", "function", "(", ")", "{", "YUITest", ".", "TestRunner", ".", "_run", "(", ")", ";", "}", ",", "0", ")", ";", "}", "else", "{", "this", ".", "_run", "(", ")", ";", "}", "}", "else", "{", "//mark the start time", "node", ".", "_start", "=", "new", "Date", "(", ")", ";", "//run the setup", "this", ".", "_execNonTestMethod", "(", "node", ".", "parent", ",", "\"setUp\"", ",", "false", ")", ";", "//now call the body of the test", "this", ".", "_resumeTest", "(", "test", ")", ";", "}", "}" ]
Runs a single test based on the data provided in the node. @param {TestNode} node The TestNode representing the test to run. @return {Void} @static @private @name _runTest
[ "Runs", "a", "single", "test", "based", "on", "the", "data", "provided", "in", "the", "node", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L9122-L9171
51,241
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function (options) { options = options || {}; //pointer to runner to avoid scope issues var runner = YUITest.TestRunner, oldMode = options.oldMode; //if there's only one suite on the masterSuite, move it up if (!oldMode && this.masterSuite.items.length == 1 && this.masterSuite.items[0] instanceof YUITest.TestSuite){ this.masterSuite = this.masterSuite.items[0]; } //determine if there are any groups to filter on runner._groups = (options.groups instanceof Array) ? "," + options.groups.join(",") + "," : ""; //initialize the runner runner._buildTestTree(); runner._context = {}; runner._root._start = new Date(); //fire the begin event runner.fire(runner.BEGIN_EVENT); //begin the testing runner._run(); }
javascript
function (options) { options = options || {}; //pointer to runner to avoid scope issues var runner = YUITest.TestRunner, oldMode = options.oldMode; //if there's only one suite on the masterSuite, move it up if (!oldMode && this.masterSuite.items.length == 1 && this.masterSuite.items[0] instanceof YUITest.TestSuite){ this.masterSuite = this.masterSuite.items[0]; } //determine if there are any groups to filter on runner._groups = (options.groups instanceof Array) ? "," + options.groups.join(",") + "," : ""; //initialize the runner runner._buildTestTree(); runner._context = {}; runner._root._start = new Date(); //fire the begin event runner.fire(runner.BEGIN_EVENT); //begin the testing runner._run(); }
[ "function", "(", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "//pointer to runner to avoid scope issues", "var", "runner", "=", "YUITest", ".", "TestRunner", ",", "oldMode", "=", "options", ".", "oldMode", ";", "//if there's only one suite on the masterSuite, move it up", "if", "(", "!", "oldMode", "&&", "this", ".", "masterSuite", ".", "items", ".", "length", "==", "1", "&&", "this", ".", "masterSuite", ".", "items", "[", "0", "]", "instanceof", "YUITest", ".", "TestSuite", ")", "{", "this", ".", "masterSuite", "=", "this", ".", "masterSuite", ".", "items", "[", "0", "]", ";", "}", "//determine if there are any groups to filter on", "runner", ".", "_groups", "=", "(", "options", ".", "groups", "instanceof", "Array", ")", "?", "\",\"", "+", "options", ".", "groups", ".", "join", "(", "\",\"", ")", "+", "\",\"", ":", "\"\"", ";", "//initialize the runner", "runner", ".", "_buildTestTree", "(", ")", ";", "runner", ".", "_context", "=", "{", "}", ";", "runner", ".", "_root", ".", "_start", "=", "new", "Date", "(", ")", ";", "//fire the begin event", "runner", ".", "fire", "(", "runner", ".", "BEGIN_EVENT", ")", ";", "//begin the testing", "runner", ".", "_run", "(", ")", ";", "}" ]
Runs the test suite. @param {Object|Boolean} options (Optional) Options for the runner: <code>oldMode</code> indicates the TestRunner should work in the YUI <= 2.8 way of internally managing test suites. <code>groups</code> is an array of test groups indicating which tests to run. @return {Void} @method run @static
[ "Runs", "the", "test", "suite", "." ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L9335-L9362
51,242
perfectapi/ami-generator
www/build/tools/csslint-rhino.js
function(filename, options) { var input = readFile(filename), result = CSSLint.verify(input, gatherRules(options)), formatId = options.format || "text", messages = result.messages || [], exitCode = 0; if (!input) { print("csslint: Could not read file data in " + filename + ". Is the file empty?"); exitCode = 1; } else { print(CSSLint.getFormatter(formatId).formatResults(result, filename, formatId)); if (messages.length > 0 && pluckByType(messages, 'error').length > 0) { exitCode = 1; } } return exitCode; }
javascript
function(filename, options) { var input = readFile(filename), result = CSSLint.verify(input, gatherRules(options)), formatId = options.format || "text", messages = result.messages || [], exitCode = 0; if (!input) { print("csslint: Could not read file data in " + filename + ". Is the file empty?"); exitCode = 1; } else { print(CSSLint.getFormatter(formatId).formatResults(result, filename, formatId)); if (messages.length > 0 && pluckByType(messages, 'error').length > 0) { exitCode = 1; } } return exitCode; }
[ "function", "(", "filename", ",", "options", ")", "{", "var", "input", "=", "readFile", "(", "filename", ")", ",", "result", "=", "CSSLint", ".", "verify", "(", "input", ",", "gatherRules", "(", "options", ")", ")", ",", "formatId", "=", "options", ".", "format", "||", "\"text\"", ",", "messages", "=", "result", ".", "messages", "||", "[", "]", ",", "exitCode", "=", "0", ";", "if", "(", "!", "input", ")", "{", "print", "(", "\"csslint: Could not read file data in \"", "+", "filename", "+", "\". Is the file empty?\"", ")", ";", "exitCode", "=", "1", ";", "}", "else", "{", "print", "(", "CSSLint", ".", "getFormatter", "(", "formatId", ")", ".", "formatResults", "(", "result", ",", "filename", ",", "formatId", ")", ")", ";", "if", "(", "messages", ".", "length", ">", "0", "&&", "pluckByType", "(", "messages", ",", "'error'", ")", ".", "length", ">", "0", ")", "{", "exitCode", "=", "1", ";", "}", "}", "return", "exitCode", ";", "}" ]
process a list of files, return 1 if one or more error occurred
[ "process", "a", "list", "of", "files", "return", "1", "if", "one", "or", "more", "error", "occurred" ]
7913f300cccc79c59a2feac42225bbb26c042766
https://github.com/perfectapi/ami-generator/blob/7913f300cccc79c59a2feac42225bbb26c042766/www/build/tools/csslint-rhino.js#L11008-L11027
51,243
yiwn/compact
lib/compact.js
compact
function compact(source) { if (!source) return null; if (isArray(source)) return compactArray(source); if (typeof source == 'object') return compactObject(source); return source; }
javascript
function compact(source) { if (!source) return null; if (isArray(source)) return compactArray(source); if (typeof source == 'object') return compactObject(source); return source; }
[ "function", "compact", "(", "source", ")", "{", "if", "(", "!", "source", ")", "return", "null", ";", "if", "(", "isArray", "(", "source", ")", ")", "return", "compactArray", "(", "source", ")", ";", "if", "(", "typeof", "source", "==", "'object'", ")", "return", "compactObject", "(", "source", ")", ";", "return", "source", ";", "}" ]
Strip `null` and `undefined` values. @param {Object|Array} source @return {Object|Array} @api public
[ "Strip", "null", "and", "undefined", "values", "." ]
a30105810a94bfb06d5d4d55020a540c85901809
https://github.com/yiwn/compact/blob/a30105810a94bfb06d5d4d55020a540c85901809/lib/compact.js#L23-L33
51,244
yiwn/compact
lib/compact.js
compactArray
function compactArray(source) { return source.reduce(function(result, value){ if (value != void 0) result.push(value); return result; }, []); }
javascript
function compactArray(source) { return source.reduce(function(result, value){ if (value != void 0) result.push(value); return result; }, []); }
[ "function", "compactArray", "(", "source", ")", "{", "return", "source", ".", "reduce", "(", "function", "(", "result", ",", "value", ")", "{", "if", "(", "value", "!=", "void", "0", ")", "result", ".", "push", "(", "value", ")", ";", "return", "result", ";", "}", ",", "[", "]", ")", ";", "}" ]
Remove `null` and `undefined` from array; @param {Array} source @return {Array} @api private
[ "Remove", "null", "and", "undefined", "from", "array", ";" ]
a30105810a94bfb06d5d4d55020a540c85901809
https://github.com/yiwn/compact/blob/a30105810a94bfb06d5d4d55020a540c85901809/lib/compact.js#L43-L49
51,245
yiwn/compact
lib/compact.js
compactObject
function compactObject(source) { var result = {}, key; for (key in source) { var value = source[key]; if (value != void 0) result[key] = value; } return result; }
javascript
function compactObject(source) { var result = {}, key; for (key in source) { var value = source[key]; if (value != void 0) result[key] = value; } return result; }
[ "function", "compactObject", "(", "source", ")", "{", "var", "result", "=", "{", "}", ",", "key", ";", "for", "(", "key", "in", "source", ")", "{", "var", "value", "=", "source", "[", "key", "]", ";", "if", "(", "value", "!=", "void", "0", ")", "result", "[", "key", "]", "=", "value", ";", "}", "return", "result", ";", "}" ]
Remove `null` and `undefined` from object; @param {Object} source @return {Object} @api private
[ "Remove", "null", "and", "undefined", "from", "object", ";" ]
a30105810a94bfb06d5d4d55020a540c85901809
https://github.com/yiwn/compact/blob/a30105810a94bfb06d5d4d55020a540c85901809/lib/compact.js#L60-L70
51,246
XadillaX/algorithmjs
lib/algorithm/qsort.js
qsort
function qsort(array, l, r, func) { if(l < r) { var i = l, j = r; var x = array[l]; while(i < j) { while(i < j && func(x, array[j])) j--; array[i] = array[j]; while(i < j && func(array[i], x)) i++; array[j] = array[i]; } array[i] = x; qsort(array, l, i - 1, func); qsort(array, i + 1, r, func); } }
javascript
function qsort(array, l, r, func) { if(l < r) { var i = l, j = r; var x = array[l]; while(i < j) { while(i < j && func(x, array[j])) j--; array[i] = array[j]; while(i < j && func(array[i], x)) i++; array[j] = array[i]; } array[i] = x; qsort(array, l, i - 1, func); qsort(array, i + 1, r, func); } }
[ "function", "qsort", "(", "array", ",", "l", ",", "r", ",", "func", ")", "{", "if", "(", "l", "<", "r", ")", "{", "var", "i", "=", "l", ",", "j", "=", "r", ";", "var", "x", "=", "array", "[", "l", "]", ";", "while", "(", "i", "<", "j", ")", "{", "while", "(", "i", "<", "j", "&&", "func", "(", "x", ",", "array", "[", "j", "]", ")", ")", "j", "--", ";", "array", "[", "i", "]", "=", "array", "[", "j", "]", ";", "while", "(", "i", "<", "j", "&&", "func", "(", "array", "[", "i", "]", ",", "x", ")", ")", "i", "++", ";", "array", "[", "j", "]", "=", "array", "[", "i", "]", ";", "}", "array", "[", "i", "]", "=", "x", ";", "qsort", "(", "array", ",", "l", ",", "i", "-", "1", ",", "func", ")", ";", "qsort", "(", "array", ",", "i", "+", "1", ",", "r", ",", "func", ")", ";", "}", "}" ]
qsort main function @param array @param l @param r @param func @return
[ "qsort", "main", "function" ]
b291834446fdead3c5303f7759b496110b57d42c
https://github.com/XadillaX/algorithmjs/blob/b291834446fdead3c5303f7759b496110b57d42c/lib/algorithm/qsort.js#L22-L38
51,247
noderaider/redux-addons
lib/context.js
validateLibOpts
function validateLibOpts(libOptsRaw) { _chai.assert.ok(libOptsRaw, 'libOpts definition is required'); var libName = libOptsRaw.libName; var validateContext = libOptsRaw.validateContext; var configureAppContext = libOptsRaw.configureAppContext; var configureInitialState = libOptsRaw.configureInitialState; (0, _chai.assert)(typeof libName === 'string', 'libName must be a string'); (0, _chai.assert)(libName.length > 0, 'libName must not be empty'); _chai.assert.ok(validateContext, 'validateContext must exist'); (0, _chai.assert)(typeof validateContext === 'function', 'validateContext must be a function'); _chai.assert.ok(configureAppContext, 'configureAppContext must exist'); (0, _chai.assert)(typeof configureAppContext === 'function', 'configureAppContext must be a function'); _chai.assert.ok(configureInitialState, 'configureInitialState must exist'); (0, _chai.assert)(typeof configureInitialState === 'function', 'configureInitialState must be a function'); }
javascript
function validateLibOpts(libOptsRaw) { _chai.assert.ok(libOptsRaw, 'libOpts definition is required'); var libName = libOptsRaw.libName; var validateContext = libOptsRaw.validateContext; var configureAppContext = libOptsRaw.configureAppContext; var configureInitialState = libOptsRaw.configureInitialState; (0, _chai.assert)(typeof libName === 'string', 'libName must be a string'); (0, _chai.assert)(libName.length > 0, 'libName must not be empty'); _chai.assert.ok(validateContext, 'validateContext must exist'); (0, _chai.assert)(typeof validateContext === 'function', 'validateContext must be a function'); _chai.assert.ok(configureAppContext, 'configureAppContext must exist'); (0, _chai.assert)(typeof configureAppContext === 'function', 'configureAppContext must be a function'); _chai.assert.ok(configureInitialState, 'configureInitialState must exist'); (0, _chai.assert)(typeof configureInitialState === 'function', 'configureInitialState must be a function'); }
[ "function", "validateLibOpts", "(", "libOptsRaw", ")", "{", "_chai", ".", "assert", ".", "ok", "(", "libOptsRaw", ",", "'libOpts definition is required'", ")", ";", "var", "libName", "=", "libOptsRaw", ".", "libName", ";", "var", "validateContext", "=", "libOptsRaw", ".", "validateContext", ";", "var", "configureAppContext", "=", "libOptsRaw", ".", "configureAppContext", ";", "var", "configureInitialState", "=", "libOptsRaw", ".", "configureInitialState", ";", "(", "0", ",", "_chai", ".", "assert", ")", "(", "typeof", "libName", "===", "'string'", ",", "'libName must be a string'", ")", ";", "(", "0", ",", "_chai", ".", "assert", ")", "(", "libName", ".", "length", ">", "0", ",", "'libName must not be empty'", ")", ";", "_chai", ".", "assert", ".", "ok", "(", "validateContext", ",", "'validateContext must exist'", ")", ";", "(", "0", ",", "_chai", ".", "assert", ")", "(", "typeof", "validateContext", "===", "'function'", ",", "'validateContext must be a function'", ")", ";", "_chai", ".", "assert", ".", "ok", "(", "configureAppContext", ",", "'configureAppContext must exist'", ")", ";", "(", "0", ",", "_chai", ".", "assert", ")", "(", "typeof", "configureAppContext", "===", "'function'", ",", "'configureAppContext must be a function'", ")", ";", "_chai", ".", "assert", ".", "ok", "(", "configureInitialState", ",", "'configureInitialState must exist'", ")", ";", "(", "0", ",", "_chai", ".", "assert", ")", "(", "typeof", "configureInitialState", "===", "'function'", ",", "'configureInitialState must be a function'", ")", ";", "}" ]
Validates library creators options
[ "Validates", "library", "creators", "options" ]
7b11262b5a89039e7d96e47b8391840e72510fe1
https://github.com/noderaider/redux-addons/blob/7b11262b5a89039e7d96e47b8391840e72510fe1/lib/context.js#L62-L80
51,248
noderaider/redux-addons
lib/context.js
validateAppOpts
function validateAppOpts(appOptsRaw) { _chai.assert.ok(appOptsRaw, 'appOpts are required'); var appName = appOptsRaw.appName; (0, _chai.assert)(typeof appName === 'string', 'appName opt must be a string'); (0, _chai.assert)(appName.length > 0, 'appName opt must not be empty'); }
javascript
function validateAppOpts(appOptsRaw) { _chai.assert.ok(appOptsRaw, 'appOpts are required'); var appName = appOptsRaw.appName; (0, _chai.assert)(typeof appName === 'string', 'appName opt must be a string'); (0, _chai.assert)(appName.length > 0, 'appName opt must not be empty'); }
[ "function", "validateAppOpts", "(", "appOptsRaw", ")", "{", "_chai", ".", "assert", ".", "ok", "(", "appOptsRaw", ",", "'appOpts are required'", ")", ";", "var", "appName", "=", "appOptsRaw", ".", "appName", ";", "(", "0", ",", "_chai", ".", "assert", ")", "(", "typeof", "appName", "===", "'string'", ",", "'appName opt must be a string'", ")", ";", "(", "0", ",", "_chai", ".", "assert", ")", "(", "appName", ".", "length", ">", "0", ",", "'appName opt must not be empty'", ")", ";", "}" ]
Validates library consumers options
[ "Validates", "library", "consumers", "options" ]
7b11262b5a89039e7d96e47b8391840e72510fe1
https://github.com/noderaider/redux-addons/blob/7b11262b5a89039e7d96e47b8391840e72510fe1/lib/context.js#L83-L90
51,249
konfirm/node-submerge
lib/submerge.js
monitorArray
function monitorArray(a, emit) { ['copyWithin', 'fill', 'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'] .forEach(function(key) { var original = a[key]; a[key] = function() { var result = original.apply(a, arguments); emit(); return result; }; }); return a; }
javascript
function monitorArray(a, emit) { ['copyWithin', 'fill', 'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'] .forEach(function(key) { var original = a[key]; a[key] = function() { var result = original.apply(a, arguments); emit(); return result; }; }); return a; }
[ "function", "monitorArray", "(", "a", ",", "emit", ")", "{", "[", "'copyWithin'", ",", "'fill'", ",", "'pop'", ",", "'push'", ",", "'reverse'", ",", "'shift'", ",", "'sort'", ",", "'splice'", ",", "'unshift'", "]", ".", "forEach", "(", "function", "(", "key", ")", "{", "var", "original", "=", "a", "[", "key", "]", ";", "a", "[", "key", "]", "=", "function", "(", ")", "{", "var", "result", "=", "original", ".", "apply", "(", "a", ",", "arguments", ")", ";", "emit", "(", ")", ";", "return", "result", ";", "}", ";", "}", ")", ";", "return", "a", ";", "}" ]
Wrap all modifying array methods, so change-emisions can be triggered @name monitorArray @access internal @param Array a @param function emitter @return Array a
[ "Wrap", "all", "modifying", "array", "methods", "so", "change", "-", "emisions", "can", "be", "triggered" ]
5c471a1c8f794eb3827ca216e739263b512ff16c
https://github.com/konfirm/node-submerge/blob/5c471a1c8f794eb3827ca216e739263b512ff16c/lib/submerge.js#L45-L60
51,250
konfirm/node-submerge
lib/submerge.js
inherit
function inherit(options, destination, source, key) { var define, override, path; if (key in destination) { if (isObject(destination[key]) && isObject(source[key])) { // live up to the name and merge the sub objects Object.keys(source[key]).forEach(function(k) { inherit(options, destination[key], source[key], k); }); } return; } options.path.push(key); define = {enumerable: true}; if (isObject(source[key])) { override = combine(options, [source[key]]); } else if (source[key] instanceof Array) { override = monitorArray(source[key], function() { options.emitter.emit('change', path, source[key], source[key]); }); } if (isTrue(options, 'live')) { path = options.path.join('.'); define.get = function() { return override || source[key]; }; define.set = function(value) { if (isTrue(options, 'locked') || value === destination[key]) { return; } if (isObject(value)) { options.path = path.split('.'); value = combine(options, [value, source[key]]); } override = null; options.emitter.emit('change', path, value, source[key]); source[key] = value; }; } else { define.value = override || source[key]; define.writable = !isTrue(options, 'locked'); } Object.defineProperty(destination, key, define); options.path.pop(); }
javascript
function inherit(options, destination, source, key) { var define, override, path; if (key in destination) { if (isObject(destination[key]) && isObject(source[key])) { // live up to the name and merge the sub objects Object.keys(source[key]).forEach(function(k) { inherit(options, destination[key], source[key], k); }); } return; } options.path.push(key); define = {enumerable: true}; if (isObject(source[key])) { override = combine(options, [source[key]]); } else if (source[key] instanceof Array) { override = monitorArray(source[key], function() { options.emitter.emit('change', path, source[key], source[key]); }); } if (isTrue(options, 'live')) { path = options.path.join('.'); define.get = function() { return override || source[key]; }; define.set = function(value) { if (isTrue(options, 'locked') || value === destination[key]) { return; } if (isObject(value)) { options.path = path.split('.'); value = combine(options, [value, source[key]]); } override = null; options.emitter.emit('change', path, value, source[key]); source[key] = value; }; } else { define.value = override || source[key]; define.writable = !isTrue(options, 'locked'); } Object.defineProperty(destination, key, define); options.path.pop(); }
[ "function", "inherit", "(", "options", ",", "destination", ",", "source", ",", "key", ")", "{", "var", "define", ",", "override", ",", "path", ";", "if", "(", "key", "in", "destination", ")", "{", "if", "(", "isObject", "(", "destination", "[", "key", "]", ")", "&&", "isObject", "(", "source", "[", "key", "]", ")", ")", "{", "// live up to the name and merge the sub objects", "Object", ".", "keys", "(", "source", "[", "key", "]", ")", ".", "forEach", "(", "function", "(", "k", ")", "{", "inherit", "(", "options", ",", "destination", "[", "key", "]", ",", "source", "[", "key", "]", ",", "k", ")", ";", "}", ")", ";", "}", "return", ";", "}", "options", ".", "path", ".", "push", "(", "key", ")", ";", "define", "=", "{", "enumerable", ":", "true", "}", ";", "if", "(", "isObject", "(", "source", "[", "key", "]", ")", ")", "{", "override", "=", "combine", "(", "options", ",", "[", "source", "[", "key", "]", "]", ")", ";", "}", "else", "if", "(", "source", "[", "key", "]", "instanceof", "Array", ")", "{", "override", "=", "monitorArray", "(", "source", "[", "key", "]", ",", "function", "(", ")", "{", "options", ".", "emitter", ".", "emit", "(", "'change'", ",", "path", ",", "source", "[", "key", "]", ",", "source", "[", "key", "]", ")", ";", "}", ")", ";", "}", "if", "(", "isTrue", "(", "options", ",", "'live'", ")", ")", "{", "path", "=", "options", ".", "path", ".", "join", "(", "'.'", ")", ";", "define", ".", "get", "=", "function", "(", ")", "{", "return", "override", "||", "source", "[", "key", "]", ";", "}", ";", "define", ".", "set", "=", "function", "(", "value", ")", "{", "if", "(", "isTrue", "(", "options", ",", "'locked'", ")", "||", "value", "===", "destination", "[", "key", "]", ")", "{", "return", ";", "}", "if", "(", "isObject", "(", "value", ")", ")", "{", "options", ".", "path", "=", "path", ".", "split", "(", "'.'", ")", ";", "value", "=", "combine", "(", "options", ",", "[", "value", ",", "source", "[", "key", "]", "]", ")", ";", "}", "override", "=", "null", ";", "options", ".", "emitter", ".", "emit", "(", "'change'", ",", "path", ",", "value", ",", "source", "[", "key", "]", ")", ";", "source", "[", "key", "]", "=", "value", ";", "}", ";", "}", "else", "{", "define", ".", "value", "=", "override", "||", "source", "[", "key", "]", ";", "define", ".", "writable", "=", "!", "isTrue", "(", "options", ",", "'locked'", ")", ";", "}", "Object", ".", "defineProperty", "(", "destination", ",", "key", ",", "define", ")", ";", "options", ".", "path", ".", "pop", "(", ")", ";", "}" ]
Inherit the value at key of one object from a single other object @name inherit @access internal @param object options {live:bool, locked:bool} @param object destination @param object source @param string key @return void
[ "Inherit", "the", "value", "at", "key", "of", "one", "object", "from", "a", "single", "other", "object" ]
5c471a1c8f794eb3827ca216e739263b512ff16c
https://github.com/konfirm/node-submerge/blob/5c471a1c8f794eb3827ca216e739263b512ff16c/lib/submerge.js#L72-L128
51,251
jokeyrhyme/promised-requirejs.js
index.js
promisedRequire
function promisedRequire (name, retries=0) { if (Array.isArray(name)) { return Promise.all(name.map((n) => { return promisedRequire(n); })); } return new Promise(function (resolve, reject) { global.requirejs([name], (result) => { resolve(result); }, (err) => { var failedId = err.requireModules && err.requireModules[0]; if (failedId === name) { global.requirejs.undef(name); let query = `script[data-requirecontext][data-requiremodule="${name}"]`; let script = document.querySelector(query); if (script) { script.parentNode.removeChild(script); } if (retries < 1) { reject(err); } else { retries -= 1; promisedRequire(name, retries).then(resolve, reject); } } }); }); }
javascript
function promisedRequire (name, retries=0) { if (Array.isArray(name)) { return Promise.all(name.map((n) => { return promisedRequire(n); })); } return new Promise(function (resolve, reject) { global.requirejs([name], (result) => { resolve(result); }, (err) => { var failedId = err.requireModules && err.requireModules[0]; if (failedId === name) { global.requirejs.undef(name); let query = `script[data-requirecontext][data-requiremodule="${name}"]`; let script = document.querySelector(query); if (script) { script.parentNode.removeChild(script); } if (retries < 1) { reject(err); } else { retries -= 1; promisedRequire(name, retries).then(resolve, reject); } } }); }); }
[ "function", "promisedRequire", "(", "name", ",", "retries", "=", "0", ")", "{", "if", "(", "Array", ".", "isArray", "(", "name", ")", ")", "{", "return", "Promise", ".", "all", "(", "name", ".", "map", "(", "(", "n", ")", "=>", "{", "return", "promisedRequire", "(", "n", ")", ";", "}", ")", ")", ";", "}", "return", "new", "Promise", "(", "function", "(", "resolve", ",", "reject", ")", "{", "global", ".", "requirejs", "(", "[", "name", "]", ",", "(", "result", ")", "=>", "{", "resolve", "(", "result", ")", ";", "}", ",", "(", "err", ")", "=>", "{", "var", "failedId", "=", "err", ".", "requireModules", "&&", "err", ".", "requireModules", "[", "0", "]", ";", "if", "(", "failedId", "===", "name", ")", "{", "global", ".", "requirejs", ".", "undef", "(", "name", ")", ";", "let", "query", "=", "`", "${", "name", "}", "`", ";", "let", "script", "=", "document", ".", "querySelector", "(", "query", ")", ";", "if", "(", "script", ")", "{", "script", ".", "parentNode", ".", "removeChild", "(", "script", ")", ";", "}", "if", "(", "retries", "<", "1", ")", "{", "reject", "(", "err", ")", ";", "}", "else", "{", "retries", "-=", "1", ";", "promisedRequire", "(", "name", ",", "retries", ")", ".", "then", "(", "resolve", ",", "reject", ")", ";", "}", "}", "}", ")", ";", "}", ")", ";", "}" ]
this module - @param {(String|String[])} name - module(s) that you wish to load - @param {Number} [retries=0] - number of extra attempts in case of error
[ "this", "module", "-" ]
2a250ad5306ce555fa76299803b367b1247427a8
https://github.com/jokeyrhyme/promised-requirejs.js/blob/2a250ad5306ce555fa76299803b367b1247427a8/index.js#L9-L37
51,252
Tennu/tennu-factoids
factoids.js
function (key) { const value = db.get(key); if (!value) { db.set(key, { frozen: true }); return; } db.set(key, { intent: value.intent, message: value.message, editor: value.editor, time: value.time, frozen: true }); return true; }
javascript
function (key) { const value = db.get(key); if (!value) { db.set(key, { frozen: true }); return; } db.set(key, { intent: value.intent, message: value.message, editor: value.editor, time: value.time, frozen: true }); return true; }
[ "function", "(", "key", ")", "{", "const", "value", "=", "db", ".", "get", "(", "key", ")", ";", "if", "(", "!", "value", ")", "{", "db", ".", "set", "(", "key", ",", "{", "frozen", ":", "true", "}", ")", ";", "return", ";", "}", "db", ".", "set", "(", "key", ",", "{", "intent", ":", "value", ".", "intent", ",", "message", ":", "value", ".", "message", ",", "editor", ":", "value", ".", "editor", ",", "time", ":", "value", ".", "time", ",", "frozen", ":", "true", "}", ")", ";", "return", "true", ";", "}" ]
String -> Boolean
[ "String", "-", ">", "Boolean" ]
1b806563c35e3f75109a6dcb561168972cf990fe
https://github.com/Tennu/tennu-factoids/blob/1b806563c35e3f75109a6dcb561168972cf990fe/factoids.js#L280-L299
51,253
Nazariglez/perenquen
lib/pixi/src/core/utils/pluginTarget.js
pluginTarget
function pluginTarget(obj) { obj.__plugins = {}; /** * Adds a plugin to an object * * @param pluginName {string} The events that should be listed. * @param ctor {Object} ?? @alvin */ obj.registerPlugin = function (pluginName, ctor) { obj.__plugins[pluginName] = ctor; }; /** * Instantiates all the plugins of this object * */ obj.prototype.initPlugins = function () { this.plugins = this.plugins || {}; for (var o in obj.__plugins) { this.plugins[o] = new (obj.__plugins[o])(this); } }; /** * Removes all the plugins of this object * */ obj.prototype.destroyPlugins = function () { for (var o in this.plugins) { this.plugins[o].destroy(); this.plugins[o] = null; } this.plugins = null; }; }
javascript
function pluginTarget(obj) { obj.__plugins = {}; /** * Adds a plugin to an object * * @param pluginName {string} The events that should be listed. * @param ctor {Object} ?? @alvin */ obj.registerPlugin = function (pluginName, ctor) { obj.__plugins[pluginName] = ctor; }; /** * Instantiates all the plugins of this object * */ obj.prototype.initPlugins = function () { this.plugins = this.plugins || {}; for (var o in obj.__plugins) { this.plugins[o] = new (obj.__plugins[o])(this); } }; /** * Removes all the plugins of this object * */ obj.prototype.destroyPlugins = function () { for (var o in this.plugins) { this.plugins[o].destroy(); this.plugins[o] = null; } this.plugins = null; }; }
[ "function", "pluginTarget", "(", "obj", ")", "{", "obj", ".", "__plugins", "=", "{", "}", ";", "/**\n * Adds a plugin to an object\n *\n * @param pluginName {string} The events that should be listed.\n * @param ctor {Object} ?? @alvin\n */", "obj", ".", "registerPlugin", "=", "function", "(", "pluginName", ",", "ctor", ")", "{", "obj", ".", "__plugins", "[", "pluginName", "]", "=", "ctor", ";", "}", ";", "/**\n * Instantiates all the plugins of this object\n *\n */", "obj", ".", "prototype", ".", "initPlugins", "=", "function", "(", ")", "{", "this", ".", "plugins", "=", "this", ".", "plugins", "||", "{", "}", ";", "for", "(", "var", "o", "in", "obj", ".", "__plugins", ")", "{", "this", ".", "plugins", "[", "o", "]", "=", "new", "(", "obj", ".", "__plugins", "[", "o", "]", ")", "(", "this", ")", ";", "}", "}", ";", "/**\n * Removes all the plugins of this object\n *\n */", "obj", ".", "prototype", ".", "destroyPlugins", "=", "function", "(", ")", "{", "for", "(", "var", "o", "in", "this", ".", "plugins", ")", "{", "this", ".", "plugins", "[", "o", "]", ".", "destroy", "(", ")", ";", "this", ".", "plugins", "[", "o", "]", "=", "null", ";", "}", "this", ".", "plugins", "=", "null", ";", "}", ";", "}" ]
Mixins functionality to make an object have "plugins". @mixin @memberof PIXI.utils @param obj {object} The object to mix into. @example function MyObject() {} pluginTarget.mixin(MyObject);
[ "Mixins", "functionality", "to", "make", "an", "object", "have", "plugins", "." ]
e023964d05afeefebdcac4e2044819fdfa3899ae
https://github.com/Nazariglez/perenquen/blob/e023964d05afeefebdcac4e2044819fdfa3899ae/lib/pixi/src/core/utils/pluginTarget.js#L12-L55
51,254
jamespdlynn/microjs
examples/game/lib/view.js
function(){ canvas = document.getElementById("canvas"); canvas.width = Zone.prototype.WIDTH; canvas.height = Zone.prototype.HEIGHT; frameCount = 0; if (GameView.isRunning()){ run(); } //Add a listener on our global gameData object, to know when our game starts/stops gameData.on("change:isRunning", function(model, value){ value ? run() : reset(); }); }
javascript
function(){ canvas = document.getElementById("canvas"); canvas.width = Zone.prototype.WIDTH; canvas.height = Zone.prototype.HEIGHT; frameCount = 0; if (GameView.isRunning()){ run(); } //Add a listener on our global gameData object, to know when our game starts/stops gameData.on("change:isRunning", function(model, value){ value ? run() : reset(); }); }
[ "function", "(", ")", "{", "canvas", "=", "document", ".", "getElementById", "(", "\"canvas\"", ")", ";", "canvas", ".", "width", "=", "Zone", ".", "prototype", ".", "WIDTH", ";", "canvas", ".", "height", "=", "Zone", ".", "prototype", ".", "HEIGHT", ";", "frameCount", "=", "0", ";", "if", "(", "GameView", ".", "isRunning", "(", ")", ")", "{", "run", "(", ")", ";", "}", "//Add a listener on our global gameData object, to know when our game starts/stops", "gameData", ".", "on", "(", "\"change:isRunning\"", ",", "function", "(", "model", ",", "value", ")", "{", "value", "?", "run", "(", ")", ":", "reset", "(", ")", ";", "}", ")", ";", "}" ]
Set up Game View
[ "Set", "up", "Game", "View" ]
780a4074de84bcd74e3ae50d0ed64144b4474166
https://github.com/jamespdlynn/microjs/blob/780a4074de84bcd74e3ae50d0ed64144b4474166/examples/game/lib/view.js#L19-L35
51,255
jamespdlynn/microjs
examples/game/lib/view.js
angleDiff
function angleDiff(angle1, angle2){ var deltaAngle = angle1-angle2; while (deltaAngle < -Math.PI) deltaAngle += (2*Math.PI); while (deltaAngle > Math.PI) deltaAngle -= (2*Math.PI); return Math.abs(deltaAngle); }
javascript
function angleDiff(angle1, angle2){ var deltaAngle = angle1-angle2; while (deltaAngle < -Math.PI) deltaAngle += (2*Math.PI); while (deltaAngle > Math.PI) deltaAngle -= (2*Math.PI); return Math.abs(deltaAngle); }
[ "function", "angleDiff", "(", "angle1", ",", "angle2", ")", "{", "var", "deltaAngle", "=", "angle1", "-", "angle2", ";", "while", "(", "deltaAngle", "<", "-", "Math", ".", "PI", ")", "deltaAngle", "+=", "(", "2", "*", "Math", ".", "PI", ")", ";", "while", "(", "deltaAngle", ">", "Math", ".", "PI", ")", "deltaAngle", "-=", "(", "2", "*", "Math", ".", "PI", ")", ";", "return", "Math", ".", "abs", "(", "deltaAngle", ")", ";", "}" ]
Calculates the delta between two angles
[ "Calculates", "the", "delta", "between", "two", "angles" ]
780a4074de84bcd74e3ae50d0ed64144b4474166
https://github.com/jamespdlynn/microjs/blob/780a4074de84bcd74e3ae50d0ed64144b4474166/examples/game/lib/view.js#L175-L180
51,256
alexpods/ClazzJS
src/components/meta/Property/Constratins.js
function(object, constraints, property) { var that = this; object.__addSetter(property, this.SETTER_NAME, this.SETTER_WEIGHT, function(value, fields) { return that.apply(value, constraints, property, fields, this); }); }
javascript
function(object, constraints, property) { var that = this; object.__addSetter(property, this.SETTER_NAME, this.SETTER_WEIGHT, function(value, fields) { return that.apply(value, constraints, property, fields, this); }); }
[ "function", "(", "object", ",", "constraints", ",", "property", ")", "{", "var", "that", "=", "this", ";", "object", ".", "__addSetter", "(", "property", ",", "this", ".", "SETTER_NAME", ",", "this", ".", "SETTER_WEIGHT", ",", "function", "(", "value", ",", "fields", ")", "{", "return", "that", ".", "apply", "(", "value", ",", "constraints", ",", "property", ",", "fields", ",", "this", ")", ";", "}", ")", ";", "}" ]
Add constraints setter to object @param {object} object Object to which constraints will be applied @param {object} constraints Hash of constraints @param {string} property Property name @this {metaProcessor}
[ "Add", "constraints", "setter", "to", "object" ]
2f94496019669813c8246d48fcceb12a3e68a870
https://github.com/alexpods/ClazzJS/blob/2f94496019669813c8246d48fcceb12a3e68a870/src/components/meta/Property/Constratins.js#L19-L25
51,257
alexpods/ClazzJS
src/components/meta/Property/Constratins.js
function(value, constraints, property, fields, object) { _.each(constraints, function(constraint, name) { if (!constraint.call(object, value, fields, property)) { throw new Error('Constraint "' + name + '" was failed!'); } }); return value; }
javascript
function(value, constraints, property, fields, object) { _.each(constraints, function(constraint, name) { if (!constraint.call(object, value, fields, property)) { throw new Error('Constraint "' + name + '" was failed!'); } }); return value; }
[ "function", "(", "value", ",", "constraints", ",", "property", ",", "fields", ",", "object", ")", "{", "_", ".", "each", "(", "constraints", ",", "function", "(", "constraint", ",", "name", ")", "{", "if", "(", "!", "constraint", ".", "call", "(", "object", ",", "value", ",", "fields", ",", "property", ")", ")", "{", "throw", "new", "Error", "(", "'Constraint \"'", "+", "name", "+", "'\" was failed!'", ")", ";", "}", "}", ")", ";", "return", "value", ";", "}" ]
Applies property constraints to object @param {*} value Property value @param {object} constraints Hash of property constraints @param {string} property Property name @param {array} fields Property fields @param {object} object Object @returns {*} value Processed property value @throws {Error} if some constraint was failed @this {metaProcessor}
[ "Applies", "property", "constraints", "to", "object" ]
2f94496019669813c8246d48fcceb12a3e68a870
https://github.com/alexpods/ClazzJS/blob/2f94496019669813c8246d48fcceb12a3e68a870/src/components/meta/Property/Constratins.js#L42-L51
51,258
vader-httpclient/vader
build/node/restClient/utils.js
normalizeUrl
function normalizeUrl(url) { if (!IS_ABSOLUTE.test(url)) { return (0, _normalizeUrl2['default'])(url).replace('http://', ''); } else { return (0, _normalizeUrl2['default'])(url); } }
javascript
function normalizeUrl(url) { if (!IS_ABSOLUTE.test(url)) { return (0, _normalizeUrl2['default'])(url).replace('http://', ''); } else { return (0, _normalizeUrl2['default'])(url); } }
[ "function", "normalizeUrl", "(", "url", ")", "{", "if", "(", "!", "IS_ABSOLUTE", ".", "test", "(", "url", ")", ")", "{", "return", "(", "0", ",", "_normalizeUrl2", "[", "'default'", "]", ")", "(", "url", ")", ".", "replace", "(", "'http://'", ",", "''", ")", ";", "}", "else", "{", "return", "(", "0", ",", "_normalizeUrl2", "[", "'default'", "]", ")", "(", "url", ")", ";", "}", "}" ]
Normalize an url. @param {String} url @return {String}
[ "Normalize", "an", "url", "." ]
4c0f5a51faae5ea143a4ce9157ef557b148be55a
https://github.com/vader-httpclient/vader/blob/4c0f5a51faae5ea143a4ce9157ef557b148be55a/build/node/restClient/utils.js#L37-L43
51,259
Psychopoulet/node-promfs
lib/extends/_isFile.js
_isFile
function _isFile (file, callback) { if ("undefined" === typeof file) { throw new ReferenceError("missing \"file\" argument"); } else if ("string" !== typeof file) { throw new TypeError("\"file\" argument is not a string"); } else if ("" === file.trim()) { throw new Error("\"file\" argument is empty"); } else if ("undefined" === typeof callback) { throw new ReferenceError("missing \"callback\" argument"); } else if ("function" !== typeof callback) { throw new TypeError("\"callback\" argument is not a function"); } else { lstat(file, (err, stats) => { return callback(null, Boolean(!err && stats.isFile())); }); } }
javascript
function _isFile (file, callback) { if ("undefined" === typeof file) { throw new ReferenceError("missing \"file\" argument"); } else if ("string" !== typeof file) { throw new TypeError("\"file\" argument is not a string"); } else if ("" === file.trim()) { throw new Error("\"file\" argument is empty"); } else if ("undefined" === typeof callback) { throw new ReferenceError("missing \"callback\" argument"); } else if ("function" !== typeof callback) { throw new TypeError("\"callback\" argument is not a function"); } else { lstat(file, (err, stats) => { return callback(null, Boolean(!err && stats.isFile())); }); } }
[ "function", "_isFile", "(", "file", ",", "callback", ")", "{", "if", "(", "\"undefined\"", "===", "typeof", "file", ")", "{", "throw", "new", "ReferenceError", "(", "\"missing \\\"file\\\" argument\"", ")", ";", "}", "else", "if", "(", "\"string\"", "!==", "typeof", "file", ")", "{", "throw", "new", "TypeError", "(", "\"\\\"file\\\" argument is not a string\"", ")", ";", "}", "else", "if", "(", "\"\"", "===", "file", ".", "trim", "(", ")", ")", "{", "throw", "new", "Error", "(", "\"\\\"file\\\" argument is empty\"", ")", ";", "}", "else", "if", "(", "\"undefined\"", "===", "typeof", "callback", ")", "{", "throw", "new", "ReferenceError", "(", "\"missing \\\"callback\\\" argument\"", ")", ";", "}", "else", "if", "(", "\"function\"", "!==", "typeof", "callback", ")", "{", "throw", "new", "TypeError", "(", "\"\\\"callback\\\" argument is not a function\"", ")", ";", "}", "else", "{", "lstat", "(", "file", ",", "(", "err", ",", "stats", ")", "=>", "{", "return", "callback", "(", "null", ",", "Boolean", "(", "!", "err", "&&", "stats", ".", "isFile", "(", ")", ")", ")", ";", "}", ")", ";", "}", "}" ]
methods Async isFile @param {string} file : file to check @param {function} callback : operation's result @returns {void}
[ "methods", "Async", "isFile" ]
016e272fc58c6ef6eae5ea551a0e8873f0ac20cc
https://github.com/Psychopoulet/node-promfs/blob/016e272fc58c6ef6eae5ea551a0e8873f0ac20cc/lib/extends/_isFile.js#L18-L43
51,260
jonschlinkert/normalize-keywords
words.js
common
function common(words) { return _.map(words, function(o) { return o.word.toLowerCase(); }).sort(); }
javascript
function common(words) { return _.map(words, function(o) { return o.word.toLowerCase(); }).sort(); }
[ "function", "common", "(", "words", ")", "{", "return", "_", ".", "map", "(", "words", ",", "function", "(", "o", ")", "{", "return", "o", ".", "word", ".", "toLowerCase", "(", ")", ";", "}", ")", ".", "sort", "(", ")", ";", "}" ]
Get an array of the 100 most common english words
[ "Get", "an", "array", "of", "the", "100", "most", "common", "english", "words" ]
f4d1a92fab85c49636929d3a23652b1795b9ac22
https://github.com/jonschlinkert/normalize-keywords/blob/f4d1a92fab85c49636929d3a23652b1795b9ac22/words.js#L10-L14
51,261
cli-kit/cli-mid-unparsed
index.js
filter
function filter(unparsed) { var cmds = this.commands() , alias = this.finder.getCommandByName; var i, l = unparsed.length; for(i = 0;i < l;i++) { //console.log('unparsed filter %s', unparsed[i]); if(alias(unparsed[i], cmds)) { unparsed.splice(i, 1); i--; l--; } } //console.log('return %j', unparsed); return unparsed; }
javascript
function filter(unparsed) { var cmds = this.commands() , alias = this.finder.getCommandByName; var i, l = unparsed.length; for(i = 0;i < l;i++) { //console.log('unparsed filter %s', unparsed[i]); if(alias(unparsed[i], cmds)) { unparsed.splice(i, 1); i--; l--; } } //console.log('return %j', unparsed); return unparsed; }
[ "function", "filter", "(", "unparsed", ")", "{", "var", "cmds", "=", "this", ".", "commands", "(", ")", ",", "alias", "=", "this", ".", "finder", ".", "getCommandByName", ";", "var", "i", ",", "l", "=", "unparsed", ".", "length", ";", "for", "(", "i", "=", "0", ";", "i", "<", "l", ";", "i", "++", ")", "{", "//console.log('unparsed filter %s', unparsed[i]);", "if", "(", "alias", "(", "unparsed", "[", "i", "]", ",", "cmds", ")", ")", "{", "unparsed", ".", "splice", "(", "i", ",", "1", ")", ";", "i", "--", ";", "l", "--", ";", "}", "}", "//console.log('return %j', unparsed);", "return", "unparsed", ";", "}" ]
Filters commands from the unparsed arguments array. Note that currently this only filters top-level commands.
[ "Filters", "commands", "from", "the", "unparsed", "arguments", "array", "." ]
7b5432ab5718ff388f690047448018b6459ee4cb
https://github.com/cli-kit/cli-mid-unparsed/blob/7b5432ab5718ff388f690047448018b6459ee4cb/index.js#L8-L22
51,262
leoxy520/Sling2JCR
index.js
startUp
function startUp(dir) { var config = { jcr_root: dir, servers: [{ host: commander.host || "http://localhost:4502", username: commander.username || "admin", password: commander.password || "admin" }] }; //create a new instance var sling2JCR = new sling2jcr_1.Sling2JCR(config.servers); sling2JCR.login().then(function (servers) { //watch the files under the jcr_root folder, or any sub directory under it. Files not under a sub directory of jcr_root won't be synchronized. watch(config.jcr_root, function (filePath) { if (fs.existsSync(filePath)) { if (fs.statSync(filePath).isFile()) { sling2JCR.process(filePath); } } else { sling2JCR.process(filePath, true); } }); }).catch(function (error) { console.log(error); }); }
javascript
function startUp(dir) { var config = { jcr_root: dir, servers: [{ host: commander.host || "http://localhost:4502", username: commander.username || "admin", password: commander.password || "admin" }] }; //create a new instance var sling2JCR = new sling2jcr_1.Sling2JCR(config.servers); sling2JCR.login().then(function (servers) { //watch the files under the jcr_root folder, or any sub directory under it. Files not under a sub directory of jcr_root won't be synchronized. watch(config.jcr_root, function (filePath) { if (fs.existsSync(filePath)) { if (fs.statSync(filePath).isFile()) { sling2JCR.process(filePath); } } else { sling2JCR.process(filePath, true); } }); }).catch(function (error) { console.log(error); }); }
[ "function", "startUp", "(", "dir", ")", "{", "var", "config", "=", "{", "jcr_root", ":", "dir", ",", "servers", ":", "[", "{", "host", ":", "commander", ".", "host", "||", "\"http://localhost:4502\"", ",", "username", ":", "commander", ".", "username", "||", "\"admin\"", ",", "password", ":", "commander", ".", "password", "||", "\"admin\"", "}", "]", "}", ";", "//create a new instance", "var", "sling2JCR", "=", "new", "sling2jcr_1", ".", "Sling2JCR", "(", "config", ".", "servers", ")", ";", "sling2JCR", ".", "login", "(", ")", ".", "then", "(", "function", "(", "servers", ")", "{", "//watch the files under the jcr_root folder, or any sub directory under it. Files not under a sub directory of jcr_root won't be synchronized.", "watch", "(", "config", ".", "jcr_root", ",", "function", "(", "filePath", ")", "{", "if", "(", "fs", ".", "existsSync", "(", "filePath", ")", ")", "{", "if", "(", "fs", ".", "statSync", "(", "filePath", ")", ".", "isFile", "(", ")", ")", "{", "sling2JCR", ".", "process", "(", "filePath", ")", ";", "}", "}", "else", "{", "sling2JCR", ".", "process", "(", "filePath", ",", "true", ")", ";", "}", "}", ")", ";", "}", ")", ".", "catch", "(", "function", "(", "error", ")", "{", "console", ".", "log", "(", "error", ")", ";", "}", ")", ";", "}" ]
end with parse to parse through the input
[ "end", "with", "parse", "to", "parse", "through", "the", "input" ]
f7bc671c0de6d2d6b4e039da1a67b7456186179b
https://github.com/leoxy520/Sling2JCR/blob/f7bc671c0de6d2d6b4e039da1a67b7456186179b/index.js#L17-L43
51,263
flowthings/node-client
flowthings/websocketFactory.js
crudable
function crudable(flowthingsWs) { return { create: function(obj, params, responseHandler, cb) { if (typeof params === 'function') { cb = responseHandler; responseHandler = params; params = {}; } else if (!params) { params = {}; } baseWs(flowthingsWs, this.objectType, 'create', {value: obj}, {msgId: params.msgId, responseHandler: responseHandler, cb: cb}); }, read: function(id, params, responseHandler, cb) { if (typeof params === 'function') { cb = responseHandler; responseHandler = params; params = {}; } else if (!params) { params = {}; } id = fixDropId(id, this); baseWs(flowthingsWs, this.objectType, 'find', {id: id}, {msgId: params.msgId, responseHandler: responseHandler, cb: cb}); }, update: function(id, obj, params, responseHandler, cb) { if (typeof params === 'function') { cb = responseHandler; responseHandler = params; params = {}; } else if (!params) { params = {}; } id = fixDropId(id, this); baseWs(flowthingsWs, this.objectType, 'update', {id: id, value: obj}, {msgId: params.msgId, responseHandler: responseHandler, cb: cb}); }, delete: function(id, params, responseHandler, cb) { if (typeof params === 'function') { cb = responseHandler; responseHandler = params; params = {}; } else if (!params) { params = {}; } id = fixDropId(id, this); baseWs(flowthingsWs, this.objectType, this.objectType, 'delete', {id: id}, {msgId: params.msgId, responseHandler: responseHandler, cb: cb}); } }; }
javascript
function crudable(flowthingsWs) { return { create: function(obj, params, responseHandler, cb) { if (typeof params === 'function') { cb = responseHandler; responseHandler = params; params = {}; } else if (!params) { params = {}; } baseWs(flowthingsWs, this.objectType, 'create', {value: obj}, {msgId: params.msgId, responseHandler: responseHandler, cb: cb}); }, read: function(id, params, responseHandler, cb) { if (typeof params === 'function') { cb = responseHandler; responseHandler = params; params = {}; } else if (!params) { params = {}; } id = fixDropId(id, this); baseWs(flowthingsWs, this.objectType, 'find', {id: id}, {msgId: params.msgId, responseHandler: responseHandler, cb: cb}); }, update: function(id, obj, params, responseHandler, cb) { if (typeof params === 'function') { cb = responseHandler; responseHandler = params; params = {}; } else if (!params) { params = {}; } id = fixDropId(id, this); baseWs(flowthingsWs, this.objectType, 'update', {id: id, value: obj}, {msgId: params.msgId, responseHandler: responseHandler, cb: cb}); }, delete: function(id, params, responseHandler, cb) { if (typeof params === 'function') { cb = responseHandler; responseHandler = params; params = {}; } else if (!params) { params = {}; } id = fixDropId(id, this); baseWs(flowthingsWs, this.objectType, this.objectType, 'delete', {id: id}, {msgId: params.msgId, responseHandler: responseHandler, cb: cb}); } }; }
[ "function", "crudable", "(", "flowthingsWs", ")", "{", "return", "{", "create", ":", "function", "(", "obj", ",", "params", ",", "responseHandler", ",", "cb", ")", "{", "if", "(", "typeof", "params", "===", "'function'", ")", "{", "cb", "=", "responseHandler", ";", "responseHandler", "=", "params", ";", "params", "=", "{", "}", ";", "}", "else", "if", "(", "!", "params", ")", "{", "params", "=", "{", "}", ";", "}", "baseWs", "(", "flowthingsWs", ",", "this", ".", "objectType", ",", "'create'", ",", "{", "value", ":", "obj", "}", ",", "{", "msgId", ":", "params", ".", "msgId", ",", "responseHandler", ":", "responseHandler", ",", "cb", ":", "cb", "}", ")", ";", "}", ",", "read", ":", "function", "(", "id", ",", "params", ",", "responseHandler", ",", "cb", ")", "{", "if", "(", "typeof", "params", "===", "'function'", ")", "{", "cb", "=", "responseHandler", ";", "responseHandler", "=", "params", ";", "params", "=", "{", "}", ";", "}", "else", "if", "(", "!", "params", ")", "{", "params", "=", "{", "}", ";", "}", "id", "=", "fixDropId", "(", "id", ",", "this", ")", ";", "baseWs", "(", "flowthingsWs", ",", "this", ".", "objectType", ",", "'find'", ",", "{", "id", ":", "id", "}", ",", "{", "msgId", ":", "params", ".", "msgId", ",", "responseHandler", ":", "responseHandler", ",", "cb", ":", "cb", "}", ")", ";", "}", ",", "update", ":", "function", "(", "id", ",", "obj", ",", "params", ",", "responseHandler", ",", "cb", ")", "{", "if", "(", "typeof", "params", "===", "'function'", ")", "{", "cb", "=", "responseHandler", ";", "responseHandler", "=", "params", ";", "params", "=", "{", "}", ";", "}", "else", "if", "(", "!", "params", ")", "{", "params", "=", "{", "}", ";", "}", "id", "=", "fixDropId", "(", "id", ",", "this", ")", ";", "baseWs", "(", "flowthingsWs", ",", "this", ".", "objectType", ",", "'update'", ",", "{", "id", ":", "id", ",", "value", ":", "obj", "}", ",", "{", "msgId", ":", "params", ".", "msgId", ",", "responseHandler", ":", "responseHandler", ",", "cb", ":", "cb", "}", ")", ";", "}", ",", "delete", ":", "function", "(", "id", ",", "params", ",", "responseHandler", ",", "cb", ")", "{", "if", "(", "typeof", "params", "===", "'function'", ")", "{", "cb", "=", "responseHandler", ";", "responseHandler", "=", "params", ";", "params", "=", "{", "}", ";", "}", "else", "if", "(", "!", "params", ")", "{", "params", "=", "{", "}", ";", "}", "id", "=", "fixDropId", "(", "id", ",", "this", ")", ";", "baseWs", "(", "flowthingsWs", ",", "this", ".", "objectType", ",", "this", ".", "objectType", ",", "'delete'", ",", "{", "id", ":", "id", "}", ",", "{", "msgId", ":", "params", ".", "msgId", ",", "responseHandler", ":", "responseHandler", ",", "cb", ":", "cb", "}", ")", ";", "}", "}", ";", "}" ]
These are in the private API. We don't really want people to access them directly.
[ "These", "are", "in", "the", "private", "API", ".", "We", "don", "t", "really", "want", "people", "to", "access", "them", "directly", "." ]
0a9e9660e28bface0da4e919fd1e2617deabbf77
https://github.com/flowthings/node-client/blob/0a9e9660e28bface0da4e919fd1e2617deabbf77/flowthings/websocketFactory.js#L247-L299
51,264
flowthings/node-client
flowthings/websocketFactory.js
dropCreate
function dropCreate(flowthingsWs) { return { create: function(drop, params, responseHandler, cb) { if (typeof params === 'function') { cb = responseHandler; responseHandler = params; params = {}; } else if (!params) { params = {}; } if (this.flowId.charAt(0) === '/') { drop.path = this.flowId; } baseWs(flowthingsWs, this.objectType, 'create', {flowId: this.flowId, value: drop}, {msgId: params.msgId, responseHandler: responseHandler, cb: cb}); }, }; }
javascript
function dropCreate(flowthingsWs) { return { create: function(drop, params, responseHandler, cb) { if (typeof params === 'function') { cb = responseHandler; responseHandler = params; params = {}; } else if (!params) { params = {}; } if (this.flowId.charAt(0) === '/') { drop.path = this.flowId; } baseWs(flowthingsWs, this.objectType, 'create', {flowId: this.flowId, value: drop}, {msgId: params.msgId, responseHandler: responseHandler, cb: cb}); }, }; }
[ "function", "dropCreate", "(", "flowthingsWs", ")", "{", "return", "{", "create", ":", "function", "(", "drop", ",", "params", ",", "responseHandler", ",", "cb", ")", "{", "if", "(", "typeof", "params", "===", "'function'", ")", "{", "cb", "=", "responseHandler", ";", "responseHandler", "=", "params", ";", "params", "=", "{", "}", ";", "}", "else", "if", "(", "!", "params", ")", "{", "params", "=", "{", "}", ";", "}", "if", "(", "this", ".", "flowId", ".", "charAt", "(", "0", ")", "===", "'/'", ")", "{", "drop", ".", "path", "=", "this", ".", "flowId", ";", "}", "baseWs", "(", "flowthingsWs", ",", "this", ".", "objectType", ",", "'create'", ",", "{", "flowId", ":", "this", ".", "flowId", ",", "value", ":", "drop", "}", ",", "{", "msgId", ":", "params", ".", "msgId", ",", "responseHandler", ":", "responseHandler", ",", "cb", ":", "cb", "}", ")", ";", "}", ",", "}", ";", "}" ]
can I roll this into the normal create?
[ "can", "I", "roll", "this", "into", "the", "normal", "create?" ]
0a9e9660e28bface0da4e919fd1e2617deabbf77
https://github.com/flowthings/node-client/blob/0a9e9660e28bface0da4e919fd1e2617deabbf77/flowthings/websocketFactory.js#L318-L336
51,265
biggora/trinte-creator
scripts/controllers/AppsController.js
function(req, res, next) { /** * If you want to redirect to another controller, uncomment */ var controllers = []; fs.readdir(__dirname + '/', function(err, files) { if (err) { throw err; } files.forEach(function(file) { if(/\.js$/i.test(file)) { if (file !== "AppsController.js") { controllers.push(file.replace('Controller.js', '').toLowerCase()); } } }); res.render('app', { controllers: controllers }); }); }
javascript
function(req, res, next) { /** * If you want to redirect to another controller, uncomment */ var controllers = []; fs.readdir(__dirname + '/', function(err, files) { if (err) { throw err; } files.forEach(function(file) { if(/\.js$/i.test(file)) { if (file !== "AppsController.js") { controllers.push(file.replace('Controller.js', '').toLowerCase()); } } }); res.render('app', { controllers: controllers }); }); }
[ "function", "(", "req", ",", "res", ",", "next", ")", "{", "/**\n * If you want to redirect to another controller, uncomment\n */", "var", "controllers", "=", "[", "]", ";", "fs", ".", "readdir", "(", "__dirname", "+", "'/'", ",", "function", "(", "err", ",", "files", ")", "{", "if", "(", "err", ")", "{", "throw", "err", ";", "}", "files", ".", "forEach", "(", "function", "(", "file", ")", "{", "if", "(", "/", "\\.js$", "/", "i", ".", "test", "(", "file", ")", ")", "{", "if", "(", "file", "!==", "\"AppsController.js\"", ")", "{", "controllers", ".", "push", "(", "file", ".", "replace", "(", "'Controller.js'", ",", "''", ")", ".", "toLowerCase", "(", ")", ")", ";", "}", "}", "}", ")", ";", "res", ".", "render", "(", "'app'", ",", "{", "controllers", ":", "controllers", "}", ")", ";", "}", ")", ";", "}" ]
Default Application index - shows a list of the controllers. Redirect here if you prefer another controller to be your index. @param req @param res @param next
[ "Default", "Application", "index", "-", "shows", "a", "list", "of", "the", "controllers", ".", "Redirect", "here", "if", "you", "prefer", "another", "controller", "to", "be", "your", "index", "." ]
fdd723405418967ca8a690867940863fd77e636b
https://github.com/biggora/trinte-creator/blob/fdd723405418967ca8a690867940863fd77e636b/scripts/controllers/AppsController.js#L20-L46
51,266
Psychopoulet/node-promfs
lib/extends/_mkdirp.js
_mkdirp
function _mkdirp (directory, mode, callback) { if ("undefined" === typeof directory) { throw new ReferenceError("missing \"directory\" argument"); } else if ("string" !== typeof directory) { throw new TypeError("\"directory\" argument is not a string"); } else if ("" === directory.trim()) { throw new Error("\"directory\" argument is empty"); } else if ("undefined" !== typeof callback && "number" !== typeof mode) { throw new TypeError("\"mode\" argument is not a number"); } else if ("undefined" === typeof callback && "undefined" === typeof mode) { throw new ReferenceError("missing \"callback\" argument"); } else if ("function" !== typeof callback && "function" !== typeof mode) { throw new TypeError("\"callback\" argument is not a function"); } else { let _callback = callback; let _mode = mode; if ("undefined" === typeof _callback) { _callback = mode; _mode = DEFAULT_OPTION; } isDirectoryProm(directory).then((exists) => { return exists ? Promise.resolve() : Promise.resolve().then(() => { const SUB_DIRECTORY = dirname(directory); return isDirectoryProm(SUB_DIRECTORY).then((_exists) => { return _exists ? new Promise((resolve, reject) => { mkdir(directory, _mode, (err) => { return err ? reject(err) : resolve(); }); }) : new Promise((resolve, reject) => { _mkdirp(SUB_DIRECTORY, _mode, (err) => { return err ? reject(err) : mkdir(directory, _mode, (_err) => { return _err ? reject(_err) : resolve(); }); }); }); }); }); }).then(() => { _callback(null); }).catch(callback); } }
javascript
function _mkdirp (directory, mode, callback) { if ("undefined" === typeof directory) { throw new ReferenceError("missing \"directory\" argument"); } else if ("string" !== typeof directory) { throw new TypeError("\"directory\" argument is not a string"); } else if ("" === directory.trim()) { throw new Error("\"directory\" argument is empty"); } else if ("undefined" !== typeof callback && "number" !== typeof mode) { throw new TypeError("\"mode\" argument is not a number"); } else if ("undefined" === typeof callback && "undefined" === typeof mode) { throw new ReferenceError("missing \"callback\" argument"); } else if ("function" !== typeof callback && "function" !== typeof mode) { throw new TypeError("\"callback\" argument is not a function"); } else { let _callback = callback; let _mode = mode; if ("undefined" === typeof _callback) { _callback = mode; _mode = DEFAULT_OPTION; } isDirectoryProm(directory).then((exists) => { return exists ? Promise.resolve() : Promise.resolve().then(() => { const SUB_DIRECTORY = dirname(directory); return isDirectoryProm(SUB_DIRECTORY).then((_exists) => { return _exists ? new Promise((resolve, reject) => { mkdir(directory, _mode, (err) => { return err ? reject(err) : resolve(); }); }) : new Promise((resolve, reject) => { _mkdirp(SUB_DIRECTORY, _mode, (err) => { return err ? reject(err) : mkdir(directory, _mode, (_err) => { return _err ? reject(_err) : resolve(); }); }); }); }); }); }).then(() => { _callback(null); }).catch(callback); } }
[ "function", "_mkdirp", "(", "directory", ",", "mode", ",", "callback", ")", "{", "if", "(", "\"undefined\"", "===", "typeof", "directory", ")", "{", "throw", "new", "ReferenceError", "(", "\"missing \\\"directory\\\" argument\"", ")", ";", "}", "else", "if", "(", "\"string\"", "!==", "typeof", "directory", ")", "{", "throw", "new", "TypeError", "(", "\"\\\"directory\\\" argument is not a string\"", ")", ";", "}", "else", "if", "(", "\"\"", "===", "directory", ".", "trim", "(", ")", ")", "{", "throw", "new", "Error", "(", "\"\\\"directory\\\" argument is empty\"", ")", ";", "}", "else", "if", "(", "\"undefined\"", "!==", "typeof", "callback", "&&", "\"number\"", "!==", "typeof", "mode", ")", "{", "throw", "new", "TypeError", "(", "\"\\\"mode\\\" argument is not a number\"", ")", ";", "}", "else", "if", "(", "\"undefined\"", "===", "typeof", "callback", "&&", "\"undefined\"", "===", "typeof", "mode", ")", "{", "throw", "new", "ReferenceError", "(", "\"missing \\\"callback\\\" argument\"", ")", ";", "}", "else", "if", "(", "\"function\"", "!==", "typeof", "callback", "&&", "\"function\"", "!==", "typeof", "mode", ")", "{", "throw", "new", "TypeError", "(", "\"\\\"callback\\\" argument is not a function\"", ")", ";", "}", "else", "{", "let", "_callback", "=", "callback", ";", "let", "_mode", "=", "mode", ";", "if", "(", "\"undefined\"", "===", "typeof", "_callback", ")", "{", "_callback", "=", "mode", ";", "_mode", "=", "DEFAULT_OPTION", ";", "}", "isDirectoryProm", "(", "directory", ")", ".", "then", "(", "(", "exists", ")", "=>", "{", "return", "exists", "?", "Promise", ".", "resolve", "(", ")", ":", "Promise", ".", "resolve", "(", ")", ".", "then", "(", "(", ")", "=>", "{", "const", "SUB_DIRECTORY", "=", "dirname", "(", "directory", ")", ";", "return", "isDirectoryProm", "(", "SUB_DIRECTORY", ")", ".", "then", "(", "(", "_exists", ")", "=>", "{", "return", "_exists", "?", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "mkdir", "(", "directory", ",", "_mode", ",", "(", "err", ")", "=>", "{", "return", "err", "?", "reject", "(", "err", ")", ":", "resolve", "(", ")", ";", "}", ")", ";", "}", ")", ":", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "_mkdirp", "(", "SUB_DIRECTORY", ",", "_mode", ",", "(", "err", ")", "=>", "{", "return", "err", "?", "reject", "(", "err", ")", ":", "mkdir", "(", "directory", ",", "_mode", ",", "(", "_err", ")", "=>", "{", "return", "_err", "?", "reject", "(", "_err", ")", ":", "resolve", "(", ")", ";", "}", ")", ";", "}", ")", ";", "}", ")", ";", "}", ")", ";", "}", ")", ";", "}", ")", ".", "then", "(", "(", ")", "=>", "{", "_callback", "(", "null", ")", ";", "}", ")", ".", "catch", "(", "callback", ")", ";", "}", "}" ]
methods Async mkdirp @param {string} directory : directory path @param {number} mode : creation mode @param {function|null} callback : operation's result @returns {void}
[ "methods", "Async", "mkdirp" ]
016e272fc58c6ef6eae5ea551a0e8873f0ac20cc
https://github.com/Psychopoulet/node-promfs/blob/016e272fc58c6ef6eae5ea551a0e8873f0ac20cc/lib/extends/_mkdirp.js#L27-L93
51,267
redisjs/jsr-server
lib/command/server/debug.js
diff
function diff(req, res) { // defined and loaded commands var cmds = this.execs // map of all standard top-level commands , map = Constants.MAP // output multi bulk reply list , list = [] , k; for(k in map) { if(!cmds[k]) list.push(k); } res.send(null, list); }
javascript
function diff(req, res) { // defined and loaded commands var cmds = this.execs // map of all standard top-level commands , map = Constants.MAP // output multi bulk reply list , list = [] , k; for(k in map) { if(!cmds[k]) list.push(k); } res.send(null, list); }
[ "function", "diff", "(", "req", ",", "res", ")", "{", "// defined and loaded commands", "var", "cmds", "=", "this", ".", "execs", "// map of all standard top-level commands", ",", "map", "=", "Constants", ".", "MAP", "// output multi bulk reply list", ",", "list", "=", "[", "]", ",", "k", ";", "for", "(", "k", "in", "map", ")", "{", "if", "(", "!", "cmds", "[", "k", "]", ")", "list", ".", "push", "(", "k", ")", ";", "}", "res", ".", "send", "(", "null", ",", "list", ")", ";", "}" ]
Respond to the DIFF subcommand. Non-standard debug subcommand that returns a diff between the list of standard redis commands and the commands loaded. Primarily useful to determine which commands have not yet been implemented, but in a scenario where commands have been renamed, deleted or custom commands loaded this could also be useful.
[ "Respond", "to", "the", "DIFF", "subcommand", "." ]
49413052d3039524fbdd2ade0ef9bae26cb4d647
https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/server/debug.js#L33-L47
51,268
redisjs/jsr-server
lib/command/server/debug.js
reload
function reload(req, res) { var log = this.log; if(Persistence.loading) { return res.send(new Error('database load in progress')); } Persistence.load(this.state.store, this.state.conf, function onLoad(err, time, diff, version) { if(err) return log.warning('db reload error: %s', err.message); log.notice( 'db reloaded by DEBUG RELOAD: %s seconds (v%s)', time, version); } ); res.send(null, Constants.OK); }
javascript
function reload(req, res) { var log = this.log; if(Persistence.loading) { return res.send(new Error('database load in progress')); } Persistence.load(this.state.store, this.state.conf, function onLoad(err, time, diff, version) { if(err) return log.warning('db reload error: %s', err.message); log.notice( 'db reloaded by DEBUG RELOAD: %s seconds (v%s)', time, version); } ); res.send(null, Constants.OK); }
[ "function", "reload", "(", "req", ",", "res", ")", "{", "var", "log", "=", "this", ".", "log", ";", "if", "(", "Persistence", ".", "loading", ")", "{", "return", "res", ".", "send", "(", "new", "Error", "(", "'database load in progress'", ")", ")", ";", "}", "Persistence", ".", "load", "(", "this", ".", "state", ".", "store", ",", "this", ".", "state", ".", "conf", ",", "function", "onLoad", "(", "err", ",", "time", ",", "diff", ",", "version", ")", "{", "if", "(", "err", ")", "return", "log", ".", "warning", "(", "'db reload error: %s'", ",", "err", ".", "message", ")", ";", "log", ".", "notice", "(", "'db reloaded by DEBUG RELOAD: %s seconds (v%s)'", ",", "time", ",", "version", ")", ";", "}", ")", ";", "res", ".", "send", "(", "null", ",", "Constants", ".", "OK", ")", ";", "}" ]
Respond to the RELOAD subcommand.
[ "Respond", "to", "the", "RELOAD", "subcommand", "." ]
49413052d3039524fbdd2ade0ef9bae26cb4d647
https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/server/debug.js#L52-L65
51,269
Nazariglez/perenquen
lib/pixi/src/core/math/shapes/Ellipse.js
Ellipse
function Ellipse(x, y, width, height) { /** * @member {number} * @default 0 */ this.x = x || 0; /** * @member {number} * @default 0 */ this.y = y || 0; /** * @member {number} * @default 0 */ this.width = width || 0; /** * @member {number} * @default 0 */ this.height = height || 0; /** * The type of the object, mainly used to avoid `instanceof` checks * * @member {number} */ this.type = CONST.SHAPES.ELIP; }
javascript
function Ellipse(x, y, width, height) { /** * @member {number} * @default 0 */ this.x = x || 0; /** * @member {number} * @default 0 */ this.y = y || 0; /** * @member {number} * @default 0 */ this.width = width || 0; /** * @member {number} * @default 0 */ this.height = height || 0; /** * The type of the object, mainly used to avoid `instanceof` checks * * @member {number} */ this.type = CONST.SHAPES.ELIP; }
[ "function", "Ellipse", "(", "x", ",", "y", ",", "width", ",", "height", ")", "{", "/**\n * @member {number}\n * @default 0\n */", "this", ".", "x", "=", "x", "||", "0", ";", "/**\n * @member {number}\n * @default 0\n */", "this", ".", "y", "=", "y", "||", "0", ";", "/**\n * @member {number}\n * @default 0\n */", "this", ".", "width", "=", "width", "||", "0", ";", "/**\n * @member {number}\n * @default 0\n */", "this", ".", "height", "=", "height", "||", "0", ";", "/**\n * The type of the object, mainly used to avoid `instanceof` checks\n *\n * @member {number}\n */", "this", ".", "type", "=", "CONST", ".", "SHAPES", ".", "ELIP", ";", "}" ]
The Ellipse object can be used to specify a hit area for displayObjects @class @memberof PIXI @param x {number} The X coordinate of the center of the ellipse @param y {number} The Y coordinate of the center of the ellipse @param width {number} The half width of this ellipse @param height {number} The half height of this ellipse
[ "The", "Ellipse", "object", "can", "be", "used", "to", "specify", "a", "hit", "area", "for", "displayObjects" ]
e023964d05afeefebdcac4e2044819fdfa3899ae
https://github.com/Nazariglez/perenquen/blob/e023964d05afeefebdcac4e2044819fdfa3899ae/lib/pixi/src/core/math/shapes/Ellipse.js#L14-L46
51,270
haraldrudell/apprunner
lib/apperror.js
apiError
function apiError(err) { var f = testProbe ? testProbe : anomaly.anomaly f.apply(this, Array.prototype.slice.call(arguments)) }
javascript
function apiError(err) { var f = testProbe ? testProbe : anomaly.anomaly f.apply(this, Array.prototype.slice.call(arguments)) }
[ "function", "apiError", "(", "err", ")", "{", "var", "f", "=", "testProbe", "?", "testProbe", ":", "anomaly", ".", "anomaly", "f", ".", "apply", "(", "this", ",", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ")", ")", "}" ]
report error from unknown api
[ "report", "error", "from", "unknown", "api" ]
8d7dead166c919d160b429e00c49a62027994c33
https://github.com/haraldrudell/apprunner/blob/8d7dead166c919d160b429e00c49a62027994c33/lib/apperror.js#L16-L19
51,271
cortexjs-legacy/cortex-scaffold-generator
index.js
function (done) { var root = node_path.join(__dirname, 'templates', template); fs.exists(root, function(exists){ if(exists){ template_root = root; }else{ template_root = node_path.join(DIR_CUSTOM_TEMPLATES, template) } done(null); }); }
javascript
function (done) { var root = node_path.join(__dirname, 'templates', template); fs.exists(root, function(exists){ if(exists){ template_root = root; }else{ template_root = node_path.join(DIR_CUSTOM_TEMPLATES, template) } done(null); }); }
[ "function", "(", "done", ")", "{", "var", "root", "=", "node_path", ".", "join", "(", "__dirname", ",", "'templates'", ",", "template", ")", ";", "fs", ".", "exists", "(", "root", ",", "function", "(", "exists", ")", "{", "if", "(", "exists", ")", "{", "template_root", "=", "root", ";", "}", "else", "{", "template_root", "=", "node_path", ".", "join", "(", "DIR_CUSTOM_TEMPLATES", ",", "template", ")", "}", "done", "(", "null", ")", ";", "}", ")", ";", "}" ]
set template root
[ "set", "template", "root" ]
da5e4b18832e478176babb9c065d3e3178b88331
https://github.com/cortexjs-legacy/cortex-scaffold-generator/blob/da5e4b18832e478176babb9c065d3e3178b88331/index.js#L75-L86
51,272
cortexjs-legacy/cortex-scaffold-generator
index.js
function (done) { var p = clone(pkg); delete p.devDependencies; var content = JSON.stringify(p, null, 2); write_if_not_exists('package.json', content, done); }
javascript
function (done) { var p = clone(pkg); delete p.devDependencies; var content = JSON.stringify(p, null, 2); write_if_not_exists('package.json', content, done); }
[ "function", "(", "done", ")", "{", "var", "p", "=", "clone", "(", "pkg", ")", ";", "delete", "p", ".", "devDependencies", ";", "var", "content", "=", "JSON", ".", "stringify", "(", "p", ",", "null", ",", "2", ")", ";", "write_if_not_exists", "(", "'package.json'", ",", "content", ",", "done", ")", ";", "}" ]
write package.json
[ "write", "package", ".", "json" ]
da5e4b18832e478176babb9c065d3e3178b88331
https://github.com/cortexjs-legacy/cortex-scaffold-generator/blob/da5e4b18832e478176babb9c065d3e3178b88331/index.js#L116-L121
51,273
timrwood/grunt-haychtml
lib/haychtml.js
extensionMatches
function extensionMatches (filename) { var extname = path.extname(filename); if (extname) { return extname === extension; } return true; }
javascript
function extensionMatches (filename) { var extname = path.extname(filename); if (extname) { return extname === extension; } return true; }
[ "function", "extensionMatches", "(", "filename", ")", "{", "var", "extname", "=", "path", ".", "extname", "(", "filename", ")", ";", "if", "(", "extname", ")", "{", "return", "extname", "===", "extension", ";", "}", "return", "true", ";", "}" ]
We only want files that end with the correct extension
[ "We", "only", "want", "files", "that", "end", "with", "the", "correct", "extension" ]
70bfa1ba754d91ae481a8b3ab0a2a566b7d73b1c
https://github.com/timrwood/grunt-haychtml/blob/70bfa1ba754d91ae481a8b3ab0a2a566b7d73b1c/lib/haychtml.js#L106-L112
51,274
timrwood/grunt-haychtml
lib/haychtml.js
handleDirectoryOrFile
function handleDirectoryOrFile (filename) { var absolutePath = path.join(dir, recursePath, filename), relativePath = path.join(recursePath, filename); if (fs.statSync(absolutePath).isDirectory()) { find(dir, extension, relativePath).forEach(addFileToOutput); } else { addFileToOutput(new File(relativePath)); } }
javascript
function handleDirectoryOrFile (filename) { var absolutePath = path.join(dir, recursePath, filename), relativePath = path.join(recursePath, filename); if (fs.statSync(absolutePath).isDirectory()) { find(dir, extension, relativePath).forEach(addFileToOutput); } else { addFileToOutput(new File(relativePath)); } }
[ "function", "handleDirectoryOrFile", "(", "filename", ")", "{", "var", "absolutePath", "=", "path", ".", "join", "(", "dir", ",", "recursePath", ",", "filename", ")", ",", "relativePath", "=", "path", ".", "join", "(", "recursePath", ",", "filename", ")", ";", "if", "(", "fs", ".", "statSync", "(", "absolutePath", ")", ".", "isDirectory", "(", ")", ")", "{", "find", "(", "dir", ",", "extension", ",", "relativePath", ")", ".", "forEach", "(", "addFileToOutput", ")", ";", "}", "else", "{", "addFileToOutput", "(", "new", "File", "(", "relativePath", ")", ")", ";", "}", "}" ]
If the path is a file, create a File object and add it to the output array.
[ "If", "the", "path", "is", "a", "file", "create", "a", "File", "object", "and", "add", "it", "to", "the", "output", "array", "." ]
70bfa1ba754d91ae481a8b3ab0a2a566b7d73b1c
https://github.com/timrwood/grunt-haychtml/blob/70bfa1ba754d91ae481a8b3ab0a2a566b7d73b1c/lib/haychtml.js#L124-L133
51,275
tjmehta/mongooseware
lib/method-lists/list-class-methods.js
listClassMethods
function listClassMethods (Model) { var classMethods = Object.keys(Model.schema.statics); for (var method in Model) { if (!isPrivateMethod(method) && isFunction(Model[method])) { classMethods.push(method); } } return classMethods; }
javascript
function listClassMethods (Model) { var classMethods = Object.keys(Model.schema.statics); for (var method in Model) { if (!isPrivateMethod(method) && isFunction(Model[method])) { classMethods.push(method); } } return classMethods; }
[ "function", "listClassMethods", "(", "Model", ")", "{", "var", "classMethods", "=", "Object", ".", "keys", "(", "Model", ".", "schema", ".", "statics", ")", ";", "for", "(", "var", "method", "in", "Model", ")", "{", "if", "(", "!", "isPrivateMethod", "(", "method", ")", "&&", "isFunction", "(", "Model", "[", "method", "]", ")", ")", "{", "classMethods", ".", "push", "(", "method", ")", ";", "}", "}", "return", "classMethods", ";", "}" ]
Returns list of non-private class methods @param {Object} Model @return {Array}
[ "Returns", "list", "of", "non", "-", "private", "class", "methods" ]
c62ce0bac82880826b3528231e08f5e5b3efdb83
https://github.com/tjmehta/mongooseware/blob/c62ce0bac82880826b3528231e08f5e5b3efdb83/lib/method-lists/list-class-methods.js#L18-L26
51,276
DeadAlready/node-foldermap
lib/utils.js
clone
function clone(obj) { if (typeof obj !== 'object') { return obj; } var ret; if (util.isArray(obj)) { ret = []; obj.forEach(function (val) { ret.push(clone(val)); }); return ret; } ret = {}; Object.keys(obj).forEach(function (key) { ret[key] = clone(obj[key]); }); return ret; }
javascript
function clone(obj) { if (typeof obj !== 'object') { return obj; } var ret; if (util.isArray(obj)) { ret = []; obj.forEach(function (val) { ret.push(clone(val)); }); return ret; } ret = {}; Object.keys(obj).forEach(function (key) { ret[key] = clone(obj[key]); }); return ret; }
[ "function", "clone", "(", "obj", ")", "{", "if", "(", "typeof", "obj", "!==", "'object'", ")", "{", "return", "obj", ";", "}", "var", "ret", ";", "if", "(", "util", ".", "isArray", "(", "obj", ")", ")", "{", "ret", "=", "[", "]", ";", "obj", ".", "forEach", "(", "function", "(", "val", ")", "{", "ret", ".", "push", "(", "clone", "(", "val", ")", ")", ";", "}", ")", ";", "return", "ret", ";", "}", "ret", "=", "{", "}", ";", "Object", ".", "keys", "(", "obj", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "ret", "[", "key", "]", "=", "clone", "(", "obj", "[", "key", "]", ")", ";", "}", ")", ";", "return", "ret", ";", "}" ]
Function for creating a clone of an object @param o {Object} object to clone @return {Object}
[ "Function", "for", "creating", "a", "clone", "of", "an", "object" ]
be6048cb3b3e9fa3b6f36542cb8835d48c7bde1d
https://github.com/DeadAlready/node-foldermap/blob/be6048cb3b3e9fa3b6f36542cb8835d48c7bde1d/lib/utils.js#L14-L31
51,277
DeadAlready/node-foldermap
lib/utils.js
extend
function extend(a, b, noClone) { // A extends B a = a || {}; if (typeof a !== 'object') { return noClone ? b : clone(b); } if (typeof b !== 'object') { return b; } if (!noClone) { a = clone(a); } Object.keys(b).forEach(function (key) { if (!a.hasOwnProperty(key) || (!(typeof b[key] === 'object' && b[key].length === undefined && b[key].constructor.name === 'Folder') && (typeof b[key] !== 'function'))) { // Simple types a[key] = b[key]; } else { // Complex types a[key] = extend(a[key], b[key], noClone); } }); return a; }
javascript
function extend(a, b, noClone) { // A extends B a = a || {}; if (typeof a !== 'object') { return noClone ? b : clone(b); } if (typeof b !== 'object') { return b; } if (!noClone) { a = clone(a); } Object.keys(b).forEach(function (key) { if (!a.hasOwnProperty(key) || (!(typeof b[key] === 'object' && b[key].length === undefined && b[key].constructor.name === 'Folder') && (typeof b[key] !== 'function'))) { // Simple types a[key] = b[key]; } else { // Complex types a[key] = extend(a[key], b[key], noClone); } }); return a; }
[ "function", "extend", "(", "a", ",", "b", ",", "noClone", ")", "{", "// A extends B", "a", "=", "a", "||", "{", "}", ";", "if", "(", "typeof", "a", "!==", "'object'", ")", "{", "return", "noClone", "?", "b", ":", "clone", "(", "b", ")", ";", "}", "if", "(", "typeof", "b", "!==", "'object'", ")", "{", "return", "b", ";", "}", "if", "(", "!", "noClone", ")", "{", "a", "=", "clone", "(", "a", ")", ";", "}", "Object", ".", "keys", "(", "b", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "if", "(", "!", "a", ".", "hasOwnProperty", "(", "key", ")", "||", "(", "!", "(", "typeof", "b", "[", "key", "]", "===", "'object'", "&&", "b", "[", "key", "]", ".", "length", "===", "undefined", "&&", "b", "[", "key", "]", ".", "constructor", ".", "name", "===", "'Folder'", ")", "&&", "(", "typeof", "b", "[", "key", "]", "!==", "'function'", ")", ")", ")", "{", "// Simple types", "a", "[", "key", "]", "=", "b", "[", "key", "]", ";", "}", "else", "{", "// Complex types", "a", "[", "key", "]", "=", "extend", "(", "a", "[", "key", "]", ",", "b", "[", "key", "]", ",", "noClone", ")", ";", "}", "}", ")", ";", "return", "a", ";", "}" ]
A extends B util.inherits works only with objects derived from Object @return {Object} Extended object
[ "A", "extends", "B" ]
be6048cb3b3e9fa3b6f36542cb8835d48c7bde1d
https://github.com/DeadAlready/node-foldermap/blob/be6048cb3b3e9fa3b6f36542cb8835d48c7bde1d/lib/utils.js#L40-L65
51,278
Zingle/tlsfs
index.js
readCertsSync
function readCertsSync(paths) { var opts = {}; if (!(paths instanceof Array)) throw new TypeError("readCertsSync expects Array argument"); switch (paths.length) { case 1: opts.pfx = fs.readFileSync(paths[0]); break; case 2: opts.cert = fs.readFileSync(paths[0]); opts.key = fs.readFileSync(paths[1]); break; default: opts.cert = fs.readFileSync(paths[0]); opts.key = fs.readFileSync(paths[1]); opts.ca = []; paths.slice(2).forEach(function(path) { opts.ca.push(fs.readFileSync(path)); }); } return opts; }
javascript
function readCertsSync(paths) { var opts = {}; if (!(paths instanceof Array)) throw new TypeError("readCertsSync expects Array argument"); switch (paths.length) { case 1: opts.pfx = fs.readFileSync(paths[0]); break; case 2: opts.cert = fs.readFileSync(paths[0]); opts.key = fs.readFileSync(paths[1]); break; default: opts.cert = fs.readFileSync(paths[0]); opts.key = fs.readFileSync(paths[1]); opts.ca = []; paths.slice(2).forEach(function(path) { opts.ca.push(fs.readFileSync(path)); }); } return opts; }
[ "function", "readCertsSync", "(", "paths", ")", "{", "var", "opts", "=", "{", "}", ";", "if", "(", "!", "(", "paths", "instanceof", "Array", ")", ")", "throw", "new", "TypeError", "(", "\"readCertsSync expects Array argument\"", ")", ";", "switch", "(", "paths", ".", "length", ")", "{", "case", "1", ":", "opts", ".", "pfx", "=", "fs", ".", "readFileSync", "(", "paths", "[", "0", "]", ")", ";", "break", ";", "case", "2", ":", "opts", ".", "cert", "=", "fs", ".", "readFileSync", "(", "paths", "[", "0", "]", ")", ";", "opts", ".", "key", "=", "fs", ".", "readFileSync", "(", "paths", "[", "1", "]", ")", ";", "break", ";", "default", ":", "opts", ".", "cert", "=", "fs", ".", "readFileSync", "(", "paths", "[", "0", "]", ")", ";", "opts", ".", "key", "=", "fs", ".", "readFileSync", "(", "paths", "[", "1", "]", ")", ";", "opts", ".", "ca", "=", "[", "]", ";", "paths", ".", "slice", "(", "2", ")", ".", "forEach", "(", "function", "(", "path", ")", "{", "opts", ".", "ca", ".", "push", "(", "fs", ".", "readFileSync", "(", "path", ")", ")", ";", "}", ")", ";", "}", "return", "opts", ";", "}" ]
Read TLS certs from filesystem synchronously. Return TLS options object with 'pfx' or 'cert', 'key', and 'ca' options, depending on the number of paths provided. @param {string[]} paths @returns {object}
[ "Read", "TLS", "certs", "from", "filesystem", "synchronously", ".", "Return", "TLS", "options", "object", "with", "pfx", "or", "cert", "key", "and", "ca", "options", "depending", "on", "the", "number", "of", "paths", "provided", "." ]
ea541c70728263867b9277369943f039c9b82bbd
https://github.com/Zingle/tlsfs/blob/ea541c70728263867b9277369943f039c9b82bbd/index.js#L11-L35
51,279
Zingle/tlsfs
index.js
readCerts
function readCerts(paths, done) { if (!(paths instanceof Array)) throw new TypeError("readCertsSync expects Array argument"); async.map(paths, fs.readFile, function(err, files) { var opts = {}; if (err) done(err); else switch (files.length) { case 1: opts.pfx = files[0]; break; case 2: opts.cert = files[0]; opts.key = files[1]; break; default: opts.cert = files[0]; opts.key = files[1]; opts.ca = files.slice(2); } done(null, opts); }); }
javascript
function readCerts(paths, done) { if (!(paths instanceof Array)) throw new TypeError("readCertsSync expects Array argument"); async.map(paths, fs.readFile, function(err, files) { var opts = {}; if (err) done(err); else switch (files.length) { case 1: opts.pfx = files[0]; break; case 2: opts.cert = files[0]; opts.key = files[1]; break; default: opts.cert = files[0]; opts.key = files[1]; opts.ca = files.slice(2); } done(null, opts); }); }
[ "function", "readCerts", "(", "paths", ",", "done", ")", "{", "if", "(", "!", "(", "paths", "instanceof", "Array", ")", ")", "throw", "new", "TypeError", "(", "\"readCertsSync expects Array argument\"", ")", ";", "async", ".", "map", "(", "paths", ",", "fs", ".", "readFile", ",", "function", "(", "err", ",", "files", ")", "{", "var", "opts", "=", "{", "}", ";", "if", "(", "err", ")", "done", "(", "err", ")", ";", "else", "switch", "(", "files", ".", "length", ")", "{", "case", "1", ":", "opts", ".", "pfx", "=", "files", "[", "0", "]", ";", "break", ";", "case", "2", ":", "opts", ".", "cert", "=", "files", "[", "0", "]", ";", "opts", ".", "key", "=", "files", "[", "1", "]", ";", "break", ";", "default", ":", "opts", ".", "cert", "=", "files", "[", "0", "]", ";", "opts", ".", "key", "=", "files", "[", "1", "]", ";", "opts", ".", "ca", "=", "files", ".", "slice", "(", "2", ")", ";", "}", "done", "(", "null", ",", "opts", ")", ";", "}", ")", ";", "}" ]
Read TLS certs from filesystem. Pass TLS options object to callback with 'pfx' or 'cert', 'key', and 'ca' options, depending on the number of paths provided. @param {string[]} paths @param {function} done
[ "Read", "TLS", "certs", "from", "filesystem", ".", "Pass", "TLS", "options", "object", "to", "callback", "with", "pfx", "or", "cert", "key", "and", "ca", "options", "depending", "on", "the", "number", "of", "paths", "provided", "." ]
ea541c70728263867b9277369943f039c9b82bbd
https://github.com/Zingle/tlsfs/blob/ea541c70728263867b9277369943f039c9b82bbd/index.js#L44-L68
51,280
nerdvibe/awesome_starter
error_handling.js
expressResponseError_silent
function expressResponseError_silent(response, message) { let errorMessage = "there was an error in the request"; if(message) errorMessage = message response.json({ success: false, error: errorMessage }); }
javascript
function expressResponseError_silent(response, message) { let errorMessage = "there was an error in the request"; if(message) errorMessage = message response.json({ success: false, error: errorMessage }); }
[ "function", "expressResponseError_silent", "(", "response", ",", "message", ")", "{", "let", "errorMessage", "=", "\"there was an error in the request\"", ";", "if", "(", "message", ")", "errorMessage", "=", "message", "response", ".", "json", "(", "{", "success", ":", "false", ",", "error", ":", "errorMessage", "}", ")", ";", "}" ]
General internal error for express
[ "General", "internal", "error", "for", "express" ]
9440d54c43dd8459f6cb5865cc65d5f0ce352523
https://github.com/nerdvibe/awesome_starter/blob/9440d54c43dd8459f6cb5865cc65d5f0ce352523/error_handling.js#L11-L16
51,281
nerdvibe/awesome_starter
error_handling.js
expressResponseError
function expressResponseError(response, error, message) { let errorMessage = "there was an error in the request"; if(message) errorMessage = message response.json({ success: false, error: errorMessage }); console.error(error); }
javascript
function expressResponseError(response, error, message) { let errorMessage = "there was an error in the request"; if(message) errorMessage = message response.json({ success: false, error: errorMessage }); console.error(error); }
[ "function", "expressResponseError", "(", "response", ",", "error", ",", "message", ")", "{", "let", "errorMessage", "=", "\"there was an error in the request\"", ";", "if", "(", "message", ")", "errorMessage", "=", "message", "response", ".", "json", "(", "{", "success", ":", "false", ",", "error", ":", "errorMessage", "}", ")", ";", "console", ".", "error", "(", "error", ")", ";", "}" ]
General internal error for express with console.error
[ "General", "internal", "error", "for", "express", "with", "console", ".", "error" ]
9440d54c43dd8459f6cb5865cc65d5f0ce352523
https://github.com/nerdvibe/awesome_starter/blob/9440d54c43dd8459f6cb5865cc65d5f0ce352523/error_handling.js#L21-L27
51,282
jonschlinkert/normalize-keywords
index.js
properize
function properize(word, options) { options = _.extend({inflect: false}, options); if (!/\./.test(word)) { word = changeCase(word); if (options.inflect === false) { return word; } return inflection.singularize(word); } return word; }
javascript
function properize(word, options) { options = _.extend({inflect: false}, options); if (!/\./.test(word)) { word = changeCase(word); if (options.inflect === false) { return word; } return inflection.singularize(word); } return word; }
[ "function", "properize", "(", "word", ",", "options", ")", "{", "options", "=", "_", ".", "extend", "(", "{", "inflect", ":", "false", "}", ",", "options", ")", ";", "if", "(", "!", "/", "\\.", "/", ".", "test", "(", "word", ")", ")", "{", "word", "=", "changeCase", "(", "word", ")", ";", "if", "(", "options", ".", "inflect", "===", "false", ")", "{", "return", "word", ";", "}", "return", "inflection", ".", "singularize", "(", "word", ")", ";", "}", "return", "word", ";", "}" ]
Make the word lowercase, dashed, and singular. @param {String} `word` @return {String}
[ "Make", "the", "word", "lowercase", "dashed", "and", "singular", "." ]
f4d1a92fab85c49636929d3a23652b1795b9ac22
https://github.com/jonschlinkert/normalize-keywords/blob/f4d1a92fab85c49636929d3a23652b1795b9ac22/index.js#L60-L70
51,283
jonschlinkert/normalize-keywords
index.js
chop
function chop(keywords) { return keywords.slice(0) .reduce(function(acc, ele) { acc = acc.concat(ele.split('-')); return acc; }, []); }
javascript
function chop(keywords) { return keywords.slice(0) .reduce(function(acc, ele) { acc = acc.concat(ele.split('-')); return acc; }, []); }
[ "function", "chop", "(", "keywords", ")", "{", "return", "keywords", ".", "slice", "(", "0", ")", ".", "reduce", "(", "function", "(", "acc", ",", "ele", ")", "{", "acc", "=", "acc", ".", "concat", "(", "ele", ".", "split", "(", "'-'", ")", ")", ";", "return", "acc", ";", "}", ",", "[", "]", ")", ";", "}" ]
Clone the array and split words by dashes, then concat the results back into the array @param {Array} keywords @return {Array}
[ "Clone", "the", "array", "and", "split", "words", "by", "dashes", "then", "concat", "the", "results", "back", "into", "the", "array" ]
f4d1a92fab85c49636929d3a23652b1795b9ac22
https://github.com/jonschlinkert/normalize-keywords/blob/f4d1a92fab85c49636929d3a23652b1795b9ac22/index.js#L80-L86
51,284
jonschlinkert/normalize-keywords
index.js
changeCase
function changeCase(str) { if (str == null) return ''; str = String(str); str = str.replace(/\./g, 'zzz') str = str.replace(/_/g, '-') str = str.replace(/([A-Z]+)/g, function (_, $1) { return '-' + $1.toLowerCase(); }); str = str.replace(/[^a-z-]+/g, '-') str = str.replace(/^[-\s]+|[-\s]+$/g, ''); str = str.replace(/zzz/g, '.'); return str; }
javascript
function changeCase(str) { if (str == null) return ''; str = String(str); str = str.replace(/\./g, 'zzz') str = str.replace(/_/g, '-') str = str.replace(/([A-Z]+)/g, function (_, $1) { return '-' + $1.toLowerCase(); }); str = str.replace(/[^a-z-]+/g, '-') str = str.replace(/^[-\s]+|[-\s]+$/g, ''); str = str.replace(/zzz/g, '.'); return str; }
[ "function", "changeCase", "(", "str", ")", "{", "if", "(", "str", "==", "null", ")", "return", "''", ";", "str", "=", "String", "(", "str", ")", ";", "str", "=", "str", ".", "replace", "(", "/", "\\.", "/", "g", ",", "'zzz'", ")", "str", "=", "str", ".", "replace", "(", "/", "_", "/", "g", ",", "'-'", ")", "str", "=", "str", ".", "replace", "(", "/", "([A-Z]+)", "/", "g", ",", "function", "(", "_", ",", "$1", ")", "{", "return", "'-'", "+", "$1", ".", "toLowerCase", "(", ")", ";", "}", ")", ";", "str", "=", "str", ".", "replace", "(", "/", "[^a-z-]+", "/", "g", ",", "'-'", ")", "str", "=", "str", ".", "replace", "(", "/", "^[-\\s]+|[-\\s]+$", "/", "g", ",", "''", ")", ";", "str", "=", "str", ".", "replace", "(", "/", "zzz", "/", "g", ",", "'.'", ")", ";", "return", "str", ";", "}" ]
Convert camelcase to slugs, remove leading and trailing dashes and whitespace. Convert underscores to dashes. @param {String} `str` @return {String}
[ "Convert", "camelcase", "to", "slugs", "remove", "leading", "and", "trailing", "dashes", "and", "whitespace", ".", "Convert", "underscores", "to", "dashes", "." ]
f4d1a92fab85c49636929d3a23652b1795b9ac22
https://github.com/jonschlinkert/normalize-keywords/blob/f4d1a92fab85c49636929d3a23652b1795b9ac22/index.js#L109-L121
51,285
jonschlinkert/normalize-keywords
index.js
sanitize
function sanitize(arr, opts) { return _.reduce(arr, function (acc, keywords) { keywords = keywords.split(' ').filter(Boolean); return acc.concat(keywords).map(function (keyword, i) { if (opts && opts.sanitize) { return opts.sanitize(keyword, i, keywords); } return keyword.toLowerCase(); }).sort(); }, []); }
javascript
function sanitize(arr, opts) { return _.reduce(arr, function (acc, keywords) { keywords = keywords.split(' ').filter(Boolean); return acc.concat(keywords).map(function (keyword, i) { if (opts && opts.sanitize) { return opts.sanitize(keyword, i, keywords); } return keyword.toLowerCase(); }).sort(); }, []); }
[ "function", "sanitize", "(", "arr", ",", "opts", ")", "{", "return", "_", ".", "reduce", "(", "arr", ",", "function", "(", "acc", ",", "keywords", ")", "{", "keywords", "=", "keywords", ".", "split", "(", "' '", ")", ".", "filter", "(", "Boolean", ")", ";", "return", "acc", ".", "concat", "(", "keywords", ")", ".", "map", "(", "function", "(", "keyword", ",", "i", ")", "{", "if", "(", "opts", "&&", "opts", ".", "sanitize", ")", "{", "return", "opts", ".", "sanitize", "(", "keyword", ",", "i", ",", "keywords", ")", ";", "}", "return", "keyword", ".", "toLowerCase", "(", ")", ";", "}", ")", ".", "sort", "(", ")", ";", "}", ",", "[", "]", ")", ";", "}" ]
Clean up empty values, sentences, and non-word characters that shouldn't polute the keywords. @param {Array} `arr` @return {Array}
[ "Clean", "up", "empty", "values", "sentences", "and", "non", "-", "word", "characters", "that", "shouldn", "t", "polute", "the", "keywords", "." ]
f4d1a92fab85c49636929d3a23652b1795b9ac22
https://github.com/jonschlinkert/normalize-keywords/blob/f4d1a92fab85c49636929d3a23652b1795b9ac22/index.js#L132-L142
51,286
jonschlinkert/normalize-keywords
index.js
uniq
function uniq(arr) { if (arr == null || arr.length === 0) { return []; } return _.reduce(arr, function(acc, ele) { var letter = exclusions.singleLetters; if (acc.indexOf(ele) === -1 && letter.indexOf(ele) === -1) { acc.push(ele); } return acc; }, []); }
javascript
function uniq(arr) { if (arr == null || arr.length === 0) { return []; } return _.reduce(arr, function(acc, ele) { var letter = exclusions.singleLetters; if (acc.indexOf(ele) === -1 && letter.indexOf(ele) === -1) { acc.push(ele); } return acc; }, []); }
[ "function", "uniq", "(", "arr", ")", "{", "if", "(", "arr", "==", "null", "||", "arr", ".", "length", "===", "0", ")", "{", "return", "[", "]", ";", "}", "return", "_", ".", "reduce", "(", "arr", ",", "function", "(", "acc", ",", "ele", ")", "{", "var", "letter", "=", "exclusions", ".", "singleLetters", ";", "if", "(", "acc", ".", "indexOf", "(", "ele", ")", "===", "-", "1", "&&", "letter", ".", "indexOf", "(", "ele", ")", "===", "-", "1", ")", "{", "acc", ".", "push", "(", "ele", ")", ";", "}", "return", "acc", ";", "}", ",", "[", "]", ")", ";", "}" ]
Uniqueify keywords. @param {Array} `arr` @return {Array}
[ "Uniqueify", "keywords", "." ]
f4d1a92fab85c49636929d3a23652b1795b9ac22
https://github.com/jonschlinkert/normalize-keywords/blob/f4d1a92fab85c49636929d3a23652b1795b9ac22/index.js#L152-L165
51,287
ecliptic/webpack-blocks-copy
lib/index.js
copy
function copy (from, to) { return Object.assign( function (context) { return function (prevConfig) { context.copyPlugin = context.copyPlugin || {patterns: []} // Merge the provided simple pattern into the config context.copyPlugin = _extends({}, context.copyPlugin, { patterns: [].concat(context.copyPlugin.patterns, [ {from: from, to: to}, ]), }) // Don't alter the config yet return prevConfig } }, {post: postConfig} ) }
javascript
function copy (from, to) { return Object.assign( function (context) { return function (prevConfig) { context.copyPlugin = context.copyPlugin || {patterns: []} // Merge the provided simple pattern into the config context.copyPlugin = _extends({}, context.copyPlugin, { patterns: [].concat(context.copyPlugin.patterns, [ {from: from, to: to}, ]), }) // Don't alter the config yet return prevConfig } }, {post: postConfig} ) }
[ "function", "copy", "(", "from", ",", "to", ")", "{", "return", "Object", ".", "assign", "(", "function", "(", "context", ")", "{", "return", "function", "(", "prevConfig", ")", "{", "context", ".", "copyPlugin", "=", "context", ".", "copyPlugin", "||", "{", "patterns", ":", "[", "]", "}", "// Merge the provided simple pattern into the config", "context", ".", "copyPlugin", "=", "_extends", "(", "{", "}", ",", "context", ".", "copyPlugin", ",", "{", "patterns", ":", "[", "]", ".", "concat", "(", "context", ".", "copyPlugin", ".", "patterns", ",", "[", "{", "from", ":", "from", ",", "to", ":", "to", "}", ",", "]", ")", ",", "}", ")", "// Don't alter the config yet", "return", "prevConfig", "}", "}", ",", "{", "post", ":", "postConfig", "}", ")", "}" ]
Adds a simple copy pattern to the list of patterns for the plugin.
[ "Adds", "a", "simple", "copy", "pattern", "to", "the", "list", "of", "patterns", "for", "the", "plugin", "." ]
3bd12137a35a9237a9bdc6c4443e5ed29bfc8812
https://github.com/ecliptic/webpack-blocks-copy/blob/3bd12137a35a9237a9bdc6c4443e5ed29bfc8812/lib/index.js#L36-L55
51,288
ecliptic/webpack-blocks-copy
lib/index.js
copyPattern
function copyPattern (pattern) { return Object.assign( function (context) { return function (prevConfig) { context.copyPlugin = context.copyPlugin || {patterns: []} // Merge the provided advanced pattern into the config context.copyPlugin = _extends({}, context.copyPlugin, { patterns: [].concat(context.copyPlugin.patterns, [pattern]), }) // Don't alter the config yet return prevConfig } }, {post: postConfig} ) }
javascript
function copyPattern (pattern) { return Object.assign( function (context) { return function (prevConfig) { context.copyPlugin = context.copyPlugin || {patterns: []} // Merge the provided advanced pattern into the config context.copyPlugin = _extends({}, context.copyPlugin, { patterns: [].concat(context.copyPlugin.patterns, [pattern]), }) // Don't alter the config yet return prevConfig } }, {post: postConfig} ) }
[ "function", "copyPattern", "(", "pattern", ")", "{", "return", "Object", ".", "assign", "(", "function", "(", "context", ")", "{", "return", "function", "(", "prevConfig", ")", "{", "context", ".", "copyPlugin", "=", "context", ".", "copyPlugin", "||", "{", "patterns", ":", "[", "]", "}", "// Merge the provided advanced pattern into the config", "context", ".", "copyPlugin", "=", "_extends", "(", "{", "}", ",", "context", ".", "copyPlugin", ",", "{", "patterns", ":", "[", "]", ".", "concat", "(", "context", ".", "copyPlugin", ".", "patterns", ",", "[", "pattern", "]", ")", ",", "}", ")", "// Don't alter the config yet", "return", "prevConfig", "}", "}", ",", "{", "post", ":", "postConfig", "}", ")", "}" ]
Adds an advanced pattern to the list of patterns for the plugin.
[ "Adds", "an", "advanced", "pattern", "to", "the", "list", "of", "patterns", "for", "the", "plugin", "." ]
3bd12137a35a9237a9bdc6c4443e5ed29bfc8812
https://github.com/ecliptic/webpack-blocks-copy/blob/3bd12137a35a9237a9bdc6c4443e5ed29bfc8812/lib/index.js#L60-L77
51,289
ecliptic/webpack-blocks-copy
lib/index.js
copyOptions
function copyOptions (options) { return Object.assign( function (context) { return function (prevConfig) { context.copyPlugin = context.copyPlugin || {} // Merge the provided copy plugin config into the context context.copyPlugin = _extends({}, context.copyPlugin, { options: options, }) // Don't alter the config yet return prevConfig } }, {post: postConfig} ) }
javascript
function copyOptions (options) { return Object.assign( function (context) { return function (prevConfig) { context.copyPlugin = context.copyPlugin || {} // Merge the provided copy plugin config into the context context.copyPlugin = _extends({}, context.copyPlugin, { options: options, }) // Don't alter the config yet return prevConfig } }, {post: postConfig} ) }
[ "function", "copyOptions", "(", "options", ")", "{", "return", "Object", ".", "assign", "(", "function", "(", "context", ")", "{", "return", "function", "(", "prevConfig", ")", "{", "context", ".", "copyPlugin", "=", "context", ".", "copyPlugin", "||", "{", "}", "// Merge the provided copy plugin config into the context", "context", ".", "copyPlugin", "=", "_extends", "(", "{", "}", ",", "context", ".", "copyPlugin", ",", "{", "options", ":", "options", ",", "}", ")", "// Don't alter the config yet", "return", "prevConfig", "}", "}", ",", "{", "post", ":", "postConfig", "}", ")", "}" ]
Sets options for the copy plugin.
[ "Sets", "options", "for", "the", "copy", "plugin", "." ]
3bd12137a35a9237a9bdc6c4443e5ed29bfc8812
https://github.com/ecliptic/webpack-blocks-copy/blob/3bd12137a35a9237a9bdc6c4443e5ed29bfc8812/lib/index.js#L82-L99
51,290
ecliptic/webpack-blocks-copy
lib/index.js
postConfig
function postConfig (context, _ref) { var merge = _ref.merge return function (prevConfig) { var _context$copyPlugin = context.copyPlugin, patterns = _context$copyPlugin.patterns, options = _context$copyPlugin.options var plugin = new _copyWebpackPlugin2.default(patterns, options) return merge({plugins: [plugin]}) } }
javascript
function postConfig (context, _ref) { var merge = _ref.merge return function (prevConfig) { var _context$copyPlugin = context.copyPlugin, patterns = _context$copyPlugin.patterns, options = _context$copyPlugin.options var plugin = new _copyWebpackPlugin2.default(patterns, options) return merge({plugins: [plugin]}) } }
[ "function", "postConfig", "(", "context", ",", "_ref", ")", "{", "var", "merge", "=", "_ref", ".", "merge", "return", "function", "(", "prevConfig", ")", "{", "var", "_context$copyPlugin", "=", "context", ".", "copyPlugin", ",", "patterns", "=", "_context$copyPlugin", ".", "patterns", ",", "options", "=", "_context$copyPlugin", ".", "options", "var", "plugin", "=", "new", "_copyWebpackPlugin2", ".", "default", "(", "patterns", ",", "options", ")", "return", "merge", "(", "{", "plugins", ":", "[", "plugin", "]", "}", ")", "}", "}" ]
Instantiate the copy plugin.
[ "Instantiate", "the", "copy", "plugin", "." ]
3bd12137a35a9237a9bdc6c4443e5ed29bfc8812
https://github.com/ecliptic/webpack-blocks-copy/blob/3bd12137a35a9237a9bdc6c4443e5ed29bfc8812/lib/index.js#L104-L115
51,291
MORPOL/createClass
createclass.js
function( mElement, aArray ) { for( var i=0; i<aArray.length; i++ ) if( aArray[i]==mElement ) return i; return -1; }
javascript
function( mElement, aArray ) { for( var i=0; i<aArray.length; i++ ) if( aArray[i]==mElement ) return i; return -1; }
[ "function", "(", "mElement", ",", "aArray", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "aArray", ".", "length", ";", "i", "++", ")", "if", "(", "aArray", "[", "i", "]", "==", "mElement", ")", "return", "i", ";", "return", "-", "1", ";", "}" ]
Check whether or not the given element exists in the given array @param mElement The element to be searched for (double equal comparison) @param aArray The array to be searched @return The index of the element within the array or -1 if it wasn't found
[ "Check", "whether", "or", "not", "the", "given", "element", "exists", "in", "the", "given", "array" ]
3e839121357fd25ff1b20fcd4ca02062f1192583
https://github.com/MORPOL/createClass/blob/3e839121357fd25ff1b20fcd4ca02062f1192583/createclass.js#L57-L63
51,292
MORPOL/createClass
createclass.js
function() { var v = []; for( var i in this ) if( typeof this[i]=="function" && this[i].__virtual ) v.push( i ); if( v.length ) createClass.log( 'error', 'INCOMPLETE CLASS '+this.__className+' HAS AT LEAST ONE PURE VIRTUAL FUNCTION: '+v.join(", ") ); }
javascript
function() { var v = []; for( var i in this ) if( typeof this[i]=="function" && this[i].__virtual ) v.push( i ); if( v.length ) createClass.log( 'error', 'INCOMPLETE CLASS '+this.__className+' HAS AT LEAST ONE PURE VIRTUAL FUNCTION: '+v.join(", ") ); }
[ "function", "(", ")", "{", "var", "v", "=", "[", "]", ";", "for", "(", "var", "i", "in", "this", ")", "if", "(", "typeof", "this", "[", "i", "]", "==", "\"function\"", "&&", "this", "[", "i", "]", ".", "__virtual", ")", "v", ".", "push", "(", "i", ")", ";", "if", "(", "v", ".", "length", ")", "createClass", ".", "log", "(", "'error'", ",", "'INCOMPLETE CLASS '", "+", "this", ".", "__className", "+", "' HAS AT LEAST ONE PURE VIRTUAL FUNCTION: '", "+", "v", ".", "join", "(", "\", \"", ")", ")", ";", "}" ]
Check for virtual errors, i.e. functions that should have been overridden, but weren't
[ "Check", "for", "virtual", "errors", "i", ".", "e", ".", "functions", "that", "should", "have", "been", "overridden", "but", "weren", "t" ]
3e839121357fd25ff1b20fcd4ca02062f1192583
https://github.com/MORPOL/createClass/blob/3e839121357fd25ff1b20fcd4ca02062f1192583/createclass.js#L291-L299
51,293
tjmehta/string-reduce
index.js
stringReduce
function stringReduce (string, reducerCallback, initialValue) { if (string.length === 0) { assertErr(initialValue, TypeError, 'Reduce of empty string with no initial value') return initialValue } var initialValuePassed = arguments.length === 3 var result var startIndex if (initialValuePassed) { // initial value, initialize reduce state result = initialValue startIndex = 0 } else { // no initial value if (string.length === 1) { return string.charAt(0) } // no initial value, initialize reduce state result = string.charAt(0) startIndex = 1 } for (var i = startIndex; i < string.length; i++) { result = reducerCallback(result, string.charAt(i), i, string) } return result }
javascript
function stringReduce (string, reducerCallback, initialValue) { if (string.length === 0) { assertErr(initialValue, TypeError, 'Reduce of empty string with no initial value') return initialValue } var initialValuePassed = arguments.length === 3 var result var startIndex if (initialValuePassed) { // initial value, initialize reduce state result = initialValue startIndex = 0 } else { // no initial value if (string.length === 1) { return string.charAt(0) } // no initial value, initialize reduce state result = string.charAt(0) startIndex = 1 } for (var i = startIndex; i < string.length; i++) { result = reducerCallback(result, string.charAt(i), i, string) } return result }
[ "function", "stringReduce", "(", "string", ",", "reducerCallback", ",", "initialValue", ")", "{", "if", "(", "string", ".", "length", "===", "0", ")", "{", "assertErr", "(", "initialValue", ",", "TypeError", ",", "'Reduce of empty string with no initial value'", ")", "return", "initialValue", "}", "var", "initialValuePassed", "=", "arguments", ".", "length", "===", "3", "var", "result", "var", "startIndex", "if", "(", "initialValuePassed", ")", "{", "// initial value, initialize reduce state", "result", "=", "initialValue", "startIndex", "=", "0", "}", "else", "{", "// no initial value", "if", "(", "string", ".", "length", "===", "1", ")", "{", "return", "string", ".", "charAt", "(", "0", ")", "}", "// no initial value, initialize reduce state", "result", "=", "string", ".", "charAt", "(", "0", ")", "startIndex", "=", "1", "}", "for", "(", "var", "i", "=", "startIndex", ";", "i", "<", "string", ".", "length", ";", "i", "++", ")", "{", "result", "=", "reducerCallback", "(", "result", ",", "string", ".", "charAt", "(", "i", ")", ",", "i", ",", "string", ")", "}", "return", "result", "}" ]
reduce a string to a value @param {string} string string to reduce @param {function} reducerCb reducer function @param {*} initialValue reduce initial value @return {*} result
[ "reduce", "a", "string", "to", "a", "value" ]
ff3e69a3b68115c793aa2d43f2ab3376688527a2
https://github.com/tjmehta/string-reduce/blob/ff3e69a3b68115c793aa2d43f2ab3376688527a2/index.js#L12-L37
51,294
nknapp/deep-aplus
index.js
handleAny
function handleAny (obj) { if (isPromiseAlike(obj)) { return obj.then(handleAny) } else if (isPlainObject(obj)) { return handleObject(obj) } else if (Object.prototype.toString.call(obj) === '[object Array]') { return handleArray(obj) } else { return new Promise(function (resolve, reject) { return resolve(obj) }) } }
javascript
function handleAny (obj) { if (isPromiseAlike(obj)) { return obj.then(handleAny) } else if (isPlainObject(obj)) { return handleObject(obj) } else if (Object.prototype.toString.call(obj) === '[object Array]') { return handleArray(obj) } else { return new Promise(function (resolve, reject) { return resolve(obj) }) } }
[ "function", "handleAny", "(", "obj", ")", "{", "if", "(", "isPromiseAlike", "(", "obj", ")", ")", "{", "return", "obj", ".", "then", "(", "handleAny", ")", "}", "else", "if", "(", "isPlainObject", "(", "obj", ")", ")", "{", "return", "handleObject", "(", "obj", ")", "}", "else", "if", "(", "Object", ".", "prototype", ".", "toString", ".", "call", "(", "obj", ")", "===", "'[object Array]'", ")", "{", "return", "handleArray", "(", "obj", ")", "}", "else", "{", "return", "new", "Promise", "(", "function", "(", "resolve", ",", "reject", ")", "{", "return", "resolve", "(", "obj", ")", "}", ")", "}", "}" ]
Return a promise for an object, array, or other value, with all internal promises resolved. @param {*} obj @returns {Promise<*>} @private
[ "Return", "a", "promise", "for", "an", "object", "array", "or", "other", "value", "with", "all", "internal", "promises", "resolved", "." ]
da8c5432e895c5087dc1f1a2234be4273ab0592c
https://github.com/nknapp/deep-aplus/blob/da8c5432e895c5087dc1f1a2234be4273ab0592c/index.js#L78-L90
51,295
redisjs/jsr-server
lib/command/database/key/dump.js
execute
function execute(req, res) { var value = req.db.getKey(req.args[0], req); if(value === undefined) return res.send(null, null); var buf = dump( {value: value}, value.rtype || Constants.TYPE_NAMES.STRING, null); res.send(null, buf); }
javascript
function execute(req, res) { var value = req.db.getKey(req.args[0], req); if(value === undefined) return res.send(null, null); var buf = dump( {value: value}, value.rtype || Constants.TYPE_NAMES.STRING, null); res.send(null, buf); }
[ "function", "execute", "(", "req", ",", "res", ")", "{", "var", "value", "=", "req", ".", "db", ".", "getKey", "(", "req", ".", "args", "[", "0", "]", ",", "req", ")", ";", "if", "(", "value", "===", "undefined", ")", "return", "res", ".", "send", "(", "null", ",", "null", ")", ";", "var", "buf", "=", "dump", "(", "{", "value", ":", "value", "}", ",", "value", ".", "rtype", "||", "Constants", ".", "TYPE_NAMES", ".", "STRING", ",", "null", ")", ";", "res", ".", "send", "(", "null", ",", "buf", ")", ";", "}" ]
Respond to the DUMP command.
[ "Respond", "to", "the", "DUMP", "command", "." ]
49413052d3039524fbdd2ade0ef9bae26cb4d647
https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/database/key/dump.js#L18-L24
51,296
rendrjs/grunt-rendr-stitch
tasks/rendr_stitch.js
assertFiles
function assertFiles(expectedNumFiles, tmpDir, callback) { function countFiles() { var numFiles = 0; grunt.file.recurse(tmpDir, function(abspath, rootdir, subdir, filename) { numFiles++; }); return numFiles === expectedNumFiles; } var interval = setInterval(function() { if (countFiles()) { clearInterval(interval); callback(); } }, 100); }
javascript
function assertFiles(expectedNumFiles, tmpDir, callback) { function countFiles() { var numFiles = 0; grunt.file.recurse(tmpDir, function(abspath, rootdir, subdir, filename) { numFiles++; }); return numFiles === expectedNumFiles; } var interval = setInterval(function() { if (countFiles()) { clearInterval(interval); callback(); } }, 100); }
[ "function", "assertFiles", "(", "expectedNumFiles", ",", "tmpDir", ",", "callback", ")", "{", "function", "countFiles", "(", ")", "{", "var", "numFiles", "=", "0", ";", "grunt", ".", "file", ".", "recurse", "(", "tmpDir", ",", "function", "(", "abspath", ",", "rootdir", ",", "subdir", ",", "filename", ")", "{", "numFiles", "++", ";", "}", ")", ";", "return", "numFiles", "===", "expectedNumFiles", ";", "}", "var", "interval", "=", "setInterval", "(", "function", "(", ")", "{", "if", "(", "countFiles", "(", ")", ")", "{", "clearInterval", "(", "interval", ")", ";", "callback", "(", ")", ";", "}", "}", ",", "100", ")", ";", "}" ]
Sometimes, the Stitch compliation appears to happen before all files are copied over to the `tmpDir`. We simply wait until they are.
[ "Sometimes", "the", "Stitch", "compliation", "appears", "to", "happen", "before", "all", "files", "are", "copied", "over", "to", "the", "tmpDir", ".", "We", "simply", "wait", "until", "they", "are", "." ]
de05755007d4af4817c7f4b46c31e4d96c42aee1
https://github.com/rendrjs/grunt-rendr-stitch/blob/de05755007d4af4817c7f4b46c31e4d96c42aee1/tasks/rendr_stitch.js#L117-L132
51,297
AndreasMadsen/thintalk
lib/layers/TCP.js
jsonStream
function jsonStream(target, socket) { // first set the channel encodeing to utf8 socket.setEncoding('utf8'); // data chunks may not contain a complete json string, thats why we store the data var jsonBuffer = ''; // emits when new data from TCP connection is received socket.on('data', function (chunk) { // first add the chunk to the json buffer jsonBuffer += chunk; var start = 0, i; // next find the next line end char while ((i = jsonBuffer.indexOf('\n', start)) >= 0) { // if one was found copy it out of the jsonBuffer string var json = jsonBuffer.slice(start, i); // now that we have a complete json string // emit message with a parsed json object target.emit('message', JSON.parse(json)); // set the starting point of next line end search start = i + 1; } // when no more complete json objects exist in the jsonBuffer, // we will slice the jsonBuffer so it only contains the uncomplete json string jsonBuffer = jsonBuffer.slice(start); }); }
javascript
function jsonStream(target, socket) { // first set the channel encodeing to utf8 socket.setEncoding('utf8'); // data chunks may not contain a complete json string, thats why we store the data var jsonBuffer = ''; // emits when new data from TCP connection is received socket.on('data', function (chunk) { // first add the chunk to the json buffer jsonBuffer += chunk; var start = 0, i; // next find the next line end char while ((i = jsonBuffer.indexOf('\n', start)) >= 0) { // if one was found copy it out of the jsonBuffer string var json = jsonBuffer.slice(start, i); // now that we have a complete json string // emit message with a parsed json object target.emit('message', JSON.parse(json)); // set the starting point of next line end search start = i + 1; } // when no more complete json objects exist in the jsonBuffer, // we will slice the jsonBuffer so it only contains the uncomplete json string jsonBuffer = jsonBuffer.slice(start); }); }
[ "function", "jsonStream", "(", "target", ",", "socket", ")", "{", "// first set the channel encodeing to utf8", "socket", ".", "setEncoding", "(", "'utf8'", ")", ";", "// data chunks may not contain a complete json string, thats why we store the data", "var", "jsonBuffer", "=", "''", ";", "// emits when new data from TCP connection is received", "socket", ".", "on", "(", "'data'", ",", "function", "(", "chunk", ")", "{", "// first add the chunk to the json buffer", "jsonBuffer", "+=", "chunk", ";", "var", "start", "=", "0", ",", "i", ";", "// next find the next line end char", "while", "(", "(", "i", "=", "jsonBuffer", ".", "indexOf", "(", "'\\n'", ",", "start", ")", ")", ">=", "0", ")", "{", "// if one was found copy it out of the jsonBuffer string", "var", "json", "=", "jsonBuffer", ".", "slice", "(", "start", ",", "i", ")", ";", "// now that we have a complete json string", "// emit message with a parsed json object", "target", ".", "emit", "(", "'message'", ",", "JSON", ".", "parse", "(", "json", ")", ")", ";", "// set the starting point of next line end search", "start", "=", "i", "+", "1", ";", "}", "// when no more complete json objects exist in the jsonBuffer,", "// we will slice the jsonBuffer so it only contains the uncomplete json string", "jsonBuffer", "=", "jsonBuffer", ".", "slice", "(", "start", ")", ";", "}", ")", ";", "}" ]
Since data from a socket comes in buffer streams in an unknown length this helper store the data until a complete json object has been received when a json object is received it will emit the message event on target. JSON strings will be isolated by a newline sign.
[ "Since", "data", "from", "a", "socket", "comes", "in", "buffer", "streams", "in", "an", "unknown", "length", "this", "helper", "store", "the", "data", "until", "a", "complete", "json", "object", "has", "been", "received", "when", "a", "json", "object", "is", "received", "it", "will", "emit", "the", "message", "event", "on", "target", ".", "JSON", "strings", "will", "be", "isolated", "by", "a", "newline", "sign", "." ]
1ea0c2703d303874fc50d8efb2013ee4d7dadeb1
https://github.com/AndreasMadsen/thintalk/blob/1ea0c2703d303874fc50d8efb2013ee4d7dadeb1/lib/layers/TCP.js#L21-L53
51,298
congajs/conga-twig
lib/tags/twig.tag.assets.js
function (token, context, chain) { var i , len , files = [] , output = '' , viewData = Object.create(context) , env = container.getParameter('kernel.environment') , data = container.get('assets.template.helper.assets') .assets(token.files[0], token.files[1], token.files[2], false); if (env === 'development') { // dev environments print all of the files one-by-one data.files.forEach(function(file) { files.push(file + '?' + data.versionParameter + '=' + data.version); }); } else { // prod or test print the combined file only files = [data.combinedFile]; } // render the output one file at a time, respectively injecting URL into each for (i = 0, len = files.length; i < len; i++) { viewData.url = files[i]; output += Twig.parse.apply(this, [token.output, viewData]); } return { chain: chain, output: output }; }
javascript
function (token, context, chain) { var i , len , files = [] , output = '' , viewData = Object.create(context) , env = container.getParameter('kernel.environment') , data = container.get('assets.template.helper.assets') .assets(token.files[0], token.files[1], token.files[2], false); if (env === 'development') { // dev environments print all of the files one-by-one data.files.forEach(function(file) { files.push(file + '?' + data.versionParameter + '=' + data.version); }); } else { // prod or test print the combined file only files = [data.combinedFile]; } // render the output one file at a time, respectively injecting URL into each for (i = 0, len = files.length; i < len; i++) { viewData.url = files[i]; output += Twig.parse.apply(this, [token.output, viewData]); } return { chain: chain, output: output }; }
[ "function", "(", "token", ",", "context", ",", "chain", ")", "{", "var", "i", ",", "len", ",", "files", "=", "[", "]", ",", "output", "=", "''", ",", "viewData", "=", "Object", ".", "create", "(", "context", ")", ",", "env", "=", "container", ".", "getParameter", "(", "'kernel.environment'", ")", ",", "data", "=", "container", ".", "get", "(", "'assets.template.helper.assets'", ")", ".", "assets", "(", "token", ".", "files", "[", "0", "]", ",", "token", ".", "files", "[", "1", "]", ",", "token", ".", "files", "[", "2", "]", ",", "false", ")", ";", "if", "(", "env", "===", "'development'", ")", "{", "// dev environments print all of the files one-by-one", "data", ".", "files", ".", "forEach", "(", "function", "(", "file", ")", "{", "files", ".", "push", "(", "file", "+", "'?'", "+", "data", ".", "versionParameter", "+", "'='", "+", "data", ".", "version", ")", ";", "}", ")", ";", "}", "else", "{", "// prod or test print the combined file only", "files", "=", "[", "data", ".", "combinedFile", "]", ";", "}", "// render the output one file at a time, respectively injecting URL into each", "for", "(", "i", "=", "0", ",", "len", "=", "files", ".", "length", ";", "i", "<", "len", ";", "i", "++", ")", "{", "viewData", ".", "url", "=", "files", "[", "i", "]", ";", "output", "+=", "Twig", ".", "parse", ".", "apply", "(", "this", ",", "[", "token", ".", "output", ",", "viewData", "]", ")", ";", "}", "return", "{", "chain", ":", "chain", ",", "output", ":", "output", "}", ";", "}" ]
Runs when the template is rendered
[ "Runs", "when", "the", "template", "is", "rendered" ]
a3d60fccb655fcf5afa91f254632c48675bebda5
https://github.com/congajs/conga-twig/blob/a3d60fccb655fcf5afa91f254632c48675bebda5/lib/tags/twig.tag.assets.js#L85-L120
51,299
jaredhanson/jsmt
lib/module.js
Module
function Module(id, parent) { this.id = id this.parent = parent; if (parent && parent.children) { parent.children.push(this); } this.children = []; this.filename = null; this.format = undefined; this.loaded = false; }
javascript
function Module(id, parent) { this.id = id this.parent = parent; if (parent && parent.children) { parent.children.push(this); } this.children = []; this.filename = null; this.format = undefined; this.loaded = false; }
[ "function", "Module", "(", "id", ",", "parent", ")", "{", "this", ".", "id", "=", "id", "this", ".", "parent", "=", "parent", ";", "if", "(", "parent", "&&", "parent", ".", "children", ")", "{", "parent", ".", "children", ".", "push", "(", "this", ")", ";", "}", "this", ".", "children", "=", "[", "]", ";", "this", ".", "filename", "=", "null", ";", "this", ".", "format", "=", "undefined", ";", "this", ".", "loaded", "=", "false", ";", "}" ]
`Module` constructor. Constructs a new module with the given `id` and `parent`. If `parent` is not null, the created module will be added as a child of `parent`. @param {String} id @param {Module} parent @api public
[ "Module", "constructor", "." ]
13962176250ef41931d8f7e2290d630bd492e4af
https://github.com/jaredhanson/jsmt/blob/13962176250ef41931d8f7e2290d630bd492e4af/lib/module.js#L25-L36