id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
21,000
nodejitsu/jitsu
lib/jitsu/commands/users.js
setupUserNoUsername
function setupUserNoUsername(callback) { // // Attempt to get the password three times. // var tries = 0; function offerReset (username) { jitsu.prompt.get(['reset'], function (err, res) { if (err) { return callback(err); } if (/^y[es]+/i.test(res['request password reset'])) { return jitsu.plugins.cli.executeCommand(['users', 'forgot', username ], callback); } callback(new Error('Invalid username / password.')); }); } (function setupAuth () { jitsu.prompt.get(['password'], function (err, result) { if (err) { return callback(err); } jitsu.config.set('username', username); jitsu.config.set('password', result.password); jitsu.setup(function () { jitsu.auth(function (err) { // // Increment the auth attempts // tries += 1; if (err) { if (tries >= 3) { jitsu.log.error('Three failed login attempts'); jitsu.log.info('Reset the password?'); return offerReset(username); } return setupAuth(); } // once password is entered checkout a token and clear out password jitsu.tokens.create(username, (jitsu.config.get('apiTokenName')||'jitsu'), function(err, result) { if(!err && result) { var token = Object.getOwnPropertyNames(result).filter(function(n){return n !== 'operation'}).pop(); jitsu.config.set('apiToken', result[token]); jitsu.config.set('apiTokenName', token); jitsu.config.clear('password'); jitsu.config.save(function (err) { return err ? callback(err) : callback(); }); } }); }); }); }); })(); }
javascript
function setupUserNoUsername(callback) { // // Attempt to get the password three times. // var tries = 0; function offerReset (username) { jitsu.prompt.get(['reset'], function (err, res) { if (err) { return callback(err); } if (/^y[es]+/i.test(res['request password reset'])) { return jitsu.plugins.cli.executeCommand(['users', 'forgot', username ], callback); } callback(new Error('Invalid username / password.')); }); } (function setupAuth () { jitsu.prompt.get(['password'], function (err, result) { if (err) { return callback(err); } jitsu.config.set('username', username); jitsu.config.set('password', result.password); jitsu.setup(function () { jitsu.auth(function (err) { // // Increment the auth attempts // tries += 1; if (err) { if (tries >= 3) { jitsu.log.error('Three failed login attempts'); jitsu.log.info('Reset the password?'); return offerReset(username); } return setupAuth(); } // once password is entered checkout a token and clear out password jitsu.tokens.create(username, (jitsu.config.get('apiTokenName')||'jitsu'), function(err, result) { if(!err && result) { var token = Object.getOwnPropertyNames(result).filter(function(n){return n !== 'operation'}).pop(); jitsu.config.set('apiToken', result[token]); jitsu.config.set('apiTokenName', token); jitsu.config.clear('password'); jitsu.config.save(function (err) { return err ? callback(err) : callback(); }); } }); }); }); }); })(); }
[ "function", "setupUserNoUsername", "(", "callback", ")", "{", "//", "// Attempt to get the password three times.", "//", "var", "tries", "=", "0", ";", "function", "offerReset", "(", "username", ")", "{", "jitsu", ".", "prompt", ".", "get", "(", "[", "'reset'", "]", ",", "function", "(", "err", ",", "res", ")", "{", "if", "(", "err", ")", "{", "return", "callback", "(", "err", ")", ";", "}", "if", "(", "/", "^y[es]+", "/", "i", ".", "test", "(", "res", "[", "'request password reset'", "]", ")", ")", "{", "return", "jitsu", ".", "plugins", ".", "cli", ".", "executeCommand", "(", "[", "'users'", ",", "'forgot'", ",", "username", "]", ",", "callback", ")", ";", "}", "callback", "(", "new", "Error", "(", "'Invalid username / password.'", ")", ")", ";", "}", ")", ";", "}", "(", "function", "setupAuth", "(", ")", "{", "jitsu", ".", "prompt", ".", "get", "(", "[", "'password'", "]", ",", "function", "(", "err", ",", "result", ")", "{", "if", "(", "err", ")", "{", "return", "callback", "(", "err", ")", ";", "}", "jitsu", ".", "config", ".", "set", "(", "'username'", ",", "username", ")", ";", "jitsu", ".", "config", ".", "set", "(", "'password'", ",", "result", ".", "password", ")", ";", "jitsu", ".", "setup", "(", "function", "(", ")", "{", "jitsu", ".", "auth", "(", "function", "(", "err", ")", "{", "//", "// Increment the auth attempts", "//", "tries", "+=", "1", ";", "if", "(", "err", ")", "{", "if", "(", "tries", ">=", "3", ")", "{", "jitsu", ".", "log", ".", "error", "(", "'Three failed login attempts'", ")", ";", "jitsu", ".", "log", ".", "info", "(", "'Reset the password?'", ")", ";", "return", "offerReset", "(", "username", ")", ";", "}", "return", "setupAuth", "(", ")", ";", "}", "// once password is entered checkout a token and clear out password ", "jitsu", ".", "tokens", ".", "create", "(", "username", ",", "(", "jitsu", ".", "config", ".", "get", "(", "'apiTokenName'", ")", "||", "'jitsu'", ")", ",", "function", "(", "err", ",", "result", ")", "{", "if", "(", "!", "err", "&&", "result", ")", "{", "var", "token", "=", "Object", ".", "getOwnPropertyNames", "(", "result", ")", ".", "filter", "(", "function", "(", "n", ")", "{", "return", "n", "!==", "'operation'", "}", ")", ".", "pop", "(", ")", ";", "jitsu", ".", "config", ".", "set", "(", "'apiToken'", ",", "result", "[", "token", "]", ")", ";", "jitsu", ".", "config", ".", "set", "(", "'apiTokenName'", ",", "token", ")", ";", "jitsu", ".", "config", ".", "clear", "(", "'password'", ")", ";", "jitsu", ".", "config", ".", "save", "(", "function", "(", "err", ")", "{", "return", "err", "?", "callback", "(", "err", ")", ":", "callback", "(", ")", ";", "}", ")", ";", "}", "}", ")", ";", "}", ")", ";", "}", ")", ";", "}", ")", ";", "}", ")", "(", ")", ";", "}" ]
This is like setupUserNoWarn except that it only asks for your password.
[ "This", "is", "like", "setupUserNoWarn", "except", "that", "it", "only", "asks", "for", "your", "password", "." ]
b4a40605cb5b888ff13fc0b0f1cfa252ad0dd917
https://github.com/nodejitsu/jitsu/blob/b4a40605cb5b888ff13fc0b0f1cfa252ad0dd917/lib/jitsu/commands/users.js#L33-L91
21,001
nodejitsu/jitsu
lib/jitsu/commands/databases.js
createDatabase
function createDatabase(database, callback) { database.type = databases.alias(database.type); // // Make sure that the user is passing in a valid database type // if (databases.available.indexOf(database.type) === -1) { jitsu.log.warn('Invalid database type ' + database.type.red); database.type = null; return promptForDatabase(callback); } jitsu.databases.create(database.type, database.name, function (err, a, res) { if (err || res.statusCode >= 400) { // // TODO: Refactor this error handling // if (err && (err.statusCode === 409 || err.statusCode === 404)) { jitsu.log.error('Database with name ' + database.name.magenta + ' already exists'); jitsu.log.info('Try again with a new database name'); database.name = null; return promptForDatabase(callback); } else { jitsu.log.error('Database could not be created'); jitsu.log.error(err || ('Unknown error code: ' + res.statusCode)); jitsu.log.error('Try again and if it still fails, please contact nodejitsu'); return callback(err); } } else { jitsu.log.info('A new ' + database.type.magenta + ' has been created'); } databases.get(database.name, callback); }); }
javascript
function createDatabase(database, callback) { database.type = databases.alias(database.type); // // Make sure that the user is passing in a valid database type // if (databases.available.indexOf(database.type) === -1) { jitsu.log.warn('Invalid database type ' + database.type.red); database.type = null; return promptForDatabase(callback); } jitsu.databases.create(database.type, database.name, function (err, a, res) { if (err || res.statusCode >= 400) { // // TODO: Refactor this error handling // if (err && (err.statusCode === 409 || err.statusCode === 404)) { jitsu.log.error('Database with name ' + database.name.magenta + ' already exists'); jitsu.log.info('Try again with a new database name'); database.name = null; return promptForDatabase(callback); } else { jitsu.log.error('Database could not be created'); jitsu.log.error(err || ('Unknown error code: ' + res.statusCode)); jitsu.log.error('Try again and if it still fails, please contact nodejitsu'); return callback(err); } } else { jitsu.log.info('A new ' + database.type.magenta + ' has been created'); } databases.get(database.name, callback); }); }
[ "function", "createDatabase", "(", "database", ",", "callback", ")", "{", "database", ".", "type", "=", "databases", ".", "alias", "(", "database", ".", "type", ")", ";", "//", "// Make sure that the user is passing in a valid database type", "//", "if", "(", "databases", ".", "available", ".", "indexOf", "(", "database", ".", "type", ")", "===", "-", "1", ")", "{", "jitsu", ".", "log", ".", "warn", "(", "'Invalid database type '", "+", "database", ".", "type", ".", "red", ")", ";", "database", ".", "type", "=", "null", ";", "return", "promptForDatabase", "(", "callback", ")", ";", "}", "jitsu", ".", "databases", ".", "create", "(", "database", ".", "type", ",", "database", ".", "name", ",", "function", "(", "err", ",", "a", ",", "res", ")", "{", "if", "(", "err", "||", "res", ".", "statusCode", ">=", "400", ")", "{", "//", "// TODO: Refactor this error handling", "//", "if", "(", "err", "&&", "(", "err", ".", "statusCode", "===", "409", "||", "err", ".", "statusCode", "===", "404", ")", ")", "{", "jitsu", ".", "log", ".", "error", "(", "'Database with name '", "+", "database", ".", "name", ".", "magenta", "+", "' already exists'", ")", ";", "jitsu", ".", "log", ".", "info", "(", "'Try again with a new database name'", ")", ";", "database", ".", "name", "=", "null", ";", "return", "promptForDatabase", "(", "callback", ")", ";", "}", "else", "{", "jitsu", ".", "log", ".", "error", "(", "'Database could not be created'", ")", ";", "jitsu", ".", "log", ".", "error", "(", "err", "||", "(", "'Unknown error code: '", "+", "res", ".", "statusCode", ")", ")", ";", "jitsu", ".", "log", ".", "error", "(", "'Try again and if it still fails, please contact nodejitsu'", ")", ";", "return", "callback", "(", "err", ")", ";", "}", "}", "else", "{", "jitsu", ".", "log", ".", "info", "(", "'A new '", "+", "database", ".", "type", ".", "magenta", "+", "' has been created'", ")", ";", "}", "databases", ".", "get", "(", "database", ".", "name", ",", "callback", ")", ";", "}", ")", ";", "}" ]
Helper function to execute the database creation.
[ "Helper", "function", "to", "execute", "the", "database", "creation", "." ]
b4a40605cb5b888ff13fc0b0f1cfa252ad0dd917
https://github.com/nodejitsu/jitsu/blob/b4a40605cb5b888ff13fc0b0f1cfa252ad0dd917/lib/jitsu/commands/databases.js#L78-L115
21,002
nodejitsu/jitsu
lib/jitsu/package.js
isValid
function isValid(desc) { if (desc.validator) { if (desc.validator instanceof RegExp) { return !desc.validator.test(value); } return !desc.validator(value); } return false; }
javascript
function isValid(desc) { if (desc.validator) { if (desc.validator instanceof RegExp) { return !desc.validator.test(value); } return !desc.validator(value); } return false; }
[ "function", "isValid", "(", "desc", ")", "{", "if", "(", "desc", ".", "validator", ")", "{", "if", "(", "desc", ".", "validator", "instanceof", "RegExp", ")", "{", "return", "!", "desc", ".", "validator", ".", "test", "(", "value", ")", ";", "}", "return", "!", "desc", ".", "validator", "(", "value", ")", ";", "}", "return", "false", ";", "}" ]
handle invalid values
[ "handle", "invalid", "values" ]
b4a40605cb5b888ff13fc0b0f1cfa252ad0dd917
https://github.com/nodejitsu/jitsu/blob/b4a40605cb5b888ff13fc0b0f1cfa252ad0dd917/lib/jitsu/package.js#L179-L188
21,003
ciaranj/connect-auth
spec/lib/jspec.growl.js
function(cmd) { var lines = [], line with (JavaImporter(java.lang, java.io)) { var proccess = Runtime.getRuntime().exec(Array.prototype.slice.call(arguments)) var stream = new DataInputStream(proccess.getInputStream()) while (line = stream.readLine()) lines.push(line + '') stream.close() } return lines }
javascript
function(cmd) { var lines = [], line with (JavaImporter(java.lang, java.io)) { var proccess = Runtime.getRuntime().exec(Array.prototype.slice.call(arguments)) var stream = new DataInputStream(proccess.getInputStream()) while (line = stream.readLine()) lines.push(line + '') stream.close() } return lines }
[ "function", "(", "cmd", ")", "{", "var", "lines", "=", "[", "]", ",", "line", "with", "(", "JavaImporter", "(", "java", ".", "lang", ",", "java", ".", "io", ")", ")", "{", "var", "proccess", "=", "Runtime", ".", "getRuntime", "(", ")", ".", "exec", "(", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ")", ")", "var", "stream", "=", "new", "DataInputStream", "(", "proccess", ".", "getInputStream", "(", ")", ")", "while", "(", "line", "=", "stream", ".", "readLine", "(", ")", ")", "lines", ".", "push", "(", "line", "+", "''", ")", "stream", ".", "close", "(", ")", "}", "return", "lines", "}" ]
Execute the given _cmd_, returning an array of lines from stdout. Examples: Growl.exec('growlnotify', '-m', msg) @param {string ...} cmd @return {array} @api public
[ "Execute", "the", "given", "_cmd_", "returning", "an", "array", "of", "lines", "from", "stdout", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.growl.js#L24-L34
21,004
ciaranj/connect-auth
spec/lib/jspec.growl.js
function(path) { return path.lastIndexOf('.') != -1 ? path.slice(path.lastIndexOf('.') + 1, path.length) : null }
javascript
function(path) { return path.lastIndexOf('.') != -1 ? path.slice(path.lastIndexOf('.') + 1, path.length) : null }
[ "function", "(", "path", ")", "{", "return", "path", ".", "lastIndexOf", "(", "'.'", ")", "!=", "-", "1", "?", "path", ".", "slice", "(", "path", ".", "lastIndexOf", "(", "'.'", ")", "+", "1", ",", "path", ".", "length", ")", ":", "null", "}" ]
Return the extension of the given _path_ or null. @param {string} path @return {string} @api private
[ "Return", "the", "extension", "of", "the", "given", "_path_", "or", "null", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.growl.js#L44-L48
21,005
ciaranj/connect-auth
spec/lib/jspec.growl.js
function(msg, options) { options = options || {} var args = ['growlnotify', '-m', msg] if (!this.binVersion()) throw new Error('growlnotify executable is required') if (image = options.image) { var flag, ext = this.extname(image) flag = flag || ext == 'icns' && 'iconpath' flag = flag || /^[A-Z]/.test(image) && 'appIcon' flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image' flag = flag || ext && (image = ext) && 'icon' flag = flag || 'icon' args.push('--' + flag, image) } if (options.sticky) args.push('--sticky') if (options.name) args.push('--name', options.name) if (options.title) args.push(options.title) this.exec.apply(this, args) }
javascript
function(msg, options) { options = options || {} var args = ['growlnotify', '-m', msg] if (!this.binVersion()) throw new Error('growlnotify executable is required') if (image = options.image) { var flag, ext = this.extname(image) flag = flag || ext == 'icns' && 'iconpath' flag = flag || /^[A-Z]/.test(image) && 'appIcon' flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image' flag = flag || ext && (image = ext) && 'icon' flag = flag || 'icon' args.push('--' + flag, image) } if (options.sticky) args.push('--sticky') if (options.name) args.push('--name', options.name) if (options.title) args.push(options.title) this.exec.apply(this, args) }
[ "function", "(", "msg", ",", "options", ")", "{", "options", "=", "options", "||", "{", "}", "var", "args", "=", "[", "'growlnotify'", ",", "'-m'", ",", "msg", "]", "if", "(", "!", "this", ".", "binVersion", "(", ")", ")", "throw", "new", "Error", "(", "'growlnotify executable is required'", ")", "if", "(", "image", "=", "options", ".", "image", ")", "{", "var", "flag", ",", "ext", "=", "this", ".", "extname", "(", "image", ")", "flag", "=", "flag", "||", "ext", "==", "'icns'", "&&", "'iconpath'", "flag", "=", "flag", "||", "/", "^[A-Z]", "/", ".", "test", "(", "image", ")", "&&", "'appIcon'", "flag", "=", "flag", "||", "/", "^png|gif|jpe?g$", "/", ".", "test", "(", "ext", ")", "&&", "'image'", "flag", "=", "flag", "||", "ext", "&&", "(", "image", "=", "ext", ")", "&&", "'icon'", "flag", "=", "flag", "||", "'icon'", "args", ".", "push", "(", "'--'", "+", "flag", ",", "image", ")", "}", "if", "(", "options", ".", "sticky", ")", "args", ".", "push", "(", "'--sticky'", ")", "if", "(", "options", ".", "name", ")", "args", ".", "push", "(", "'--name'", ",", "options", ".", "name", ")", "if", "(", "options", ".", "title", ")", "args", ".", "push", "(", "options", ".", "title", ")", "this", ".", "exec", ".", "apply", "(", "this", ",", "args", ")", "}" ]
Send growl notification _msg_ with _options_. Options: - title Notification title - sticky Make the notification stick (defaults to false) - name Application name (defaults to growlnotify) - image - path to an icon sets --iconpath - path to an image sets --image - capitalized word sets --appIcon - filename uses extname as --icon - otherwise treated as --icon Examples: Growl.notify('New email') Growl.notify('5 new emails', { title: 'Thunderbird' }) @param {string} msg @param {options} hash @api public
[ "Send", "growl", "notification", "_msg_", "with", "_options_", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.growl.js#L86-L103
21,006
ciaranj/connect-auth
spec/lib/jspec.shell.js
function() { for (var name in this.commands) if (this.commands.hasOwnProperty(name)) this.commands[name][1].length ? this.main[name] = this.commands[name][1] : this.main.__defineGetter__(name, this.commands[name][1]) }
javascript
function() { for (var name in this.commands) if (this.commands.hasOwnProperty(name)) this.commands[name][1].length ? this.main[name] = this.commands[name][1] : this.main.__defineGetter__(name, this.commands[name][1]) }
[ "function", "(", ")", "{", "for", "(", "var", "name", "in", "this", ".", "commands", ")", "if", "(", "this", ".", "commands", ".", "hasOwnProperty", "(", "name", ")", ")", "this", ".", "commands", "[", "name", "]", "[", "1", "]", ".", "length", "?", "this", ".", "main", "[", "name", "]", "=", "this", ".", "commands", "[", "name", "]", "[", "1", "]", ":", "this", ".", "main", ".", "__defineGetter__", "(", "name", ",", "this", ".", "commands", "[", "name", "]", "[", "1", "]", ")", "}" ]
Start the interactive shell. @api public
[ "Start", "the", "interactive", "shell", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.shell.js#L28-L34
21,007
ciaranj/connect-auth
examples/mac/app.js
createServer
function createServer () { // Create server var server = express.createServer(); // Configure Server server.configure(function () { // Built-in server.use(express.methodOverride()); // Allow method override using _method form parameter server.use(express.bodyDecoder()); // Parse application/x-www-form-urlencoded server.use(express.staticProvider(__dirname + '/files')); // Serve client documents in local directory // Local server.use(setResponseHeader()); // Set default response headers for CORS server.use(logConsole()); // Display incoming requests // Authentication server.use(auth([auth.Mac({ realm: "Example", // Set realm, typically a domain name or application name getTokenAttributes: getToken, // Function used to fetch the access token record, typically from a database // hostHeader: 'x-forwarded-host', // Needed when running behind a proxy such as Apache2 // isHTTPS: true, // Uncomment for HTTPS checkNonce: nonceCheck, // Optional nonce checking function bodyHashMode: "require" })])); // Require body hash validation for all non GET/HEAD/OPTIONS requests }); // Setup generic OPTIONS route server.options(/.+/, function (req, res) { res.send(' '); }); return server; }
javascript
function createServer () { // Create server var server = express.createServer(); // Configure Server server.configure(function () { // Built-in server.use(express.methodOverride()); // Allow method override using _method form parameter server.use(express.bodyDecoder()); // Parse application/x-www-form-urlencoded server.use(express.staticProvider(__dirname + '/files')); // Serve client documents in local directory // Local server.use(setResponseHeader()); // Set default response headers for CORS server.use(logConsole()); // Display incoming requests // Authentication server.use(auth([auth.Mac({ realm: "Example", // Set realm, typically a domain name or application name getTokenAttributes: getToken, // Function used to fetch the access token record, typically from a database // hostHeader: 'x-forwarded-host', // Needed when running behind a proxy such as Apache2 // isHTTPS: true, // Uncomment for HTTPS checkNonce: nonceCheck, // Optional nonce checking function bodyHashMode: "require" })])); // Require body hash validation for all non GET/HEAD/OPTIONS requests }); // Setup generic OPTIONS route server.options(/.+/, function (req, res) { res.send(' '); }); return server; }
[ "function", "createServer", "(", ")", "{", "// Create server", "var", "server", "=", "express", ".", "createServer", "(", ")", ";", "// Configure Server", "server", ".", "configure", "(", "function", "(", ")", "{", "// Built-in", "server", ".", "use", "(", "express", ".", "methodOverride", "(", ")", ")", ";", "// Allow method override using _method form parameter", "server", ".", "use", "(", "express", ".", "bodyDecoder", "(", ")", ")", ";", "// Parse application/x-www-form-urlencoded", "server", ".", "use", "(", "express", ".", "staticProvider", "(", "__dirname", "+", "'/files'", ")", ")", ";", "// Serve client documents in local directory", "// Local", "server", ".", "use", "(", "setResponseHeader", "(", ")", ")", ";", "// Set default response headers for CORS", "server", ".", "use", "(", "logConsole", "(", ")", ")", ";", "// Display incoming requests", "// Authentication", "server", ".", "use", "(", "auth", "(", "[", "auth", ".", "Mac", "(", "{", "realm", ":", "\"Example\"", ",", "// Set realm, typically a domain name or application name", "getTokenAttributes", ":", "getToken", ",", "// Function used to fetch the access token record, typically from a database", "// hostHeader: 'x-forwarded-host', // Needed when running behind a proxy such as Apache2", "// isHTTPS: true, // Uncomment for HTTPS", "checkNonce", ":", "nonceCheck", ",", "// Optional nonce checking function", "bodyHashMode", ":", "\"require\"", "}", ")", "]", ")", ")", ";", "// Require body hash validation for all non GET/HEAD/OPTIONS requests", "}", ")", ";", "// Setup generic OPTIONS route", "server", ".", "options", "(", "/", ".+", "/", ",", "function", "(", "req", ",", "res", ")", "{", "res", ".", "send", "(", "' '", ")", ";", "}", ")", ";", "return", "server", ";", "}" ]
Create and configure server instance
[ "Create", "and", "configure", "server", "instance" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/examples/mac/app.js#L9-L48
21,008
ciaranj/connect-auth
examples/mac/app.js
logConsole
function logConsole() { return function (req, res, next) { console.log('Received request: ' + req.method + ' ' + req.originalUrl); next(); }; }
javascript
function logConsole() { return function (req, res, next) { console.log('Received request: ' + req.method + ' ' + req.originalUrl); next(); }; }
[ "function", "logConsole", "(", ")", "{", "return", "function", "(", "req", ",", "res", ",", "next", ")", "{", "console", ".", "log", "(", "'Received request: '", "+", "req", ".", "method", "+", "' '", "+", "req", ".", "originalUrl", ")", ";", "next", "(", ")", ";", "}", ";", "}" ]
Log requests to console
[ "Log", "requests", "to", "console" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/examples/mac/app.js#L69-L77
21,009
ciaranj/connect-auth
lib/auth.strategies/http/mac.js
signRequest
function signRequest(method, URI, host, port, token, secret, hashMethod, timestamp, nonce, bodyHash) { // Parse request URI var uri = URL.parse(URI, true); if (uri.pathname == null) { // Error: Bad request URI return ""; } // Construct normalized request string var normalized = token + '\n' + timestamp + '\n' + nonce + '\n' + bodyHash + '\n' + method.toUpperCase() + '\n' + host.toLowerCase() + '\n' + port + '\n' + uri.pathname + '\n'; // Normalize parameters var params = new Array; if (uri.query) { var count = 0; for (var p in uri.query) { if (typeof uri.query[p] == 'string') { params[count++] = percentEscape(p) + "=" + percentEscape(uri.query[p]); } else { for (var i in uri.query[p]) { params[count++] = percentEscape(p) + "=" + percentEscape(uri.query[p][i]); } } } params.sort(); for (var i in params) { normalized += params[i] + '\n'; } } // Sign normalized request string var hmac = Crypto.createHmac(hashMethod, secret).update(normalized); var digest = hmac.digest(encoding = "base64"); return digest; }
javascript
function signRequest(method, URI, host, port, token, secret, hashMethod, timestamp, nonce, bodyHash) { // Parse request URI var uri = URL.parse(URI, true); if (uri.pathname == null) { // Error: Bad request URI return ""; } // Construct normalized request string var normalized = token + '\n' + timestamp + '\n' + nonce + '\n' + bodyHash + '\n' + method.toUpperCase() + '\n' + host.toLowerCase() + '\n' + port + '\n' + uri.pathname + '\n'; // Normalize parameters var params = new Array; if (uri.query) { var count = 0; for (var p in uri.query) { if (typeof uri.query[p] == 'string') { params[count++] = percentEscape(p) + "=" + percentEscape(uri.query[p]); } else { for (var i in uri.query[p]) { params[count++] = percentEscape(p) + "=" + percentEscape(uri.query[p][i]); } } } params.sort(); for (var i in params) { normalized += params[i] + '\n'; } } // Sign normalized request string var hmac = Crypto.createHmac(hashMethod, secret).update(normalized); var digest = hmac.digest(encoding = "base64"); return digest; }
[ "function", "signRequest", "(", "method", ",", "URI", ",", "host", ",", "port", ",", "token", ",", "secret", ",", "hashMethod", ",", "timestamp", ",", "nonce", ",", "bodyHash", ")", "{", "// Parse request URI", "var", "uri", "=", "URL", ".", "parse", "(", "URI", ",", "true", ")", ";", "if", "(", "uri", ".", "pathname", "==", "null", ")", "{", "// Error: Bad request URI", "return", "\"\"", ";", "}", "// Construct normalized request string", "var", "normalized", "=", "token", "+", "'\\n'", "+", "timestamp", "+", "'\\n'", "+", "nonce", "+", "'\\n'", "+", "bodyHash", "+", "'\\n'", "+", "method", ".", "toUpperCase", "(", ")", "+", "'\\n'", "+", "host", ".", "toLowerCase", "(", ")", "+", "'\\n'", "+", "port", "+", "'\\n'", "+", "uri", ".", "pathname", "+", "'\\n'", ";", "// Normalize parameters", "var", "params", "=", "new", "Array", ";", "if", "(", "uri", ".", "query", ")", "{", "var", "count", "=", "0", ";", "for", "(", "var", "p", "in", "uri", ".", "query", ")", "{", "if", "(", "typeof", "uri", ".", "query", "[", "p", "]", "==", "'string'", ")", "{", "params", "[", "count", "++", "]", "=", "percentEscape", "(", "p", ")", "+", "\"=\"", "+", "percentEscape", "(", "uri", ".", "query", "[", "p", "]", ")", ";", "}", "else", "{", "for", "(", "var", "i", "in", "uri", ".", "query", "[", "p", "]", ")", "{", "params", "[", "count", "++", "]", "=", "percentEscape", "(", "p", ")", "+", "\"=\"", "+", "percentEscape", "(", "uri", ".", "query", "[", "p", "]", "[", "i", "]", ")", ";", "}", "}", "}", "params", ".", "sort", "(", ")", ";", "for", "(", "var", "i", "in", "params", ")", "{", "normalized", "+=", "params", "[", "i", "]", "+", "'\\n'", ";", "}", "}", "// Sign normalized request string", "var", "hmac", "=", "Crypto", ".", "createHmac", "(", "hashMethod", ",", "secret", ")", ".", "update", "(", "normalized", ")", ";", "var", "digest", "=", "hmac", ".", "digest", "(", "encoding", "=", "\"base64\"", ")", ";", "return", "digest", ";", "}" ]
Calculate the request signature
[ "Calculate", "the", "request", "signature" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/lib/auth.strategies/http/mac.js#L252-L310
21,010
ciaranj/connect-auth
lib/auth.strategies/http/mac.js
percentEscape
function percentEscape(value) { // Percent-escape per specification var escapedString = ''; for (var i = 0; i < value.length; i++) { var char = value.charCodeAt(i); if ((char >= 48 && char <= 57) || // 09 (char >= 65 && char <= 90) || // AZ (char >= 97 && char <= 122) || // az char == 45 || // - char == 95 || // _ char == 46 || // . char == 126) { // ~ escapedString += String.fromCharCode(char); } else { escapedString += '%' + char.toString(16).toUpperCase(); } } return escapedString; }
javascript
function percentEscape(value) { // Percent-escape per specification var escapedString = ''; for (var i = 0; i < value.length; i++) { var char = value.charCodeAt(i); if ((char >= 48 && char <= 57) || // 09 (char >= 65 && char <= 90) || // AZ (char >= 97 && char <= 122) || // az char == 45 || // - char == 95 || // _ char == 46 || // . char == 126) { // ~ escapedString += String.fromCharCode(char); } else { escapedString += '%' + char.toString(16).toUpperCase(); } } return escapedString; }
[ "function", "percentEscape", "(", "value", ")", "{", "// Percent-escape per specification", "var", "escapedString", "=", "''", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "value", ".", "length", ";", "i", "++", ")", "{", "var", "char", "=", "value", ".", "charCodeAt", "(", "i", ")", ";", "if", "(", "(", "char", ">=", "48", "&&", "char", "<=", "57", ")", "||", "// 09", "(", "char", ">=", "65", "&&", "char", "<=", "90", ")", "||", "// AZ", "(", "char", ">=", "97", "&&", "char", "<=", "122", ")", "||", "// az", "char", "==", "45", "||", "// -", "char", "==", "95", "||", "// _", "char", "==", "46", "||", "// .", "char", "==", "126", ")", "{", "// ~", "escapedString", "+=", "String", ".", "fromCharCode", "(", "char", ")", ";", "}", "else", "{", "escapedString", "+=", "'%'", "+", "char", ".", "toString", "(", "16", ")", ".", "toUpperCase", "(", ")", ";", "}", "}", "return", "escapedString", ";", "}" ]
Percent encode values per custom specification
[ "Percent", "encode", "values", "per", "custom", "specification" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/lib/auth.strategies/http/mac.js#L315-L342
21,011
ciaranj/connect-auth
lib/auth.strategies/oauth/_oauthservices.js
function(requestParameters, next) { if(self.providerProvidesValidateNotReplayClient) { self.provider.validateNotReplayClient(requestParameters.oauth_consumer_key, requestParameters.oauth_token, requestParameters.oauth_timestamp, requestParameters.oauth_nonce, function(err, result) { if(err) { callback(new errors.OAuthUnauthorizedError('Invalid / used nonce'), null); } else { next(); } }); } else { self.provider.validateNotReplay(requestParameters.oauth_token, requestParameters.oauth_timestamp, requestParameters.oauth_nonce, function(err, result) { if(err) { callback(new errors.OAuthUnauthorizedError('Invalid / used nonce'), null); } else { next(); } }); } }
javascript
function(requestParameters, next) { if(self.providerProvidesValidateNotReplayClient) { self.provider.validateNotReplayClient(requestParameters.oauth_consumer_key, requestParameters.oauth_token, requestParameters.oauth_timestamp, requestParameters.oauth_nonce, function(err, result) { if(err) { callback(new errors.OAuthUnauthorizedError('Invalid / used nonce'), null); } else { next(); } }); } else { self.provider.validateNotReplay(requestParameters.oauth_token, requestParameters.oauth_timestamp, requestParameters.oauth_nonce, function(err, result) { if(err) { callback(new errors.OAuthUnauthorizedError('Invalid / used nonce'), null); } else { next(); } }); } }
[ "function", "(", "requestParameters", ",", "next", ")", "{", "if", "(", "self", ".", "providerProvidesValidateNotReplayClient", ")", "{", "self", ".", "provider", ".", "validateNotReplayClient", "(", "requestParameters", ".", "oauth_consumer_key", ",", "requestParameters", ".", "oauth_token", ",", "requestParameters", ".", "oauth_timestamp", ",", "requestParameters", ".", "oauth_nonce", ",", "function", "(", "err", ",", "result", ")", "{", "if", "(", "err", ")", "{", "callback", "(", "new", "errors", ".", "OAuthUnauthorizedError", "(", "'Invalid / used nonce'", ")", ",", "null", ")", ";", "}", "else", "{", "next", "(", ")", ";", "}", "}", ")", ";", "}", "else", "{", "self", ".", "provider", ".", "validateNotReplay", "(", "requestParameters", ".", "oauth_token", ",", "requestParameters", ".", "oauth_timestamp", ",", "requestParameters", ".", "oauth_nonce", ",", "function", "(", "err", ",", "result", ")", "{", "if", "(", "err", ")", "{", "callback", "(", "new", "errors", ".", "OAuthUnauthorizedError", "(", "'Invalid / used nonce'", ")", ",", "null", ")", ";", "}", "else", "{", "next", "(", ")", ";", "}", "}", ")", ";", "}", "}" ]
Given all the requestParameters and the next step function, error out if the a replay is detected
[ "Given", "all", "the", "requestParameters", "and", "the", "next", "step", "function", "error", "out", "if", "the", "a", "replay", "is", "detected" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/lib/auth.strategies/oauth/_oauthservices.js#L227-L245
21,012
kartograph/kartograph.js
dist/kartograph.js
kdtree
function kdtree() { var kdtree = {}, axes = ["x", "y"], root, points = []; kdtree.axes = function(x) { if (!arguments.length) return axes; axes = x; return kdtree; }; kdtree.points = function(x) { if (!arguments.length) return points; points = x; root = null; return kdtree; }; kdtree.find = function(x) { return find(kdtree.root(), x, root).point; }; kdtree.root = function(x) { return root || (root = node(points, 0)); }; function node(points, depth) { if (!points.length) return; var axis = axes[depth % axes.length], median = points.length >> 1; points.sort(order(axis)); // could use random sample to speed up here return { axis: axis, point: points[median], left: node(points.slice(0, median), depth + 1), right: node(points.slice(median + 1), depth + 1) }; } function distance(a, b) { var sum = 0; for (var i = 0; i < axes.length; i++) { var axis = axes[i], d = a[axis] - b[axis]; sum += d * d; } return sum; } function order(axis) { return function(a, b) { a = a[axis]; b = b[axis]; return a < b ? -1 : a > b ? 1 : 0; }; } function find(node, point, best) { if (distance(node.point, point) < distance(best.point, point)) best = node; if (node.left) best = find(node.left, point, best); if (node.right) { var d = node.point[node.axis] - point[node.axis]; if (d * d < distance(best.point, point)) best = find(node.right, point, best); } return best; } return kdtree; }
javascript
function kdtree() { var kdtree = {}, axes = ["x", "y"], root, points = []; kdtree.axes = function(x) { if (!arguments.length) return axes; axes = x; return kdtree; }; kdtree.points = function(x) { if (!arguments.length) return points; points = x; root = null; return kdtree; }; kdtree.find = function(x) { return find(kdtree.root(), x, root).point; }; kdtree.root = function(x) { return root || (root = node(points, 0)); }; function node(points, depth) { if (!points.length) return; var axis = axes[depth % axes.length], median = points.length >> 1; points.sort(order(axis)); // could use random sample to speed up here return { axis: axis, point: points[median], left: node(points.slice(0, median), depth + 1), right: node(points.slice(median + 1), depth + 1) }; } function distance(a, b) { var sum = 0; for (var i = 0; i < axes.length; i++) { var axis = axes[i], d = a[axis] - b[axis]; sum += d * d; } return sum; } function order(axis) { return function(a, b) { a = a[axis]; b = b[axis]; return a < b ? -1 : a > b ? 1 : 0; }; } function find(node, point, best) { if (distance(node.point, point) < distance(best.point, point)) best = node; if (node.left) best = find(node.left, point, best); if (node.right) { var d = node.point[node.axis] - point[node.axis]; if (d * d < distance(best.point, point)) best = find(node.right, point, best); } return best; } return kdtree; }
[ "function", "kdtree", "(", ")", "{", "var", "kdtree", "=", "{", "}", ",", "axes", "=", "[", "\"x\"", ",", "\"y\"", "]", ",", "root", ",", "points", "=", "[", "]", ";", "kdtree", ".", "axes", "=", "function", "(", "x", ")", "{", "if", "(", "!", "arguments", ".", "length", ")", "return", "axes", ";", "axes", "=", "x", ";", "return", "kdtree", ";", "}", ";", "kdtree", ".", "points", "=", "function", "(", "x", ")", "{", "if", "(", "!", "arguments", ".", "length", ")", "return", "points", ";", "points", "=", "x", ";", "root", "=", "null", ";", "return", "kdtree", ";", "}", ";", "kdtree", ".", "find", "=", "function", "(", "x", ")", "{", "return", "find", "(", "kdtree", ".", "root", "(", ")", ",", "x", ",", "root", ")", ".", "point", ";", "}", ";", "kdtree", ".", "root", "=", "function", "(", "x", ")", "{", "return", "root", "||", "(", "root", "=", "node", "(", "points", ",", "0", ")", ")", ";", "}", ";", "function", "node", "(", "points", ",", "depth", ")", "{", "if", "(", "!", "points", ".", "length", ")", "return", ";", "var", "axis", "=", "axes", "[", "depth", "%", "axes", ".", "length", "]", ",", "median", "=", "points", ".", "length", ">>", "1", ";", "points", ".", "sort", "(", "order", "(", "axis", ")", ")", ";", "// could use random sample to speed up here", "return", "{", "axis", ":", "axis", ",", "point", ":", "points", "[", "median", "]", ",", "left", ":", "node", "(", "points", ".", "slice", "(", "0", ",", "median", ")", ",", "depth", "+", "1", ")", ",", "right", ":", "node", "(", "points", ".", "slice", "(", "median", "+", "1", ")", ",", "depth", "+", "1", ")", "}", ";", "}", "function", "distance", "(", "a", ",", "b", ")", "{", "var", "sum", "=", "0", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "axes", ".", "length", ";", "i", "++", ")", "{", "var", "axis", "=", "axes", "[", "i", "]", ",", "d", "=", "a", "[", "axis", "]", "-", "b", "[", "axis", "]", ";", "sum", "+=", "d", "*", "d", ";", "}", "return", "sum", ";", "}", "function", "order", "(", "axis", ")", "{", "return", "function", "(", "a", ",", "b", ")", "{", "a", "=", "a", "[", "axis", "]", ";", "b", "=", "b", "[", "axis", "]", ";", "return", "a", "<", "b", "?", "-", "1", ":", "a", ">", "b", "?", "1", ":", "0", ";", "}", ";", "}", "function", "find", "(", "node", ",", "point", ",", "best", ")", "{", "if", "(", "distance", "(", "node", ".", "point", ",", "point", ")", "<", "distance", "(", "best", ".", "point", ",", "point", ")", ")", "best", "=", "node", ";", "if", "(", "node", ".", "left", ")", "best", "=", "find", "(", "node", ".", "left", ",", "point", ",", "best", ")", ";", "if", "(", "node", ".", "right", ")", "{", "var", "d", "=", "node", ".", "point", "[", "node", ".", "axis", "]", "-", "point", "[", "node", ".", "axis", "]", ";", "if", "(", "d", "*", "d", "<", "distance", "(", "best", ".", "point", ",", "point", ")", ")", "best", "=", "find", "(", "node", ".", "right", ",", "point", ",", "best", ")", ";", "}", "return", "best", ";", "}", "return", "kdtree", ";", "}" ]
kd-tree
[ "kd", "-", "tree" ]
d3d3f2e1d022cd8c40236d94659ca54fe6aa52c1
https://github.com/kartograph/kartograph.js/blob/d3d3f2e1d022cd8c40236d94659ca54fe6aa52c1/dist/kartograph.js#L5238-L5305
21,013
ciaranj/connect-auth
spec/lib/jspec.js
function(path) { if (JSpec.cache[path]) return JSpec.cache[path] return JSpec.cache[path] = JSpec.tryLoading(JSpec.options.fixturePath + '/' + path) || JSpec.tryLoading(JSpec.options.fixturePath + '/' + path + '.html') }
javascript
function(path) { if (JSpec.cache[path]) return JSpec.cache[path] return JSpec.cache[path] = JSpec.tryLoading(JSpec.options.fixturePath + '/' + path) || JSpec.tryLoading(JSpec.options.fixturePath + '/' + path + '.html') }
[ "function", "(", "path", ")", "{", "if", "(", "JSpec", ".", "cache", "[", "path", "]", ")", "return", "JSpec", ".", "cache", "[", "path", "]", "return", "JSpec", ".", "cache", "[", "path", "]", "=", "JSpec", ".", "tryLoading", "(", "JSpec", ".", "options", ".", "fixturePath", "+", "'/'", "+", "path", ")", "||", "JSpec", ".", "tryLoading", "(", "JSpec", ".", "options", ".", "fixturePath", "+", "'/'", "+", "path", "+", "'.html'", ")", "}" ]
Load fixture at _path_. Fixtures are resolved as: - <path> - <path>.html @param {string} path @return {string} @api public
[ "Load", "fixture", "at", "_path_", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L66-L71
21,014
ciaranj/connect-auth
spec/lib/jspec.js
function(results, options) { var uri = options.uri || 'http://' + window.location.host + '/results' JSpec.post(uri, { stats: JSpec.stats, options: options, results: map(results.allSuites, function(suite) { if (suite.hasSpecs()) return { description: suite.description, specs: map(suite.specs, function(spec) { return { description: spec.description, message: !spec.passed() ? spec.failure().message : null, status: spec.requiresImplementation() ? 'pending' : spec.passed() ? 'pass' : 'fail', assertions: map(spec.assertions, function(assertion){ return { passed: assertion.passed } }) } }) } }) }) if ('close' in main) main.close() }
javascript
function(results, options) { var uri = options.uri || 'http://' + window.location.host + '/results' JSpec.post(uri, { stats: JSpec.stats, options: options, results: map(results.allSuites, function(suite) { if (suite.hasSpecs()) return { description: suite.description, specs: map(suite.specs, function(spec) { return { description: spec.description, message: !spec.passed() ? spec.failure().message : null, status: spec.requiresImplementation() ? 'pending' : spec.passed() ? 'pass' : 'fail', assertions: map(spec.assertions, function(assertion){ return { passed: assertion.passed } }) } }) } }) }) if ('close' in main) main.close() }
[ "function", "(", "results", ",", "options", ")", "{", "var", "uri", "=", "options", ".", "uri", "||", "'http://'", "+", "window", ".", "location", ".", "host", "+", "'/results'", "JSpec", ".", "post", "(", "uri", ",", "{", "stats", ":", "JSpec", ".", "stats", ",", "options", ":", "options", ",", "results", ":", "map", "(", "results", ".", "allSuites", ",", "function", "(", "suite", ")", "{", "if", "(", "suite", ".", "hasSpecs", "(", ")", ")", "return", "{", "description", ":", "suite", ".", "description", ",", "specs", ":", "map", "(", "suite", ".", "specs", ",", "function", "(", "spec", ")", "{", "return", "{", "description", ":", "spec", ".", "description", ",", "message", ":", "!", "spec", ".", "passed", "(", ")", "?", "spec", ".", "failure", "(", ")", ".", "message", ":", "null", ",", "status", ":", "spec", ".", "requiresImplementation", "(", ")", "?", "'pending'", ":", "spec", ".", "passed", "(", ")", "?", "'pass'", ":", "'fail'", ",", "assertions", ":", "map", "(", "spec", ".", "assertions", ",", "function", "(", "assertion", ")", "{", "return", "{", "passed", ":", "assertion", ".", "passed", "}", "}", ")", "}", "}", ")", "}", "}", ")", "}", ")", "if", "(", "'close'", "in", "main", ")", "main", ".", "close", "(", ")", "}" ]
Report to server. Options: - uri specific uri to report to. - verbose weither or not to output messages - failuresOnly output failure messages only @api public
[ "Report", "to", "server", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L89-L116
21,015
ciaranj/connect-auth
spec/lib/jspec.js
function(results, options) { var id = option('reportToId') || 'jspec' var report = document.getElementById(id) var failuresOnly = option('failuresOnly') var classes = results.stats.failures ? 'has-failures' : '' if (!report) throw 'JSpec requires the element #' + id + ' to output its reports' function bodyContents(body) { return JSpec. escape(JSpec.contentsOf(body)). replace(/^ */gm, function(a){ return (new Array(Math.round(a.length / 3))).join(' ') }). replace(/\r\n|\r|\n/gm, '<br/>') } report.innerHTML = '<div id="jspec-report" class="' + classes + '"><div class="heading"> \ <span class="passes">Passes: <em>' + results.stats.passes + '</em></span> \ <span class="failures">Failures: <em>' + results.stats.failures + '</em></span> \ <span class="passes">Duration: <em>' + results.duration + '</em> ms</span> \ </div><table class="suites">' + map(results.allSuites, function(suite) { var displaySuite = failuresOnly ? suite.ran && !suite.passed() : suite.ran if (displaySuite && suite.hasSpecs()) return '<tr class="description"><td colspan="2">' + escape(suite.description) + '</td></tr>' + map(suite.specs, function(i, spec) { return '<tr class="' + (i % 2 ? 'odd' : 'even') + '">' + (spec.requiresImplementation() ? '<td class="requires-implementation" colspan="2">' + escape(spec.description) + '</td>' : (spec.passed() && !failuresOnly) ? '<td class="pass">' + escape(spec.description)+ '</td><td>' + spec.assertionsGraph() + '</td>' : !spec.passed() ? '<td class="fail">' + escape(spec.description) + map(spec.failures(), function(a){ return '<em>' + escape(a.message) + '</em>' }).join('') + '</td><td>' + spec.assertionsGraph() + '</td>' : '') + '<tr class="body"><td colspan="2"><pre>' + bodyContents(spec.body) + '</pre></td></tr>' }).join('') + '</tr>' }).join('') + '</table></div>' }
javascript
function(results, options) { var id = option('reportToId') || 'jspec' var report = document.getElementById(id) var failuresOnly = option('failuresOnly') var classes = results.stats.failures ? 'has-failures' : '' if (!report) throw 'JSpec requires the element #' + id + ' to output its reports' function bodyContents(body) { return JSpec. escape(JSpec.contentsOf(body)). replace(/^ */gm, function(a){ return (new Array(Math.round(a.length / 3))).join(' ') }). replace(/\r\n|\r|\n/gm, '<br/>') } report.innerHTML = '<div id="jspec-report" class="' + classes + '"><div class="heading"> \ <span class="passes">Passes: <em>' + results.stats.passes + '</em></span> \ <span class="failures">Failures: <em>' + results.stats.failures + '</em></span> \ <span class="passes">Duration: <em>' + results.duration + '</em> ms</span> \ </div><table class="suites">' + map(results.allSuites, function(suite) { var displaySuite = failuresOnly ? suite.ran && !suite.passed() : suite.ran if (displaySuite && suite.hasSpecs()) return '<tr class="description"><td colspan="2">' + escape(suite.description) + '</td></tr>' + map(suite.specs, function(i, spec) { return '<tr class="' + (i % 2 ? 'odd' : 'even') + '">' + (spec.requiresImplementation() ? '<td class="requires-implementation" colspan="2">' + escape(spec.description) + '</td>' : (spec.passed() && !failuresOnly) ? '<td class="pass">' + escape(spec.description)+ '</td><td>' + spec.assertionsGraph() + '</td>' : !spec.passed() ? '<td class="fail">' + escape(spec.description) + map(spec.failures(), function(a){ return '<em>' + escape(a.message) + '</em>' }).join('') + '</td><td>' + spec.assertionsGraph() + '</td>' : '') + '<tr class="body"><td colspan="2"><pre>' + bodyContents(spec.body) + '</pre></td></tr>' }).join('') + '</tr>' }).join('') + '</table></div>' }
[ "function", "(", "results", ",", "options", ")", "{", "var", "id", "=", "option", "(", "'reportToId'", ")", "||", "'jspec'", "var", "report", "=", "document", ".", "getElementById", "(", "id", ")", "var", "failuresOnly", "=", "option", "(", "'failuresOnly'", ")", "var", "classes", "=", "results", ".", "stats", ".", "failures", "?", "'has-failures'", ":", "''", "if", "(", "!", "report", ")", "throw", "'JSpec requires the element #'", "+", "id", "+", "' to output its reports'", "function", "bodyContents", "(", "body", ")", "{", "return", "JSpec", ".", "escape", "(", "JSpec", ".", "contentsOf", "(", "body", ")", ")", ".", "replace", "(", "/", "^ *", "/", "gm", ",", "function", "(", "a", ")", "{", "return", "(", "new", "Array", "(", "Math", ".", "round", "(", "a", ".", "length", "/", "3", ")", ")", ")", ".", "join", "(", "' '", ")", "}", ")", ".", "replace", "(", "/", "\\r\\n|\\r|\\n", "/", "gm", ",", "'<br/>'", ")", "}", "report", ".", "innerHTML", "=", "'<div id=\"jspec-report\" class=\"'", "+", "classes", "+", "'\"><div class=\"heading\"> \\\n <span class=\"passes\">Passes: <em>'", "+", "results", ".", "stats", ".", "passes", "+", "'</em></span> \\\n <span class=\"failures\">Failures: <em>'", "+", "results", ".", "stats", ".", "failures", "+", "'</em></span> \\\n <span class=\"passes\">Duration: <em>'", "+", "results", ".", "duration", "+", "'</em> ms</span> \\\n </div><table class=\"suites\">'", "+", "map", "(", "results", ".", "allSuites", ",", "function", "(", "suite", ")", "{", "var", "displaySuite", "=", "failuresOnly", "?", "suite", ".", "ran", "&&", "!", "suite", ".", "passed", "(", ")", ":", "suite", ".", "ran", "if", "(", "displaySuite", "&&", "suite", ".", "hasSpecs", "(", ")", ")", "return", "'<tr class=\"description\"><td colspan=\"2\">'", "+", "escape", "(", "suite", ".", "description", ")", "+", "'</td></tr>'", "+", "map", "(", "suite", ".", "specs", ",", "function", "(", "i", ",", "spec", ")", "{", "return", "'<tr class=\"'", "+", "(", "i", "%", "2", "?", "'odd'", ":", "'even'", ")", "+", "'\">'", "+", "(", "spec", ".", "requiresImplementation", "(", ")", "?", "'<td class=\"requires-implementation\" colspan=\"2\">'", "+", "escape", "(", "spec", ".", "description", ")", "+", "'</td>'", ":", "(", "spec", ".", "passed", "(", ")", "&&", "!", "failuresOnly", ")", "?", "'<td class=\"pass\">'", "+", "escape", "(", "spec", ".", "description", ")", "+", "'</td><td>'", "+", "spec", ".", "assertionsGraph", "(", ")", "+", "'</td>'", ":", "!", "spec", ".", "passed", "(", ")", "?", "'<td class=\"fail\">'", "+", "escape", "(", "spec", ".", "description", ")", "+", "map", "(", "spec", ".", "failures", "(", ")", ",", "function", "(", "a", ")", "{", "return", "'<em>'", "+", "escape", "(", "a", ".", "message", ")", "+", "'</em>'", "}", ")", ".", "join", "(", "''", ")", "+", "'</td><td>'", "+", "spec", ".", "assertionsGraph", "(", ")", "+", "'</td>'", ":", "''", ")", "+", "'<tr class=\"body\"><td colspan=\"2\"><pre>'", "+", "bodyContents", "(", "spec", ".", "body", ")", "+", "'</pre></td></tr>'", "}", ")", ".", "join", "(", "''", ")", "+", "'</tr>'", "}", ")", ".", "join", "(", "''", ")", "+", "'</table></div>'", "}" ]
Default reporter, outputting to the DOM. Options: - reportToId id of element to output reports to, defaults to 'jspec' - failuresOnly displays only suites with failing specs @api public
[ "Default", "reporter", "outputting", "to", "the", "DOM", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L128-L164
21,016
ciaranj/connect-auth
spec/lib/jspec.js
function(results, options) { failuresOnly = option('failuresOnly') print(color("\n Passes: ", 'bold') + color(results.stats.passes, 'green') + color(" Failures: ", 'bold') + color(results.stats.failures, 'red') + color(" Duration: ", 'bold') + color(results.duration, 'green') + " ms \n") function indent(string) { return string.replace(/^(.)/gm, ' $1') } each(results.allSuites, function(suite) { var displaySuite = failuresOnly ? suite.ran && !suite.passed() : suite.ran if (displaySuite && suite.hasSpecs()) { print(color(' ' + suite.description, 'bold')) each(suite.specs, function(spec){ var assertionsGraph = inject(spec.assertions, '', function(graph, assertion){ return graph + color('.', assertion.passed ? 'green' : 'red') }) if (spec.requiresImplementation()) print(color(' ' + spec.description, 'blue') + assertionsGraph) else if (spec.passed() && !failuresOnly) print(color(' ' + spec.description, 'green') + assertionsGraph) else if (!spec.passed()) print(color(' ' + spec.description, 'red') + assertionsGraph + "\n" + indent(map(spec.failures(), function(a){ return a.message }).join("\n")) + "\n") }) print("") } }) quit(results.stats.failures) }
javascript
function(results, options) { failuresOnly = option('failuresOnly') print(color("\n Passes: ", 'bold') + color(results.stats.passes, 'green') + color(" Failures: ", 'bold') + color(results.stats.failures, 'red') + color(" Duration: ", 'bold') + color(results.duration, 'green') + " ms \n") function indent(string) { return string.replace(/^(.)/gm, ' $1') } each(results.allSuites, function(suite) { var displaySuite = failuresOnly ? suite.ran && !suite.passed() : suite.ran if (displaySuite && suite.hasSpecs()) { print(color(' ' + suite.description, 'bold')) each(suite.specs, function(spec){ var assertionsGraph = inject(spec.assertions, '', function(graph, assertion){ return graph + color('.', assertion.passed ? 'green' : 'red') }) if (spec.requiresImplementation()) print(color(' ' + spec.description, 'blue') + assertionsGraph) else if (spec.passed() && !failuresOnly) print(color(' ' + spec.description, 'green') + assertionsGraph) else if (!spec.passed()) print(color(' ' + spec.description, 'red') + assertionsGraph + "\n" + indent(map(spec.failures(), function(a){ return a.message }).join("\n")) + "\n") }) print("") } }) quit(results.stats.failures) }
[ "function", "(", "results", ",", "options", ")", "{", "failuresOnly", "=", "option", "(", "'failuresOnly'", ")", "print", "(", "color", "(", "\"\\n Passes: \"", ",", "'bold'", ")", "+", "color", "(", "results", ".", "stats", ".", "passes", ",", "'green'", ")", "+", "color", "(", "\" Failures: \"", ",", "'bold'", ")", "+", "color", "(", "results", ".", "stats", ".", "failures", ",", "'red'", ")", "+", "color", "(", "\" Duration: \"", ",", "'bold'", ")", "+", "color", "(", "results", ".", "duration", ",", "'green'", ")", "+", "\" ms \\n\"", ")", "function", "indent", "(", "string", ")", "{", "return", "string", ".", "replace", "(", "/", "^(.)", "/", "gm", ",", "' $1'", ")", "}", "each", "(", "results", ".", "allSuites", ",", "function", "(", "suite", ")", "{", "var", "displaySuite", "=", "failuresOnly", "?", "suite", ".", "ran", "&&", "!", "suite", ".", "passed", "(", ")", ":", "suite", ".", "ran", "if", "(", "displaySuite", "&&", "suite", ".", "hasSpecs", "(", ")", ")", "{", "print", "(", "color", "(", "' '", "+", "suite", ".", "description", ",", "'bold'", ")", ")", "each", "(", "suite", ".", "specs", ",", "function", "(", "spec", ")", "{", "var", "assertionsGraph", "=", "inject", "(", "spec", ".", "assertions", ",", "''", ",", "function", "(", "graph", ",", "assertion", ")", "{", "return", "graph", "+", "color", "(", "'.'", ",", "assertion", ".", "passed", "?", "'green'", ":", "'red'", ")", "}", ")", "if", "(", "spec", ".", "requiresImplementation", "(", ")", ")", "print", "(", "color", "(", "' '", "+", "spec", ".", "description", ",", "'blue'", ")", "+", "assertionsGraph", ")", "else", "if", "(", "spec", ".", "passed", "(", ")", "&&", "!", "failuresOnly", ")", "print", "(", "color", "(", "' '", "+", "spec", ".", "description", ",", "'green'", ")", "+", "assertionsGraph", ")", "else", "if", "(", "!", "spec", ".", "passed", "(", ")", ")", "print", "(", "color", "(", "' '", "+", "spec", ".", "description", ",", "'red'", ")", "+", "assertionsGraph", "+", "\"\\n\"", "+", "indent", "(", "map", "(", "spec", ".", "failures", "(", ")", ",", "function", "(", "a", ")", "{", "return", "a", ".", "message", "}", ")", ".", "join", "(", "\"\\n\"", ")", ")", "+", "\"\\n\"", ")", "}", ")", "print", "(", "\"\"", ")", "}", "}", ")", "quit", "(", "results", ".", "stats", ".", "failures", ")", "}" ]
Terminal reporter. @api public
[ "Terminal", "reporter", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L172-L203
21,017
ciaranj/connect-auth
spec/lib/jspec.js
function(results, options) { console.log('') console.log('Passes: ' + results.stats.passes + ' Failures: ' + results.stats.failures) each(results.allSuites, function(suite) { if (suite.ran) { console.group(suite.description) each(suite.specs, function(spec){ var assertionCount = spec.assertions.length + ':' if (spec.requiresImplementation()) console.warn(spec.description) else if (spec.passed()) console.log(assertionCount + ' ' + spec.description) else console.error(assertionCount + ' ' + spec.description + ', ' + spec.failure().message) }) console.groupEnd() } }) }
javascript
function(results, options) { console.log('') console.log('Passes: ' + results.stats.passes + ' Failures: ' + results.stats.failures) each(results.allSuites, function(suite) { if (suite.ran) { console.group(suite.description) each(suite.specs, function(spec){ var assertionCount = spec.assertions.length + ':' if (spec.requiresImplementation()) console.warn(spec.description) else if (spec.passed()) console.log(assertionCount + ' ' + spec.description) else console.error(assertionCount + ' ' + spec.description + ', ' + spec.failure().message) }) console.groupEnd() } }) }
[ "function", "(", "results", ",", "options", ")", "{", "console", ".", "log", "(", "''", ")", "console", ".", "log", "(", "'Passes: '", "+", "results", ".", "stats", ".", "passes", "+", "' Failures: '", "+", "results", ".", "stats", ".", "failures", ")", "each", "(", "results", ".", "allSuites", ",", "function", "(", "suite", ")", "{", "if", "(", "suite", ".", "ran", ")", "{", "console", ".", "group", "(", "suite", ".", "description", ")", "each", "(", "suite", ".", "specs", ",", "function", "(", "spec", ")", "{", "var", "assertionCount", "=", "spec", ".", "assertions", ".", "length", "+", "':'", "if", "(", "spec", ".", "requiresImplementation", "(", ")", ")", "console", ".", "warn", "(", "spec", ".", "description", ")", "else", "if", "(", "spec", ".", "passed", "(", ")", ")", "console", ".", "log", "(", "assertionCount", "+", "' '", "+", "spec", ".", "description", ")", "else", "console", ".", "error", "(", "assertionCount", "+", "' '", "+", "spec", ".", "description", "+", "', '", "+", "spec", ".", "failure", "(", ")", ".", "message", ")", "}", ")", "console", ".", "groupEnd", "(", ")", "}", "}", ")", "}" ]
Console reporter. @api public
[ "Console", "reporter", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L211-L229
21,018
ciaranj/connect-auth
spec/lib/jspec.js
function() { return any(this.calls, function(call){ return self.expectedResult.an_instance_of ? call.result.constructor == self.expectedResult.an_instance_of: equal(self.expectedResult, call.result) }) }
javascript
function() { return any(this.calls, function(call){ return self.expectedResult.an_instance_of ? call.result.constructor == self.expectedResult.an_instance_of: equal(self.expectedResult, call.result) }) }
[ "function", "(", ")", "{", "return", "any", "(", "this", ".", "calls", ",", "function", "(", "call", ")", "{", "return", "self", ".", "expectedResult", ".", "an_instance_of", "?", "call", ".", "result", ".", "constructor", "==", "self", ".", "expectedResult", ".", "an_instance_of", ":", "equal", "(", "self", ".", "expectedResult", ",", "call", ".", "result", ")", "}", ")", "}" ]
Check if any calls have passing results
[ "Check", "if", "any", "calls", "have", "passing", "results" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L317-L323
21,019
ciaranj/connect-auth
spec/lib/jspec.js
function() { return any(this.calls, function(call){ return any(self.expectedArgs, function(i, arg){ return arg.an_instance_of ? call.args[i].constructor == arg.an_instance_of: equal(arg, call.args[i]) }) }) }
javascript
function() { return any(this.calls, function(call){ return any(self.expectedArgs, function(i, arg){ return arg.an_instance_of ? call.args[i].constructor == arg.an_instance_of: equal(arg, call.args[i]) }) }) }
[ "function", "(", ")", "{", "return", "any", "(", "this", ".", "calls", ",", "function", "(", "call", ")", "{", "return", "any", "(", "self", ".", "expectedArgs", ",", "function", "(", "i", ",", "arg", ")", "{", "return", "arg", ".", "an_instance_of", "?", "call", ".", "args", "[", "i", "]", ".", "constructor", "==", "arg", ".", "an_instance_of", ":", "equal", "(", "arg", ",", "call", ".", "args", "[", "i", "]", ")", "}", ")", "}", ")", "}" ]
Check if any arguments pass
[ "Check", "if", "any", "arguments", "pass" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L353-L362
21,020
ciaranj/connect-auth
spec/lib/jspec.js
function(description, body) { var self = this extend(this, { body: body, description: description, suites: [], specs: [], ran: false, hooks: { 'before' : [], 'after' : [], 'before_each' : [], 'after_each' : [] }, // Add a spec to the suite addSpec : function(description, body) { var spec = new JSpec.Spec(description, body) this.specs.push(spec) JSpec.stats.specs++ // TODO: abstract spec.suite = this }, // Add a hook to the suite addHook : function(hook, body) { this.hooks[hook].push(body) }, // Add a nested suite addSuite : function(description, body) { var suite = new JSpec.Suite(description, body) JSpec.allSuites.push(suite) suite.name = suite.description suite.description = this.description + ' ' + suite.description this.suites.push(suite) suite.suite = this }, // Invoke a hook in context to this suite hook : function(hook) { if (this.suite) this.suite.hook(hook) each(this.hooks[hook], function(body) { JSpec.evalBody(body, "Error in hook '" + hook + "', suite '" + self.description + "': ") }) }, // Check if nested suites are present hasSuites : function() { return this.suites.length }, // Check if this suite has specs hasSpecs : function() { return this.specs.length }, // Check if the entire suite passed passed : function() { return !any(this.specs, function(spec){ return !spec.passed() }) } }) }
javascript
function(description, body) { var self = this extend(this, { body: body, description: description, suites: [], specs: [], ran: false, hooks: { 'before' : [], 'after' : [], 'before_each' : [], 'after_each' : [] }, // Add a spec to the suite addSpec : function(description, body) { var spec = new JSpec.Spec(description, body) this.specs.push(spec) JSpec.stats.specs++ // TODO: abstract spec.suite = this }, // Add a hook to the suite addHook : function(hook, body) { this.hooks[hook].push(body) }, // Add a nested suite addSuite : function(description, body) { var suite = new JSpec.Suite(description, body) JSpec.allSuites.push(suite) suite.name = suite.description suite.description = this.description + ' ' + suite.description this.suites.push(suite) suite.suite = this }, // Invoke a hook in context to this suite hook : function(hook) { if (this.suite) this.suite.hook(hook) each(this.hooks[hook], function(body) { JSpec.evalBody(body, "Error in hook '" + hook + "', suite '" + self.description + "': ") }) }, // Check if nested suites are present hasSuites : function() { return this.suites.length }, // Check if this suite has specs hasSpecs : function() { return this.specs.length }, // Check if the entire suite passed passed : function() { return !any(this.specs, function(spec){ return !spec.passed() }) } }) }
[ "function", "(", "description", ",", "body", ")", "{", "var", "self", "=", "this", "extend", "(", "this", ",", "{", "body", ":", "body", ",", "description", ":", "description", ",", "suites", ":", "[", "]", ",", "specs", ":", "[", "]", ",", "ran", ":", "false", ",", "hooks", ":", "{", "'before'", ":", "[", "]", ",", "'after'", ":", "[", "]", ",", "'before_each'", ":", "[", "]", ",", "'after_each'", ":", "[", "]", "}", ",", "// Add a spec to the suite", "addSpec", ":", "function", "(", "description", ",", "body", ")", "{", "var", "spec", "=", "new", "JSpec", ".", "Spec", "(", "description", ",", "body", ")", "this", ".", "specs", ".", "push", "(", "spec", ")", "JSpec", ".", "stats", ".", "specs", "++", "// TODO: abstract", "spec", ".", "suite", "=", "this", "}", ",", "// Add a hook to the suite", "addHook", ":", "function", "(", "hook", ",", "body", ")", "{", "this", ".", "hooks", "[", "hook", "]", ".", "push", "(", "body", ")", "}", ",", "// Add a nested suite", "addSuite", ":", "function", "(", "description", ",", "body", ")", "{", "var", "suite", "=", "new", "JSpec", ".", "Suite", "(", "description", ",", "body", ")", "JSpec", ".", "allSuites", ".", "push", "(", "suite", ")", "suite", ".", "name", "=", "suite", ".", "description", "suite", ".", "description", "=", "this", ".", "description", "+", "' '", "+", "suite", ".", "description", "this", ".", "suites", ".", "push", "(", "suite", ")", "suite", ".", "suite", "=", "this", "}", ",", "// Invoke a hook in context to this suite", "hook", ":", "function", "(", "hook", ")", "{", "if", "(", "this", ".", "suite", ")", "this", ".", "suite", ".", "hook", "(", "hook", ")", "each", "(", "this", ".", "hooks", "[", "hook", "]", ",", "function", "(", "body", ")", "{", "JSpec", ".", "evalBody", "(", "body", ",", "\"Error in hook '\"", "+", "hook", "+", "\"', suite '\"", "+", "self", ".", "description", "+", "\"': \"", ")", "}", ")", "}", ",", "// Check if nested suites are present", "hasSuites", ":", "function", "(", ")", "{", "return", "this", ".", "suites", ".", "length", "}", ",", "// Check if this suite has specs", "hasSpecs", ":", "function", "(", ")", "{", "return", "this", ".", "specs", ".", "length", "}", ",", "// Check if the entire suite passed", "passed", ":", "function", "(", ")", "{", "return", "!", "any", "(", "this", ".", "specs", ",", "function", "(", "spec", ")", "{", "return", "!", "spec", ".", "passed", "(", ")", "}", ")", "}", "}", ")", "}" ]
Specification Suite block object. @param {string} description @param {function} body @api private
[ "Specification", "Suite", "block", "object", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L421-L486
21,021
ciaranj/connect-auth
spec/lib/jspec.js
function(description, body) { var spec = new JSpec.Spec(description, body) this.specs.push(spec) JSpec.stats.specs++ // TODO: abstract spec.suite = this }
javascript
function(description, body) { var spec = new JSpec.Spec(description, body) this.specs.push(spec) JSpec.stats.specs++ // TODO: abstract spec.suite = this }
[ "function", "(", "description", ",", "body", ")", "{", "var", "spec", "=", "new", "JSpec", ".", "Spec", "(", "description", ",", "body", ")", "this", ".", "specs", ".", "push", "(", "spec", ")", "JSpec", ".", "stats", ".", "specs", "++", "// TODO: abstract", "spec", ".", "suite", "=", "this", "}" ]
Add a spec to the suite
[ "Add", "a", "spec", "to", "the", "suite" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L433-L438
21,022
ciaranj/connect-auth
spec/lib/jspec.js
function(description, body) { var suite = new JSpec.Suite(description, body) JSpec.allSuites.push(suite) suite.name = suite.description suite.description = this.description + ' ' + suite.description this.suites.push(suite) suite.suite = this }
javascript
function(description, body) { var suite = new JSpec.Suite(description, body) JSpec.allSuites.push(suite) suite.name = suite.description suite.description = this.description + ' ' + suite.description this.suites.push(suite) suite.suite = this }
[ "function", "(", "description", ",", "body", ")", "{", "var", "suite", "=", "new", "JSpec", ".", "Suite", "(", "description", ",", "body", ")", "JSpec", ".", "allSuites", ".", "push", "(", "suite", ")", "suite", ".", "name", "=", "suite", ".", "description", "suite", ".", "description", "=", "this", ".", "description", "+", "' '", "+", "suite", ".", "description", "this", ".", "suites", ".", "push", "(", "suite", ")", "suite", ".", "suite", "=", "this", "}" ]
Add a nested suite
[ "Add", "a", "nested", "suite" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L448-L455
21,023
ciaranj/connect-auth
spec/lib/jspec.js
function(hook) { if (this.suite) this.suite.hook(hook) each(this.hooks[hook], function(body) { JSpec.evalBody(body, "Error in hook '" + hook + "', suite '" + self.description + "': ") }) }
javascript
function(hook) { if (this.suite) this.suite.hook(hook) each(this.hooks[hook], function(body) { JSpec.evalBody(body, "Error in hook '" + hook + "', suite '" + self.description + "': ") }) }
[ "function", "(", "hook", ")", "{", "if", "(", "this", ".", "suite", ")", "this", ".", "suite", ".", "hook", "(", "hook", ")", "each", "(", "this", ".", "hooks", "[", "hook", "]", ",", "function", "(", "body", ")", "{", "JSpec", ".", "evalBody", "(", "body", ",", "\"Error in hook '\"", "+", "hook", "+", "\"', suite '\"", "+", "self", ".", "description", "+", "\"': \"", ")", "}", ")", "}" ]
Invoke a hook in context to this suite
[ "Invoke", "a", "hook", "in", "context", "to", "this", "suite" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L459-L464
21,024
ciaranj/connect-auth
spec/lib/jspec.js
function(description, body) { extend(this, { body: body, description: description, assertions: [], // Add passing assertion pass : function(message) { this.assertions.push({ passed: true, message: message }) if (JSpec.assert) ++JSpec.stats.passes }, // Add failing assertion fail : function(message) { this.assertions.push({ passed: false, message: message }) if (JSpec.assert) ++JSpec.stats.failures }, // Run deferred assertions runDeferredAssertions : function() { each(this.assertions, function(assertion){ if (assertion.defer) assertion.run().report(), hook('afterAssertion', assertion) }) }, // Find first failing assertion failure : function() { return find(this.assertions, function(assertion){ return !assertion.passed }) }, // Find all failing assertions failures : function() { return select(this.assertions, function(assertion){ return !assertion.passed }) }, // Weither or not the spec passed passed : function() { return !this.failure() }, // Weither or not the spec requires implementation (no assertions) requiresImplementation : function() { return this.assertions.length == 0 }, // Sprite based assertions graph assertionsGraph : function() { return map(this.assertions, function(assertion){ return '<span class="assertion ' + (assertion.passed ? 'passed' : 'failed') + '"></span>' }).join('') } }) }
javascript
function(description, body) { extend(this, { body: body, description: description, assertions: [], // Add passing assertion pass : function(message) { this.assertions.push({ passed: true, message: message }) if (JSpec.assert) ++JSpec.stats.passes }, // Add failing assertion fail : function(message) { this.assertions.push({ passed: false, message: message }) if (JSpec.assert) ++JSpec.stats.failures }, // Run deferred assertions runDeferredAssertions : function() { each(this.assertions, function(assertion){ if (assertion.defer) assertion.run().report(), hook('afterAssertion', assertion) }) }, // Find first failing assertion failure : function() { return find(this.assertions, function(assertion){ return !assertion.passed }) }, // Find all failing assertions failures : function() { return select(this.assertions, function(assertion){ return !assertion.passed }) }, // Weither or not the spec passed passed : function() { return !this.failure() }, // Weither or not the spec requires implementation (no assertions) requiresImplementation : function() { return this.assertions.length == 0 }, // Sprite based assertions graph assertionsGraph : function() { return map(this.assertions, function(assertion){ return '<span class="assertion ' + (assertion.passed ? 'passed' : 'failed') + '"></span>' }).join('') } }) }
[ "function", "(", "description", ",", "body", ")", "{", "extend", "(", "this", ",", "{", "body", ":", "body", ",", "description", ":", "description", ",", "assertions", ":", "[", "]", ",", "// Add passing assertion", "pass", ":", "function", "(", "message", ")", "{", "this", ".", "assertions", ".", "push", "(", "{", "passed", ":", "true", ",", "message", ":", "message", "}", ")", "if", "(", "JSpec", ".", "assert", ")", "++", "JSpec", ".", "stats", ".", "passes", "}", ",", "// Add failing assertion", "fail", ":", "function", "(", "message", ")", "{", "this", ".", "assertions", ".", "push", "(", "{", "passed", ":", "false", ",", "message", ":", "message", "}", ")", "if", "(", "JSpec", ".", "assert", ")", "++", "JSpec", ".", "stats", ".", "failures", "}", ",", "// Run deferred assertions", "runDeferredAssertions", ":", "function", "(", ")", "{", "each", "(", "this", ".", "assertions", ",", "function", "(", "assertion", ")", "{", "if", "(", "assertion", ".", "defer", ")", "assertion", ".", "run", "(", ")", ".", "report", "(", ")", ",", "hook", "(", "'afterAssertion'", ",", "assertion", ")", "}", ")", "}", ",", "// Find first failing assertion", "failure", ":", "function", "(", ")", "{", "return", "find", "(", "this", ".", "assertions", ",", "function", "(", "assertion", ")", "{", "return", "!", "assertion", ".", "passed", "}", ")", "}", ",", "// Find all failing assertions", "failures", ":", "function", "(", ")", "{", "return", "select", "(", "this", ".", "assertions", ",", "function", "(", "assertion", ")", "{", "return", "!", "assertion", ".", "passed", "}", ")", "}", ",", "// Weither or not the spec passed", "passed", ":", "function", "(", ")", "{", "return", "!", "this", ".", "failure", "(", ")", "}", ",", "// Weither or not the spec requires implementation (no assertions)", "requiresImplementation", ":", "function", "(", ")", "{", "return", "this", ".", "assertions", ".", "length", "==", "0", "}", ",", "// Sprite based assertions graph", "assertionsGraph", ":", "function", "(", ")", "{", "return", "map", "(", "this", ".", "assertions", ",", "function", "(", "assertion", ")", "{", "return", "'<span class=\"assertion '", "+", "(", "assertion", ".", "passed", "?", "'passed'", ":", "'failed'", ")", "+", "'\"></span>'", "}", ")", ".", "join", "(", "''", ")", "}", "}", ")", "}" ]
Specification block object. @param {string} description @param {function} body @api private
[ "Specification", "block", "object", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L496-L560
21,025
ciaranj/connect-auth
spec/lib/jspec.js
function(message) { this.assertions.push({ passed: true, message: message }) if (JSpec.assert) ++JSpec.stats.passes }
javascript
function(message) { this.assertions.push({ passed: true, message: message }) if (JSpec.assert) ++JSpec.stats.passes }
[ "function", "(", "message", ")", "{", "this", ".", "assertions", ".", "push", "(", "{", "passed", ":", "true", ",", "message", ":", "message", "}", ")", "if", "(", "JSpec", ".", "assert", ")", "++", "JSpec", ".", "stats", ".", "passes", "}" ]
Add passing assertion
[ "Add", "passing", "assertion" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L504-L507
21,026
ciaranj/connect-auth
spec/lib/jspec.js
function(message) { this.assertions.push({ passed: false, message: message }) if (JSpec.assert) ++JSpec.stats.failures }
javascript
function(message) { this.assertions.push({ passed: false, message: message }) if (JSpec.assert) ++JSpec.stats.failures }
[ "function", "(", "message", ")", "{", "this", ".", "assertions", ".", "push", "(", "{", "passed", ":", "false", ",", "message", ":", "message", "}", ")", "if", "(", "JSpec", ".", "assert", ")", "++", "JSpec", ".", "stats", ".", "failures", "}" ]
Add failing assertion
[ "Add", "failing", "assertion" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L511-L514
21,027
ciaranj/connect-auth
spec/lib/jspec.js
function() { each(this.assertions, function(assertion){ if (assertion.defer) assertion.run().report(), hook('afterAssertion', assertion) }) }
javascript
function() { each(this.assertions, function(assertion){ if (assertion.defer) assertion.run().report(), hook('afterAssertion', assertion) }) }
[ "function", "(", ")", "{", "each", "(", "this", ".", "assertions", ",", "function", "(", "assertion", ")", "{", "if", "(", "assertion", ".", "defer", ")", "assertion", ".", "run", "(", ")", ".", "report", "(", ")", ",", "hook", "(", "'afterAssertion'", ",", "assertion", ")", "}", ")", "}" ]
Run deferred assertions
[ "Run", "deferred", "assertions" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L518-L522
21,028
ciaranj/connect-auth
spec/lib/jspec.js
function(object) { var self = this if (object == undefined || object == null) return 'null' if (object === true) return 'true' if (object === false) return 'false' switch (typeof object) { case 'number': return object case 'string': return this.escapable.test(object) ? '"' + object.replace(this.escapable, function (a) { return typeof self.meta[a] === 'string' ? self.meta[a] : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4) }) + '"' : '"' + object + '"' case 'object': if (object.constructor == Array) return '[' + map(object, function(val){ return self.encode(val) }).join(', ') + ']' else if (object) return '{' + map(object, function(key, val){ return self.encode(key) + ':' + self.encode(val) }).join(', ') + '}' } return 'null' }
javascript
function(object) { var self = this if (object == undefined || object == null) return 'null' if (object === true) return 'true' if (object === false) return 'false' switch (typeof object) { case 'number': return object case 'string': return this.escapable.test(object) ? '"' + object.replace(this.escapable, function (a) { return typeof self.meta[a] === 'string' ? self.meta[a] : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4) }) + '"' : '"' + object + '"' case 'object': if (object.constructor == Array) return '[' + map(object, function(val){ return self.encode(val) }).join(', ') + ']' else if (object) return '{' + map(object, function(key, val){ return self.encode(key) + ':' + self.encode(val) }).join(', ') + '}' } return 'null' }
[ "function", "(", "object", ")", "{", "var", "self", "=", "this", "if", "(", "object", "==", "undefined", "||", "object", "==", "null", ")", "return", "'null'", "if", "(", "object", "===", "true", ")", "return", "'true'", "if", "(", "object", "===", "false", ")", "return", "'false'", "switch", "(", "typeof", "object", ")", "{", "case", "'number'", ":", "return", "object", "case", "'string'", ":", "return", "this", ".", "escapable", ".", "test", "(", "object", ")", "?", "'\"'", "+", "object", ".", "replace", "(", "this", ".", "escapable", ",", "function", "(", "a", ")", "{", "return", "typeof", "self", ".", "meta", "[", "a", "]", "===", "'string'", "?", "self", ".", "meta", "[", "a", "]", ":", "'\\\\u'", "+", "(", "'0000'", "+", "a", ".", "charCodeAt", "(", "0", ")", ".", "toString", "(", "16", ")", ")", ".", "slice", "(", "-", "4", ")", "}", ")", "+", "'\"'", ":", "'\"'", "+", "object", "+", "'\"'", "case", "'object'", ":", "if", "(", "object", ".", "constructor", "==", "Array", ")", "return", "'['", "+", "map", "(", "object", ",", "function", "(", "val", ")", "{", "return", "self", ".", "encode", "(", "val", ")", "}", ")", ".", "join", "(", "', '", ")", "+", "']'", "else", "if", "(", "object", ")", "return", "'{'", "+", "map", "(", "object", ",", "function", "(", "key", ",", "val", ")", "{", "return", "self", ".", "encode", "(", "key", ")", "+", "':'", "+", "self", ".", "encode", "(", "val", ")", "}", ")", ".", "join", "(", "', '", ")", "+", "'}'", "}", "return", "'null'", "}" ]
JSON encode _object_. @param {mixed} object @return {string} @api private
[ "JSON", "encode", "_object_", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L596-L620
21,029
ciaranj/connect-auth
spec/lib/jspec.js
function(object) { var module = object.constructor == JSpec.Module ? object : new JSpec.Module(object) this.modules.push(module) if ('init' in module) module.init() if ('utilities' in module) extend(this.defaultContext, module.utilities) if ('matchers' in module) this.addMatchers(module.matchers) if ('reporters' in module) extend(this.reporters, module.reporters) if ('DSLs' in module) each(module.DSLs, function(name, methods){ JSpec.DSLs[name] = JSpec.DSLs[name] || {} extend(JSpec.DSLs[name], methods) }) return this }
javascript
function(object) { var module = object.constructor == JSpec.Module ? object : new JSpec.Module(object) this.modules.push(module) if ('init' in module) module.init() if ('utilities' in module) extend(this.defaultContext, module.utilities) if ('matchers' in module) this.addMatchers(module.matchers) if ('reporters' in module) extend(this.reporters, module.reporters) if ('DSLs' in module) each(module.DSLs, function(name, methods){ JSpec.DSLs[name] = JSpec.DSLs[name] || {} extend(JSpec.DSLs[name], methods) }) return this }
[ "function", "(", "object", ")", "{", "var", "module", "=", "object", ".", "constructor", "==", "JSpec", ".", "Module", "?", "object", ":", "new", "JSpec", ".", "Module", "(", "object", ")", "this", ".", "modules", ".", "push", "(", "module", ")", "if", "(", "'init'", "in", "module", ")", "module", ".", "init", "(", ")", "if", "(", "'utilities'", "in", "module", ")", "extend", "(", "this", ".", "defaultContext", ",", "module", ".", "utilities", ")", "if", "(", "'matchers'", "in", "module", ")", "this", ".", "addMatchers", "(", "module", ".", "matchers", ")", "if", "(", "'reporters'", "in", "module", ")", "extend", "(", "this", ".", "reporters", ",", "module", ".", "reporters", ")", "if", "(", "'DSLs'", "in", "module", ")", "each", "(", "module", ".", "DSLs", ",", "function", "(", "name", ",", "methods", ")", "{", "JSpec", ".", "DSLs", "[", "name", "]", "=", "JSpec", ".", "DSLs", "[", "name", "]", "||", "{", "}", "extend", "(", "JSpec", ".", "DSLs", "[", "name", "]", ",", "methods", ")", "}", ")", "return", "this", "}" ]
Include _object_ which may be a hash or Module instance. @param {hash, Module} object @return {JSpec} @api public
[ "Include", "_object_", "which", "may", "be", "a", "hash", "or", "Module", "instance", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L684-L697
21,030
ciaranj/connect-auth
spec/lib/jspec.js
function(name, args) { args = toArray(arguments, 1) return inject(JSpec.modules, [], function(results, module){ if (typeof module[name] == 'function') results.push(JSpec.evalHook(module, name, args)) }) }
javascript
function(name, args) { args = toArray(arguments, 1) return inject(JSpec.modules, [], function(results, module){ if (typeof module[name] == 'function') results.push(JSpec.evalHook(module, name, args)) }) }
[ "function", "(", "name", ",", "args", ")", "{", "args", "=", "toArray", "(", "arguments", ",", "1", ")", "return", "inject", "(", "JSpec", ".", "modules", ",", "[", "]", ",", "function", "(", "results", ",", "module", ")", "{", "if", "(", "typeof", "module", "[", "name", "]", "==", "'function'", ")", "results", ".", "push", "(", "JSpec", ".", "evalHook", "(", "module", ",", "name", ",", "args", ")", ")", "}", ")", "}" ]
Add a module hook _name_, which is immediately called per module with the _args_ given. An array of hook return values is returned. @param {name} string @param {...} args @return {array} @api private
[ "Add", "a", "module", "hook", "_name_", "which", "is", "immediately", "called", "per", "module", "with", "the", "_args_", "given", ".", "An", "array", "of", "hook", "return", "values", "is", "returned", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L710-L716
21,031
ciaranj/connect-auth
spec/lib/jspec.js
function(module, name, args) { hook('evaluatingHookBody', module, name) try { return module[name].apply(module, args) } catch(e) { error('Error in hook ' + module.name + '.' + name + ': ', e) } }
javascript
function(module, name, args) { hook('evaluatingHookBody', module, name) try { return module[name].apply(module, args) } catch(e) { error('Error in hook ' + module.name + '.' + name + ': ', e) } }
[ "function", "(", "module", ",", "name", ",", "args", ")", "{", "hook", "(", "'evaluatingHookBody'", ",", "module", ",", "name", ")", "try", "{", "return", "module", "[", "name", "]", ".", "apply", "(", "module", ",", "args", ")", "}", "catch", "(", "e", ")", "{", "error", "(", "'Error in hook '", "+", "module", ".", "name", "+", "'.'", "+", "name", "+", "': '", ",", "e", ")", "}", "}" ]
Eval _module_ hook _name_ with _args_. Evaluates in context to the module itself, JSpec, and JSpec.context. @param {Module} module @param {string} name @param {array} args @return {mixed} @api private
[ "Eval", "_module_", "hook", "_name_", "with", "_args_", ".", "Evaluates", "in", "context", "to", "the", "module", "itself", "JSpec", "and", "JSpec", ".", "context", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L729-L733
21,032
ciaranj/connect-auth
spec/lib/jspec.js
function(description) { return find(this.allSuites, function(suite){ return suite.name == description || suite.description == description }) }
javascript
function(description) { return find(this.allSuites, function(suite){ return suite.name == description || suite.description == description }) }
[ "function", "(", "description", ")", "{", "return", "find", "(", "this", ".", "allSuites", ",", "function", "(", "suite", ")", "{", "return", "suite", ".", "name", "==", "description", "||", "suite", ".", "description", "==", "description", "}", ")", "}" ]
Find a suite by its description or name. @param {string} description @return {Suite} @api private
[ "Find", "a", "suite", "by", "its", "description", "or", "name", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L762-L766
21,033
ciaranj/connect-auth
spec/lib/jspec.js
function(fromSuite, toSuite) { each(fromSuite.specs, function(spec){ spec.assertions = [] toSuite.specs.push(spec) }) }
javascript
function(fromSuite, toSuite) { each(fromSuite.specs, function(spec){ spec.assertions = [] toSuite.specs.push(spec) }) }
[ "function", "(", "fromSuite", ",", "toSuite", ")", "{", "each", "(", "fromSuite", ".", "specs", ",", "function", "(", "spec", ")", "{", "spec", ".", "assertions", "=", "[", "]", "toSuite", ".", "specs", ".", "push", "(", "spec", ")", "}", ")", "}" ]
Copy specs from one suite to another. @param {Suite} fromSuite @param {Suite} toSuite @api public
[ "Copy", "specs", "from", "one", "suite", "to", "another", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L789-L794
21,034
ciaranj/connect-auth
spec/lib/jspec.js
function(string, color) { return "\u001B[" + { bold : 1, black : 30, red : 31, green : 32, yellow : 33, blue : 34, magenta : 35, cyan : 36, white : 37 }[color] + 'm' + string + "\u001B[0m" }
javascript
function(string, color) { return "\u001B[" + { bold : 1, black : 30, red : 31, green : 32, yellow : 33, blue : 34, magenta : 35, cyan : 36, white : 37 }[color] + 'm' + string + "\u001B[0m" }
[ "function", "(", "string", ",", "color", ")", "{", "return", "\"\\u001B[\"", "+", "{", "bold", ":", "1", ",", "black", ":", "30", ",", "red", ":", "31", ",", "green", ":", "32", ",", "yellow", ":", "33", ",", "blue", ":", "34", ",", "magenta", ":", "35", ",", "cyan", ":", "36", ",", "white", ":", "37", "}", "[", "color", "]", "+", "'m'", "+", "string", "+", "\"\\u001B[0m\"", "}" ]
Return ANSI-escaped colored string. @param {string} string @param {string} color @return {string} @api public
[ "Return", "ANSI", "-", "escaped", "colored", "string", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L818-L830
21,035
ciaranj/connect-auth
spec/lib/jspec.js
function(actual, expected, negate, name) { return 'expected ' + puts(actual) + ' to ' + (negate ? 'not ' : '') + name.replace(/_/g, ' ') + ' ' + (expected.length > 1 ? puts.apply(this, expected.slice(1)) : '') }
javascript
function(actual, expected, negate, name) { return 'expected ' + puts(actual) + ' to ' + (negate ? 'not ' : '') + name.replace(/_/g, ' ') + ' ' + (expected.length > 1 ? puts.apply(this, expected.slice(1)) : '') }
[ "function", "(", "actual", ",", "expected", ",", "negate", ",", "name", ")", "{", "return", "'expected '", "+", "puts", "(", "actual", ")", "+", "' to '", "+", "(", "negate", "?", "'not '", ":", "''", ")", "+", "name", ".", "replace", "(", "/", "_", "/", "g", ",", "' '", ")", "+", "' '", "+", "(", "expected", ".", "length", ">", "1", "?", "puts", ".", "apply", "(", "this", ",", "expected", ".", "slice", "(", "1", ")", ")", ":", "''", ")", "}" ]
Default matcher message callback. @api private
[ "Default", "matcher", "message", "callback", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L838-L845
21,036
ciaranj/connect-auth
spec/lib/jspec.js
function(body) { switch (body.constructor) { case String: if (captures = body.match(/^alias (\w+)/)) return JSpec.matchers[last(captures)] if (body.length < 4) body = 'actual ' + body + ' expected' return { match: function(actual, expected) { return eval(body) }} case Function: return { match: body } default: return body } }
javascript
function(body) { switch (body.constructor) { case String: if (captures = body.match(/^alias (\w+)/)) return JSpec.matchers[last(captures)] if (body.length < 4) body = 'actual ' + body + ' expected' return { match: function(actual, expected) { return eval(body) }} case Function: return { match: body } default: return body } }
[ "function", "(", "body", ")", "{", "switch", "(", "body", ".", "constructor", ")", "{", "case", "String", ":", "if", "(", "captures", "=", "body", ".", "match", "(", "/", "^alias (\\w+)", "/", ")", ")", "return", "JSpec", ".", "matchers", "[", "last", "(", "captures", ")", "]", "if", "(", "body", ".", "length", "<", "4", ")", "body", "=", "'actual '", "+", "body", "+", "' expected'", "return", "{", "match", ":", "function", "(", "actual", ",", "expected", ")", "{", "return", "eval", "(", "body", ")", "}", "}", "case", "Function", ":", "return", "{", "match", ":", "body", "}", "default", ":", "return", "body", "}", "}" ]
Normalize a matcher body This process allows the following conversions until the matcher is in its final normalized hash state. - '==' becomes 'actual == expected' - 'actual == expected' becomes 'return actual == expected' - function(actual, expected) { return actual == expected } becomes { match : function(actual, expected) { return actual == expected }} @param {mixed} body @return {hash} @api public
[ "Normalize", "a", "matcher", "body" ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L880-L893
21,037
ciaranj/connect-auth
spec/lib/jspec.js
function(key) { return (value = query(key)) !== null ? value : JSpec.options[key] || null }
javascript
function(key) { return (value = query(key)) !== null ? value : JSpec.options[key] || null }
[ "function", "(", "key", ")", "{", "return", "(", "value", "=", "query", "(", "key", ")", ")", "!==", "null", "?", "value", ":", "JSpec", ".", "options", "[", "key", "]", "||", "null", "}" ]
Get option value. This method first checks if the option key has been set via the query string, otherwise returning the options hash value. @param {string} key @return {mixed} @api public
[ "Get", "option", "value", ".", "This", "method", "first", "checks", "if", "the", "option", "key", "has", "been", "set", "via", "the", "query", "string", "otherwise", "returning", "the", "options", "hash", "value", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L905-L908
21,038
ciaranj/connect-auth
spec/lib/jspec.js
function(a, b) { if (typeof a != typeof b) return if (a === b) return true if (a instanceof RegExp) return a.toString() === b.toString() if (a instanceof Date) return Number(a) === Number(b) if (typeof a != 'object') return if (a.length !== undefined) if (a.length !== b.length) return else for (var i = 0, len = a.length; i < len; ++i) if (!equal(a[i], b[i])) return for (var key in a) if (!equal(a[key], b[key])) return return true }
javascript
function(a, b) { if (typeof a != typeof b) return if (a === b) return true if (a instanceof RegExp) return a.toString() === b.toString() if (a instanceof Date) return Number(a) === Number(b) if (typeof a != 'object') return if (a.length !== undefined) if (a.length !== b.length) return else for (var i = 0, len = a.length; i < len; ++i) if (!equal(a[i], b[i])) return for (var key in a) if (!equal(a[key], b[key])) return return true }
[ "function", "(", "a", ",", "b", ")", "{", "if", "(", "typeof", "a", "!=", "typeof", "b", ")", "return", "if", "(", "a", "===", "b", ")", "return", "true", "if", "(", "a", "instanceof", "RegExp", ")", "return", "a", ".", "toString", "(", ")", "===", "b", ".", "toString", "(", ")", "if", "(", "a", "instanceof", "Date", ")", "return", "Number", "(", "a", ")", "===", "Number", "(", "b", ")", "if", "(", "typeof", "a", "!=", "'object'", ")", "return", "if", "(", "a", ".", "length", "!==", "undefined", ")", "if", "(", "a", ".", "length", "!==", "b", ".", "length", ")", "return", "else", "for", "(", "var", "i", "=", "0", ",", "len", "=", "a", ".", "length", ";", "i", "<", "len", ";", "++", "i", ")", "if", "(", "!", "equal", "(", "a", "[", "i", "]", ",", "b", "[", "i", "]", ")", ")", "return", "for", "(", "var", "key", "in", "a", ")", "if", "(", "!", "equal", "(", "a", "[", "key", "]", ",", "b", "[", "key", "]", ")", ")", "return", "return", "true", "}" ]
Check if object _a_, is equal to object _b_. @param {object} a @param {object} b @return {bool} @api private
[ "Check", "if", "object", "_a_", "is", "equal", "to", "object", "_b_", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L919-L937
21,039
ciaranj/connect-auth
spec/lib/jspec.js
function(html) { return html.toString() .replace(/&/gmi, '&amp;') .replace(/"/gmi, '&quot;') .replace(/>/gmi, '&gt;') .replace(/</gmi, '&lt;') }
javascript
function(html) { return html.toString() .replace(/&/gmi, '&amp;') .replace(/"/gmi, '&quot;') .replace(/>/gmi, '&gt;') .replace(/</gmi, '&lt;') }
[ "function", "(", "html", ")", "{", "return", "html", ".", "toString", "(", ")", ".", "replace", "(", "/", "&", "/", "gmi", ",", "'&amp;'", ")", ".", "replace", "(", "/", "\"", "/", "gmi", ",", "'&quot;'", ")", ".", "replace", "(", "/", ">", "/", "gmi", ",", "'&gt;'", ")", ".", "replace", "(", "/", "<", "/", "gmi", ",", "'&lt;'", ")", "}" ]
Escape HTML. @param {string} html @return {string} @api public
[ "Escape", "HTML", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1003-L1009
21,040
ciaranj/connect-auth
spec/lib/jspec.js
function(actual, matcher, expected) { var assertion = new JSpec.Assertion(JSpec.matchers[matcher], actual, toArray(arguments, 2)) return assertion.run().result }
javascript
function(actual, matcher, expected) { var assertion = new JSpec.Assertion(JSpec.matchers[matcher], actual, toArray(arguments, 2)) return assertion.run().result }
[ "function", "(", "actual", ",", "matcher", ",", "expected", ")", "{", "var", "assertion", "=", "new", "JSpec", ".", "Assertion", "(", "JSpec", ".", "matchers", "[", "matcher", "]", ",", "actual", ",", "toArray", "(", "arguments", ",", "2", ")", ")", "return", "assertion", ".", "run", "(", ")", ".", "result", "}" ]
Perform an assertion without reporting. This method is primarily used for internal matchers in order retain DRYness. May be invoked like below: does('foo', 'eql', 'foo') does([1,2], 'include', 1, 2) External hooks are not run for internal assertions performed by does(). @param {mixed} actual @param {string} matcher @param {...} expected @return {mixed} @api private
[ "Perform", "an", "assertion", "without", "reporting", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1031-L1034
21,041
ciaranj/connect-auth
spec/lib/jspec.js
function(actual) { function assert(matcher, args, negate) { var expected = toArray(args, 1) matcher.negate = negate assertion = new JSpec.Assertion(matcher, actual, expected, negate) hook('beforeAssertion', assertion) if (matcher.defer) assertion.run() else JSpec.currentSpec.assertions.push(assertion.run().report()), hook('afterAssertion', assertion) return assertion.result } function to(matcher) { return assert(matcher, arguments, false) } function not_to(matcher) { return assert(matcher, arguments, true) } return { to : to, should : to, not_to: not_to, should_not : not_to } }
javascript
function(actual) { function assert(matcher, args, negate) { var expected = toArray(args, 1) matcher.negate = negate assertion = new JSpec.Assertion(matcher, actual, expected, negate) hook('beforeAssertion', assertion) if (matcher.defer) assertion.run() else JSpec.currentSpec.assertions.push(assertion.run().report()), hook('afterAssertion', assertion) return assertion.result } function to(matcher) { return assert(matcher, arguments, false) } function not_to(matcher) { return assert(matcher, arguments, true) } return { to : to, should : to, not_to: not_to, should_not : not_to } }
[ "function", "(", "actual", ")", "{", "function", "assert", "(", "matcher", ",", "args", ",", "negate", ")", "{", "var", "expected", "=", "toArray", "(", "args", ",", "1", ")", "matcher", ".", "negate", "=", "negate", "assertion", "=", "new", "JSpec", ".", "Assertion", "(", "matcher", ",", "actual", ",", "expected", ",", "negate", ")", "hook", "(", "'beforeAssertion'", ",", "assertion", ")", "if", "(", "matcher", ".", "defer", ")", "assertion", ".", "run", "(", ")", "else", "JSpec", ".", "currentSpec", ".", "assertions", ".", "push", "(", "assertion", ".", "run", "(", ")", ".", "report", "(", ")", ")", ",", "hook", "(", "'afterAssertion'", ",", "assertion", ")", "return", "assertion", ".", "result", "}", "function", "to", "(", "matcher", ")", "{", "return", "assert", "(", "matcher", ",", "arguments", ",", "false", ")", "}", "function", "not_to", "(", "matcher", ")", "{", "return", "assert", "(", "matcher", ",", "arguments", ",", "true", ")", "}", "return", "{", "to", ":", "to", ",", "should", ":", "to", ",", "not_to", ":", "not_to", ",", "should_not", ":", "not_to", "}", "}" ]
Perform an assertion. expect(true).to('be', true) expect('foo').not_to('include', 'bar') expect([1, [2]]).to('include', 1, [2]) @param {mixed} actual @return {hash} @api public
[ "Perform", "an", "assertion", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1048-L1073
21,042
ciaranj/connect-auth
spec/lib/jspec.js
function(callback, a, b) { return callback.length == 1 ? callback(b) : callback(a, b) }
javascript
function(callback, a, b) { return callback.length == 1 ? callback(b) : callback(a, b) }
[ "function", "(", "callback", ",", "a", ",", "b", ")", "{", "return", "callback", ".", "length", "==", "1", "?", "callback", "(", "b", ")", ":", "callback", "(", "a", ",", "b", ")", "}" ]
Call an iterator callback with arguments a, or b depending on the arity of the callback. @param {function} callback @param {mixed} a @param {mixed} b @return {mixed} @api private
[ "Call", "an", "iterator", "callback", "with", "arguments", "a", "or", "b", "depending", "on", "the", "arity", "of", "the", "callback", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1101-L1103
21,043
ciaranj/connect-auth
spec/lib/jspec.js
function(object, callback) { if (object.constructor == Array) for (var i = 0, len = object.length; i < len; ++i) callIterator(callback, i, object[i]) else for (var key in object) if (object.hasOwnProperty(key)) callIterator(callback, key, object[key]) }
javascript
function(object, callback) { if (object.constructor == Array) for (var i = 0, len = object.length; i < len; ++i) callIterator(callback, i, object[i]) else for (var key in object) if (object.hasOwnProperty(key)) callIterator(callback, key, object[key]) }
[ "function", "(", "object", ",", "callback", ")", "{", "if", "(", "object", ".", "constructor", "==", "Array", ")", "for", "(", "var", "i", "=", "0", ",", "len", "=", "object", ".", "length", ";", "i", "<", "len", ";", "++", "i", ")", "callIterator", "(", "callback", ",", "i", ",", "object", "[", "i", "]", ")", "else", "for", "(", "var", "key", "in", "object", ")", "if", "(", "object", ".", "hasOwnProperty", "(", "key", ")", ")", "callIterator", "(", "callback", ",", "key", ",", "object", "[", "key", "]", ")", "}" ]
Iterate an object, invoking the given callback. @param {hash, array} object @param {function} callback @return {JSpec} @api public
[ "Iterate", "an", "object", "invoking", "the", "given", "callback", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1128-L1136
21,044
ciaranj/connect-auth
spec/lib/jspec.js
function(object, memo, callback) { each(object, function(key, value){ memo = (callback.length == 2 ? callback(memo, value): callback(memo, key, value)) || memo }) return memo }
javascript
function(object, memo, callback) { each(object, function(key, value){ memo = (callback.length == 2 ? callback(memo, value): callback(memo, key, value)) || memo }) return memo }
[ "function", "(", "object", ",", "memo", ",", "callback", ")", "{", "each", "(", "object", ",", "function", "(", "key", ",", "value", ")", "{", "memo", "=", "(", "callback", ".", "length", "==", "2", "?", "callback", "(", "memo", ",", "value", ")", ":", "callback", "(", "memo", ",", "key", ",", "value", ")", ")", "||", "memo", "}", ")", "return", "memo", "}" ]
Iterate with memo. @param {hash, array} object @param {object} memo @param {function} callback @return {object} @api public
[ "Iterate", "with", "memo", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1148-L1156
21,045
ciaranj/connect-auth
spec/lib/jspec.js
function(object, method) { if (method) { if (object['__prototype__' + method]) delete object[method] else object[method] = object['__original__' + method] delete object['__prototype__' + method] delete object['__original____' + method] } else if (object) { for (var key in object) if (captures = key.match(/^(?:__prototype__|__original__)(.*)/)) destub(object, captures[1]) } else while (JSpec.stubbed.length) destub(JSpec.stubbed.shift()) }
javascript
function(object, method) { if (method) { if (object['__prototype__' + method]) delete object[method] else object[method] = object['__original__' + method] delete object['__prototype__' + method] delete object['__original____' + method] } else if (object) { for (var key in object) if (captures = key.match(/^(?:__prototype__|__original__)(.*)/)) destub(object, captures[1]) } else while (JSpec.stubbed.length) destub(JSpec.stubbed.shift()) }
[ "function", "(", "object", ",", "method", ")", "{", "if", "(", "method", ")", "{", "if", "(", "object", "[", "'__prototype__'", "+", "method", "]", ")", "delete", "object", "[", "method", "]", "else", "object", "[", "method", "]", "=", "object", "[", "'__original__'", "+", "method", "]", "delete", "object", "[", "'__prototype__'", "+", "method", "]", "delete", "object", "[", "'__original____'", "+", "method", "]", "}", "else", "if", "(", "object", ")", "{", "for", "(", "var", "key", "in", "object", ")", "if", "(", "captures", "=", "key", ".", "match", "(", "/", "^(?:__prototype__|__original__)(.*)", "/", ")", ")", "destub", "(", "object", ",", "captures", "[", "1", "]", ")", "}", "else", "while", "(", "JSpec", ".", "stubbed", ".", "length", ")", "destub", "(", "JSpec", ".", "stubbed", ".", "shift", "(", ")", ")", "}" ]
Destub _object_'s _method_. When no _method_ is passed all stubbed methods are destubbed. When no arguments are passed every object found in JSpec.stubbed will be destubbed. @param {mixed} object @param {string} method @api public
[ "Destub", "_object_", "s", "_method_", ".", "When", "no", "_method_", "is", "passed", "all", "stubbed", "methods", "are", "destubbed", ".", "When", "no", "arguments", "are", "passed", "every", "object", "found", "in", "JSpec", ".", "stubbed", "will", "be", "destubbed", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1169-L1186
21,046
ciaranj/connect-auth
spec/lib/jspec.js
function(object, method) { hook('stubbing', object, method) JSpec.stubbed.push(object) var type = object.hasOwnProperty(method) ? '__original__' : '__prototype__' object[type + method] = object[method] object[method] = function(){} return { and_return : function(value) { if (typeof value == 'function') object[method] = value else object[method] = function(){ return value } } } }
javascript
function(object, method) { hook('stubbing', object, method) JSpec.stubbed.push(object) var type = object.hasOwnProperty(method) ? '__original__' : '__prototype__' object[type + method] = object[method] object[method] = function(){} return { and_return : function(value) { if (typeof value == 'function') object[method] = value else object[method] = function(){ return value } } } }
[ "function", "(", "object", ",", "method", ")", "{", "hook", "(", "'stubbing'", ",", "object", ",", "method", ")", "JSpec", ".", "stubbed", ".", "push", "(", "object", ")", "var", "type", "=", "object", ".", "hasOwnProperty", "(", "method", ")", "?", "'__original__'", ":", "'__prototype__'", "object", "[", "type", "+", "method", "]", "=", "object", "[", "method", "]", "object", "[", "method", "]", "=", "function", "(", ")", "{", "}", "return", "{", "and_return", ":", "function", "(", "value", ")", "{", "if", "(", "typeof", "value", "==", "'function'", ")", "object", "[", "method", "]", "=", "value", "else", "object", "[", "method", "]", "=", "function", "(", ")", "{", "return", "value", "}", "}", "}", "}" ]
Stub _object_'s _method_. stub(foo, 'toString').and_return('bar') @param {mixed} object @param {string} method @return {hash} @api public
[ "Stub", "_object_", "s", "_method_", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1199-L1211
21,047
ciaranj/connect-auth
spec/lib/jspec.js
function(object, callback) { return inject(object, [], function(memo, key, value){ memo.push(callIterator(callback, key, value)) }) }
javascript
function(object, callback) { return inject(object, [], function(memo, key, value){ memo.push(callIterator(callback, key, value)) }) }
[ "function", "(", "object", ",", "callback", ")", "{", "return", "inject", "(", "object", ",", "[", "]", ",", "function", "(", "memo", ",", "key", ",", "value", ")", "{", "memo", ".", "push", "(", "callIterator", "(", "callback", ",", "key", ",", "value", ")", ")", "}", ")", "}" ]
Map callback return values. @param {hash, array} object @param {function} callback @return {array} @api public
[ "Map", "callback", "return", "values", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1222-L1226
21,048
ciaranj/connect-auth
spec/lib/jspec.js
function(object, callback) { return inject(object, null, function(state, key, value){ if (state == undefined) return callIterator(callback, key, value) ? value : state }) }
javascript
function(object, callback) { return inject(object, null, function(state, key, value){ if (state == undefined) return callIterator(callback, key, value) ? value : state }) }
[ "function", "(", "object", ",", "callback", ")", "{", "return", "inject", "(", "object", ",", "null", ",", "function", "(", "state", ",", "key", ",", "value", ")", "{", "if", "(", "state", "==", "undefined", ")", "return", "callIterator", "(", "callback", ",", "key", ",", "value", ")", "?", "value", ":", "state", "}", ")", "}" ]
Returns the first matching expression or null. @param {hash, array} object @param {function} callback @return {mixed} @api public
[ "Returns", "the", "first", "matching", "expression", "or", "null", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1237-L1242
21,049
ciaranj/connect-auth
spec/lib/jspec.js
function(object, callback) { return inject(object, [], function(selected, key, value){ if (callIterator(callback, key, value)) selected.push(value) }) }
javascript
function(object, callback) { return inject(object, [], function(selected, key, value){ if (callIterator(callback, key, value)) selected.push(value) }) }
[ "function", "(", "object", ",", "callback", ")", "{", "return", "inject", "(", "object", ",", "[", "]", ",", "function", "(", "selected", ",", "key", ",", "value", ")", "{", "if", "(", "callIterator", "(", "callback", ",", "key", ",", "value", ")", ")", "selected", ".", "push", "(", "value", ")", "}", ")", "}" ]
Returns an array of values collected when the callback given evaluates to true. @param {hash, array} object @return {function} callback @return {array} @api public
[ "Returns", "an", "array", "of", "values", "collected", "when", "the", "callback", "given", "evaluates", "to", "true", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1254-L1259
21,050
ciaranj/connect-auth
spec/lib/jspec.js
function(name, body) { hook('addingMatcher', name, body) if (name.indexOf(' ') != -1) { var matchers = name.split(/\s+/) var prefix = matchers.shift() each(matchers, function(name) { JSpec.addMatcher(prefix + '_' + name, body(name)) }) } this.matchers[name] = this.normalizeMatcherMessage(this.normalizeMatcherBody(body)) this.matchers[name].name = name }
javascript
function(name, body) { hook('addingMatcher', name, body) if (name.indexOf(' ') != -1) { var matchers = name.split(/\s+/) var prefix = matchers.shift() each(matchers, function(name) { JSpec.addMatcher(prefix + '_' + name, body(name)) }) } this.matchers[name] = this.normalizeMatcherMessage(this.normalizeMatcherBody(body)) this.matchers[name].name = name }
[ "function", "(", "name", ",", "body", ")", "{", "hook", "(", "'addingMatcher'", ",", "name", ",", "body", ")", "if", "(", "name", ".", "indexOf", "(", "' '", ")", "!=", "-", "1", ")", "{", "var", "matchers", "=", "name", ".", "split", "(", "/", "\\s+", "/", ")", "var", "prefix", "=", "matchers", ".", "shift", "(", ")", "each", "(", "matchers", ",", "function", "(", "name", ")", "{", "JSpec", ".", "addMatcher", "(", "prefix", "+", "'_'", "+", "name", ",", "body", "(", "name", ")", ")", "}", ")", "}", "this", ".", "matchers", "[", "name", "]", "=", "this", ".", "normalizeMatcherMessage", "(", "this", ".", "normalizeMatcherBody", "(", "body", ")", ")", "this", ".", "matchers", "[", "name", "]", ".", "name", "=", "name", "}" ]
Define a matcher. @param {string} name @param {hash, function, string} body @api public
[ "Define", "a", "matcher", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1282-L1293
21,051
ciaranj/connect-auth
spec/lib/jspec.js
function(description, body) { var suite = new JSpec.Suite(description, body) hook('addingSuite', suite) this.allSuites.push(suite) this.suites.push(suite) }
javascript
function(description, body) { var suite = new JSpec.Suite(description, body) hook('addingSuite', suite) this.allSuites.push(suite) this.suites.push(suite) }
[ "function", "(", "description", ",", "body", ")", "{", "var", "suite", "=", "new", "JSpec", ".", "Suite", "(", "description", ",", "body", ")", "hook", "(", "'addingSuite'", ",", "suite", ")", "this", ".", "allSuites", ".", "push", "(", "suite", ")", "this", ".", "suites", ".", "push", "(", "suite", ")", "}" ]
Add a root suite to JSpec. @param {string} description @param {body} function @api public
[ "Add", "a", "root", "suite", "to", "JSpec", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1303-L1308
21,052
ciaranj/connect-auth
spec/lib/jspec.js
function(body, errorMessage) { var dsl = this.DSL || this.DSLs.snake var matchers = this.matchers var context = this.context || this.defaultContext var contents = this.contentsOf(body) hook('evaluatingBody', dsl, matchers, context, contents) try { with (dsl){ with (context) { with (matchers) { eval(contents) }}} } catch(e) { error(errorMessage, e) } }
javascript
function(body, errorMessage) { var dsl = this.DSL || this.DSLs.snake var matchers = this.matchers var context = this.context || this.defaultContext var contents = this.contentsOf(body) hook('evaluatingBody', dsl, matchers, context, contents) try { with (dsl){ with (context) { with (matchers) { eval(contents) }}} } catch(e) { error(errorMessage, e) } }
[ "function", "(", "body", ",", "errorMessage", ")", "{", "var", "dsl", "=", "this", ".", "DSL", "||", "this", ".", "DSLs", ".", "snake", "var", "matchers", "=", "this", ".", "matchers", "var", "context", "=", "this", ".", "context", "||", "this", ".", "defaultContext", "var", "contents", "=", "this", ".", "contentsOf", "(", "body", ")", "hook", "(", "'evaluatingBody'", ",", "dsl", ",", "matchers", ",", "context", ",", "contents", ")", "try", "{", "with", "(", "dsl", ")", "{", "with", "(", "context", ")", "{", "with", "(", "matchers", ")", "{", "eval", "(", "contents", ")", "}", "}", "}", "}", "catch", "(", "e", ")", "{", "error", "(", "errorMessage", ",", "e", ")", "}", "}" ]
Evaluate a JSpec capture body. @param {function} body @param {string} errorMessage (optional) @return {Type} @api private
[ "Evaluate", "a", "JSpec", "capture", "body", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1331-L1339
21,053
ciaranj/connect-auth
spec/lib/jspec.js
function(input) { if (typeof input != 'string') return input = hookImmutable('preprocessing', input) return input. replace(/\t/g, ' '). replace(/\r\n|\n|\r/g, '\n'). split('__END__')[0]. replace(/([\w\.]+)\.(stub|destub)\((.*?)\)$/gm, '$2($1, $3)'). replace(/describe\s+(.*?)$/gm, 'describe($1, function(){'). replace(/^\s+it\s+(.*?)$/gm, ' it($1, function(){'). replace(/^ *(before_each|after_each|before|after)(?= |\n|$)/gm, 'JSpec.currentSuite.addHook("$1", function(){'). replace(/^\s*end(?=\s|$)/gm, '});'). replace(/-\{/g, 'function(){'). replace(/(\d+)\.\.(\d+)/g, function(_, a, b){ return range(a, b) }). replace(/\.should([_\.]not)?[_\.](\w+)(?: |;|$)(.*)$/gm, '.should$1_$2($3)'). replace(/([\/\s]*)(.+?)\.(should(?:[_\.]not)?)[_\.](\w+)\((.*)\)\s*;?$/gm, '$1 expect($2).$3($4, $5)'). replace(/, \)/g, ')'). replace(/should\.not/g, 'should_not') }
javascript
function(input) { if (typeof input != 'string') return input = hookImmutable('preprocessing', input) return input. replace(/\t/g, ' '). replace(/\r\n|\n|\r/g, '\n'). split('__END__')[0]. replace(/([\w\.]+)\.(stub|destub)\((.*?)\)$/gm, '$2($1, $3)'). replace(/describe\s+(.*?)$/gm, 'describe($1, function(){'). replace(/^\s+it\s+(.*?)$/gm, ' it($1, function(){'). replace(/^ *(before_each|after_each|before|after)(?= |\n|$)/gm, 'JSpec.currentSuite.addHook("$1", function(){'). replace(/^\s*end(?=\s|$)/gm, '});'). replace(/-\{/g, 'function(){'). replace(/(\d+)\.\.(\d+)/g, function(_, a, b){ return range(a, b) }). replace(/\.should([_\.]not)?[_\.](\w+)(?: |;|$)(.*)$/gm, '.should$1_$2($3)'). replace(/([\/\s]*)(.+?)\.(should(?:[_\.]not)?)[_\.](\w+)\((.*)\)\s*;?$/gm, '$1 expect($2).$3($4, $5)'). replace(/, \)/g, ')'). replace(/should\.not/g, 'should_not') }
[ "function", "(", "input", ")", "{", "if", "(", "typeof", "input", "!=", "'string'", ")", "return", "input", "=", "hookImmutable", "(", "'preprocessing'", ",", "input", ")", "return", "input", ".", "replace", "(", "/", "\\t", "/", "g", ",", "' '", ")", ".", "replace", "(", "/", "\\r\\n|\\n|\\r", "/", "g", ",", "'\\n'", ")", ".", "split", "(", "'__END__'", ")", "[", "0", "]", ".", "replace", "(", "/", "([\\w\\.]+)\\.(stub|destub)\\((.*?)\\)$", "/", "gm", ",", "'$2($1, $3)'", ")", ".", "replace", "(", "/", "describe\\s+(.*?)$", "/", "gm", ",", "'describe($1, function(){'", ")", ".", "replace", "(", "/", "^\\s+it\\s+(.*?)$", "/", "gm", ",", "' it($1, function(){'", ")", ".", "replace", "(", "/", "^ *(before_each|after_each|before|after)(?= |\\n|$)", "/", "gm", ",", "'JSpec.currentSuite.addHook(\"$1\", function(){'", ")", ".", "replace", "(", "/", "^\\s*end(?=\\s|$)", "/", "gm", ",", "'});'", ")", ".", "replace", "(", "/", "-\\{", "/", "g", ",", "'function(){'", ")", ".", "replace", "(", "/", "(\\d+)\\.\\.(\\d+)", "/", "g", ",", "function", "(", "_", ",", "a", ",", "b", ")", "{", "return", "range", "(", "a", ",", "b", ")", "}", ")", ".", "replace", "(", "/", "\\.should([_\\.]not)?[_\\.](\\w+)(?: |;|$)(.*)$", "/", "gm", ",", "'.should$1_$2($3)'", ")", ".", "replace", "(", "/", "([\\/\\s]*)(.+?)\\.(should(?:[_\\.]not)?)[_\\.](\\w+)\\((.*)\\)\\s*;?$", "/", "gm", ",", "'$1 expect($2).$3($4, $5)'", ")", ".", "replace", "(", "/", ", \\)", "/", "g", ",", "')'", ")", ".", "replace", "(", "/", "should\\.not", "/", "g", ",", "'should_not'", ")", "}" ]
Pre-process a string of JSpec. @param {string} input @return {string} @api private
[ "Pre", "-", "process", "a", "string", "of", "JSpec", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1349-L1367
21,054
ciaranj/connect-auth
spec/lib/jspec.js
function(start, end) { var current = parseInt(start), end = parseInt(end), values = [current] if (end > current) while (++current <= end) values.push(current) else while (--current >= end) values.push(current) return '[' + values + ']' }
javascript
function(start, end) { var current = parseInt(start), end = parseInt(end), values = [current] if (end > current) while (++current <= end) values.push(current) else while (--current >= end) values.push(current) return '[' + values + ']' }
[ "function", "(", "start", ",", "end", ")", "{", "var", "current", "=", "parseInt", "(", "start", ")", ",", "end", "=", "parseInt", "(", "end", ")", ",", "values", "=", "[", "current", "]", "if", "(", "end", ">", "current", ")", "while", "(", "++", "current", "<=", "end", ")", "values", ".", "push", "(", "current", ")", "else", "while", "(", "--", "current", ">=", "end", ")", "values", ".", "push", "(", "current", ")", "return", "'['", "+", "values", "+", "']'", "}" ]
Create a range string which can be evaluated to a native array. @param {int} start @param {int} end @return {string} @api public
[ "Create", "a", "range", "string", "which", "can", "be", "evaluated", "to", "a", "native", "array", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1378-L1383
21,055
ciaranj/connect-auth
spec/lib/jspec.js
function() { this.duration = Number(new Date) - this.start hook('reporting', JSpec.options) new (JSpec.options.reporter || JSpec.reporters.DOM)(JSpec, JSpec.options) }
javascript
function() { this.duration = Number(new Date) - this.start hook('reporting', JSpec.options) new (JSpec.options.reporter || JSpec.reporters.DOM)(JSpec, JSpec.options) }
[ "function", "(", ")", "{", "this", ".", "duration", "=", "Number", "(", "new", "Date", ")", "-", "this", ".", "start", "hook", "(", "'reporting'", ",", "JSpec", ".", "options", ")", "new", "(", "JSpec", ".", "options", ".", "reporter", "||", "JSpec", ".", "reporters", ".", "DOM", ")", "(", "JSpec", ",", "JSpec", ".", "options", ")", "}" ]
Report on the results. @api public
[ "Report", "on", "the", "results", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1391-L1395
21,056
ciaranj/connect-auth
spec/lib/jspec.js
function(options) { if (any(hook('running'), haveStopped)) return this if (options) extend(this.options, options) this.start = Number(new Date) each(this.suites, function(suite) { JSpec.runSuite(suite) }) return this }
javascript
function(options) { if (any(hook('running'), haveStopped)) return this if (options) extend(this.options, options) this.start = Number(new Date) each(this.suites, function(suite) { JSpec.runSuite(suite) }) return this }
[ "function", "(", "options", ")", "{", "if", "(", "any", "(", "hook", "(", "'running'", ")", ",", "haveStopped", ")", ")", "return", "this", "if", "(", "options", ")", "extend", "(", "this", ".", "options", ",", "options", ")", "this", ".", "start", "=", "Number", "(", "new", "Date", ")", "each", "(", "this", ".", "suites", ",", "function", "(", "suite", ")", "{", "JSpec", ".", "runSuite", "(", "suite", ")", "}", ")", "return", "this", "}" ]
Run the spec suites. Options are merged with JSpec options when present. @param {hash} options @return {JSpec} @api public
[ "Run", "the", "spec", "suites", ".", "Options", "are", "merged", "with", "JSpec", "options", "when", "present", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1406-L1412
21,057
ciaranj/connect-auth
spec/lib/jspec.js
function(suite) { this.currentSuite = suite this.evalBody(suite.body) suite.ran = true hook('beforeSuite', suite), suite.hook('before') each(suite.specs, function(spec) { hook('beforeSpec', spec) suite.hook('before_each') JSpec.runSpec(spec) hook('afterSpec', spec) suite.hook('after_each') }) if (suite.hasSuites()) { each(suite.suites, function(suite) { JSpec.runSuite(suite) }) } hook('afterSuite', suite), suite.hook('after') this.stats.suitesFinished++ }
javascript
function(suite) { this.currentSuite = suite this.evalBody(suite.body) suite.ran = true hook('beforeSuite', suite), suite.hook('before') each(suite.specs, function(spec) { hook('beforeSpec', spec) suite.hook('before_each') JSpec.runSpec(spec) hook('afterSpec', spec) suite.hook('after_each') }) if (suite.hasSuites()) { each(suite.suites, function(suite) { JSpec.runSuite(suite) }) } hook('afterSuite', suite), suite.hook('after') this.stats.suitesFinished++ }
[ "function", "(", "suite", ")", "{", "this", ".", "currentSuite", "=", "suite", "this", ".", "evalBody", "(", "suite", ".", "body", ")", "suite", ".", "ran", "=", "true", "hook", "(", "'beforeSuite'", ",", "suite", ")", ",", "suite", ".", "hook", "(", "'before'", ")", "each", "(", "suite", ".", "specs", ",", "function", "(", "spec", ")", "{", "hook", "(", "'beforeSpec'", ",", "spec", ")", "suite", ".", "hook", "(", "'before_each'", ")", "JSpec", ".", "runSpec", "(", "spec", ")", "hook", "(", "'afterSpec'", ",", "spec", ")", "suite", ".", "hook", "(", "'after_each'", ")", "}", ")", "if", "(", "suite", ".", "hasSuites", "(", ")", ")", "{", "each", "(", "suite", ".", "suites", ",", "function", "(", "suite", ")", "{", "JSpec", ".", "runSuite", "(", "suite", ")", "}", ")", "}", "hook", "(", "'afterSuite'", ",", "suite", ")", ",", "suite", ".", "hook", "(", "'after'", ")", "this", ".", "stats", ".", "suitesFinished", "++", "}" ]
Run a suite. @param {Suite} suite @api public
[ "Run", "a", "suite", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1421-L1440
21,058
ciaranj/connect-auth
spec/lib/jspec.js
function(spec) { this.currentSpec = spec try { this.evalBody(spec.body) } catch (e) { fail(e) } spec.runDeferredAssertions() destub() this.stats.specsFinished++ this.stats.assertions += spec.assertions.length }
javascript
function(spec) { this.currentSpec = spec try { this.evalBody(spec.body) } catch (e) { fail(e) } spec.runDeferredAssertions() destub() this.stats.specsFinished++ this.stats.assertions += spec.assertions.length }
[ "function", "(", "spec", ")", "{", "this", ".", "currentSpec", "=", "spec", "try", "{", "this", ".", "evalBody", "(", "spec", ".", "body", ")", "}", "catch", "(", "e", ")", "{", "fail", "(", "e", ")", "}", "spec", ".", "runDeferredAssertions", "(", ")", "destub", "(", ")", "this", ".", "stats", ".", "specsFinished", "++", "this", ".", "stats", ".", "assertions", "+=", "spec", ".", "assertions", ".", "length", "}" ]
Run a spec. @param {Spec} spec @api public
[ "Run", "a", "spec", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1471-L1479
21,059
ciaranj/connect-auth
spec/lib/jspec.js
function(dependency, message) { hook('requiring', dependency, message) try { eval(dependency) } catch (e) { throw 'JSpec depends on ' + dependency + ' ' + message } return this }
javascript
function(dependency, message) { hook('requiring', dependency, message) try { eval(dependency) } catch (e) { throw 'JSpec depends on ' + dependency + ' ' + message } return this }
[ "function", "(", "dependency", ",", "message", ")", "{", "hook", "(", "'requiring'", ",", "dependency", ",", "message", ")", "try", "{", "eval", "(", "dependency", ")", "}", "catch", "(", "e", ")", "{", "throw", "'JSpec depends on '", "+", "dependency", "+", "' '", "+", "message", "}", "return", "this", "}" ]
Require a dependency, with optional message. @param {string} dependency @param {string} message (optional) @return {JSpec} @api public
[ "Require", "a", "dependency", "with", "optional", "message", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1490-L1495
21,060
ciaranj/connect-auth
spec/lib/jspec.js
function(key, queryString) { var queryString = (queryString || (main.location ? main.location.search : null) || '').substring(1) return inject(queryString.split('&'), null, function(value, pair){ parts = pair.split('=') return parts[0] == key ? parts[1].replace(/%20|\+/gmi, ' ') : value }) }
javascript
function(key, queryString) { var queryString = (queryString || (main.location ? main.location.search : null) || '').substring(1) return inject(queryString.split('&'), null, function(value, pair){ parts = pair.split('=') return parts[0] == key ? parts[1].replace(/%20|\+/gmi, ' ') : value }) }
[ "function", "(", "key", ",", "queryString", ")", "{", "var", "queryString", "=", "(", "queryString", "||", "(", "main", ".", "location", "?", "main", ".", "location", ".", "search", ":", "null", ")", "||", "''", ")", ".", "substring", "(", "1", ")", "return", "inject", "(", "queryString", ".", "split", "(", "'&'", ")", ",", "null", ",", "function", "(", "value", ",", "pair", ")", "{", "parts", "=", "pair", ".", "split", "(", "'='", ")", "return", "parts", "[", "0", "]", "==", "key", "?", "parts", "[", "1", "]", ".", "replace", "(", "/", "%20|\\+", "/", "gmi", ",", "' '", ")", ":", "value", "}", ")", "}" ]
Query against the current query strings keys or the queryString specified. @param {string} key @param {string} queryString @return {string, null} @api private
[ "Query", "against", "the", "current", "query", "strings", "keys", "or", "the", "queryString", "specified", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1507-L1513
21,061
ciaranj/connect-auth
spec/lib/jspec.js
function(message, e) { if ('stack' in e) require('util').puts(e.stack + '\n') throw (message ? message : '') + e.toString() + (e.line ? ' near line ' + e.line : '') }
javascript
function(message, e) { if ('stack' in e) require('util').puts(e.stack + '\n') throw (message ? message : '') + e.toString() + (e.line ? ' near line ' + e.line : '') }
[ "function", "(", "message", ",", "e", ")", "{", "if", "(", "'stack'", "in", "e", ")", "require", "(", "'util'", ")", ".", "puts", "(", "e", ".", "stack", "+", "'\\n'", ")", "throw", "(", "message", "?", "message", ":", "''", ")", "+", "e", ".", "toString", "(", ")", "+", "(", "e", ".", "line", "?", "' near line '", "+", "e", ".", "line", ":", "''", ")", "}" ]
Throw a JSpec related error. @param {string} message @param {Exception} e @api public
[ "Throw", "a", "JSpec", "related", "error", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1523-L1528
21,062
ciaranj/connect-auth
spec/lib/jspec.js
function(uri, data) { if (any(hook('posting', uri, data), haveStopped)) return var request = this.xhr() request.open('POST', uri, false) request.setRequestHeader('Content-Type', 'application/json') request.send(JSpec.JSON.encode(data)) }
javascript
function(uri, data) { if (any(hook('posting', uri, data), haveStopped)) return var request = this.xhr() request.open('POST', uri, false) request.setRequestHeader('Content-Type', 'application/json') request.send(JSpec.JSON.encode(data)) }
[ "function", "(", "uri", ",", "data", ")", "{", "if", "(", "any", "(", "hook", "(", "'posting'", ",", "uri", ",", "data", ")", ",", "haveStopped", ")", ")", "return", "var", "request", "=", "this", ".", "xhr", "(", ")", "request", ".", "open", "(", "'POST'", ",", "uri", ",", "false", ")", "request", ".", "setRequestHeader", "(", "'Content-Type'", ",", "'application/json'", ")", "request", ".", "send", "(", "JSpec", ".", "JSON", ".", "encode", "(", "data", ")", ")", "}" ]
Ad-hoc POST request for JSpec server usage. @param {string} uri @param {string} data @api private
[ "Ad", "-", "hoc", "POST", "request", "for", "JSpec", "server", "usage", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1538-L1544
21,063
ciaranj/connect-auth
spec/lib/jspec.js
function(file, callback) { if (any(hook('loading', file), haveStopped)) return if ('readFile' in main) return readFile(file) else if (this.hasXhr()) { var request = this.xhr() request.open('GET', file, false) request.send(null) if (request.readyState == 4 && (request.status == 0 || request.status.toString().charAt(0) == 2)) return request.responseText } else error("failed to load `" + file + "'") }
javascript
function(file, callback) { if (any(hook('loading', file), haveStopped)) return if ('readFile' in main) return readFile(file) else if (this.hasXhr()) { var request = this.xhr() request.open('GET', file, false) request.send(null) if (request.readyState == 4 && (request.status == 0 || request.status.toString().charAt(0) == 2)) return request.responseText } else error("failed to load `" + file + "'") }
[ "function", "(", "file", ",", "callback", ")", "{", "if", "(", "any", "(", "hook", "(", "'loading'", ",", "file", ")", ",", "haveStopped", ")", ")", "return", "if", "(", "'readFile'", "in", "main", ")", "return", "readFile", "(", "file", ")", "else", "if", "(", "this", ".", "hasXhr", "(", ")", ")", "{", "var", "request", "=", "this", ".", "xhr", "(", ")", "request", ".", "open", "(", "'GET'", ",", "file", ",", "false", ")", "request", ".", "send", "(", "null", ")", "if", "(", "request", ".", "readyState", "==", "4", "&&", "(", "request", ".", "status", "==", "0", "||", "request", ".", "status", ".", "toString", "(", ")", ".", "charAt", "(", "0", ")", "==", "2", ")", ")", "return", "request", ".", "responseText", "}", "else", "error", "(", "\"failed to load `\"", "+", "file", "+", "\"'\"", ")", "}" ]
Load a _file_'s contents. @param {string} file @param {function} callback @return {string} @api public
[ "Load", "a", "_file_", "s", "contents", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.js#L1611-L1626
21,064
ciaranj/connect-auth
spec/lib/jspec.xhr.js
function(method, url, async, user, password) { this.user = user this.password = password this.url = url this.readyState = 1 this.method = method.toUpperCase() if (async != undefined) this.async = async if (this.async) this.onreadystatechange() }
javascript
function(method, url, async, user, password) { this.user = user this.password = password this.url = url this.readyState = 1 this.method = method.toUpperCase() if (async != undefined) this.async = async if (this.async) this.onreadystatechange() }
[ "function", "(", "method", ",", "url", ",", "async", ",", "user", ",", "password", ")", "{", "this", ".", "user", "=", "user", "this", ".", "password", "=", "password", "this", ".", "url", "=", "url", "this", ".", "readyState", "=", "1", "this", ".", "method", "=", "method", ".", "toUpperCase", "(", ")", "if", "(", "async", "!=", "undefined", ")", "this", ".", "async", "=", "async", "if", "(", "this", ".", "async", ")", "this", ".", "onreadystatechange", "(", ")", "}" ]
Open mock request.
[ "Open", "mock", "request", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.xhr.js#L57-L65
21,065
ciaranj/connect-auth
spec/lib/jspec.xhr.js
function(data) { var self = this this.data = data this.readyState = 4 if (this.method == 'HEAD') this.responseText = null this.responseHeaders['content-length'] = (this.responseText || '').length if(this.async) this.onreadystatechange() lastRequest = function(){ return self } }
javascript
function(data) { var self = this this.data = data this.readyState = 4 if (this.method == 'HEAD') this.responseText = null this.responseHeaders['content-length'] = (this.responseText || '').length if(this.async) this.onreadystatechange() lastRequest = function(){ return self } }
[ "function", "(", "data", ")", "{", "var", "self", "=", "this", "this", ".", "data", "=", "data", "this", ".", "readyState", "=", "4", "if", "(", "this", ".", "method", "==", "'HEAD'", ")", "this", ".", "responseText", "=", "null", "this", ".", "responseHeaders", "[", "'content-length'", "]", "=", "(", "this", ".", "responseText", "||", "''", ")", ".", "length", "if", "(", "this", ".", "async", ")", "this", ".", "onreadystatechange", "(", ")", "lastRequest", "=", "function", "(", ")", "{", "return", "self", "}", "}" ]
Send request _data_.
[ "Send", "request", "_data_", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.xhr.js#L71-L81
21,066
ciaranj/connect-auth
spec/lib/jspec.xhr.js
mockRequest
function mockRequest() { return { and_return : function(body, type, status, headers) { XMLHttpRequest = MockXMLHttpRequest ActiveXObject = false status = status || 200 headers = headers || {} headers['content-type'] = type JSpec.extend(XMLHttpRequest.prototype, { responseText: body, responseHeaders: headers, status: status, statusText: JSpec.statusCodes[status] }) }} }
javascript
function mockRequest() { return { and_return : function(body, type, status, headers) { XMLHttpRequest = MockXMLHttpRequest ActiveXObject = false status = status || 200 headers = headers || {} headers['content-type'] = type JSpec.extend(XMLHttpRequest.prototype, { responseText: body, responseHeaders: headers, status: status, statusText: JSpec.statusCodes[status] }) }} }
[ "function", "mockRequest", "(", ")", "{", "return", "{", "and_return", ":", "function", "(", "body", ",", "type", ",", "status", ",", "headers", ")", "{", "XMLHttpRequest", "=", "MockXMLHttpRequest", "ActiveXObject", "=", "false", "status", "=", "status", "||", "200", "headers", "=", "headers", "||", "{", "}", "headers", "[", "'content-type'", "]", "=", "type", "JSpec", ".", "extend", "(", "XMLHttpRequest", ".", "prototype", ",", "{", "responseText", ":", "body", ",", "responseHeaders", ":", "headers", ",", "status", ":", "status", ",", "statusText", ":", "JSpec", ".", "statusCodes", "[", "status", "]", "}", ")", "}", "}", "}" ]
Mock XMLHttpRequest requests. mockRequest().and_return('some data', 'text/plain', 200, { 'X-SomeHeader' : 'somevalue' }) @return {hash} @api public
[ "Mock", "XMLHttpRequest", "requests", "." ]
9b7c06461f58309136bace9c1abe9709dfb763f6
https://github.com/ciaranj/connect-auth/blob/9b7c06461f58309136bace9c1abe9709dfb763f6/spec/lib/jspec.xhr.js#L139-L153
21,067
documentcloud/underscore-contrib
dist/underscore-contrib.js
function() { return _.reduce(arguments, function(acc, elem) { if (_.isArguments(elem)) { return concat.call(acc, slice.call(elem)); } else { return concat.call(acc, elem); } }, []); }
javascript
function() { return _.reduce(arguments, function(acc, elem) { if (_.isArguments(elem)) { return concat.call(acc, slice.call(elem)); } else { return concat.call(acc, elem); } }, []); }
[ "function", "(", ")", "{", "return", "_", ".", "reduce", "(", "arguments", ",", "function", "(", "acc", ",", "elem", ")", "{", "if", "(", "_", ".", "isArguments", "(", "elem", ")", ")", "{", "return", "concat", ".", "call", "(", "acc", ",", "slice", ".", "call", "(", "elem", ")", ")", ";", "}", "else", "{", "return", "concat", ".", "call", "(", "acc", ",", "elem", ")", ";", "}", "}", ",", "[", "]", ")", ";", "}" ]
Concatenates one or more arrays given as arguments. If given objects and scalars as arguments `cat` will plop them down in place in the result array. If given an `arguments` object, `cat` will treat it like an array and concatenate it likewise.
[ "Concatenates", "one", "or", "more", "arrays", "given", "as", "arguments", ".", "If", "given", "objects", "and", "scalars", "as", "arguments", "cat", "will", "plop", "them", "down", "in", "place", "in", "the", "result", "array", ".", "If", "given", "an", "arguments", "object", "cat", "will", "treat", "it", "like", "an", "array", "and", "concatenate", "it", "likewise", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L37-L46
21,068
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, n, pad) { var p = function(array) { if (array == null) return []; var part = _.take(array, n); if (n === _.size(part)) { return _.cons(part, p(_.drop(array, n))); } else { return pad ? [_.take(_.cat(part, pad), n)] : []; } }; return p(array); }
javascript
function(array, n, pad) { var p = function(array) { if (array == null) return []; var part = _.take(array, n); if (n === _.size(part)) { return _.cons(part, p(_.drop(array, n))); } else { return pad ? [_.take(_.cat(part, pad), n)] : []; } }; return p(array); }
[ "function", "(", "array", ",", "n", ",", "pad", ")", "{", "var", "p", "=", "function", "(", "array", ")", "{", "if", "(", "array", "==", "null", ")", "return", "[", "]", ";", "var", "part", "=", "_", ".", "take", "(", "array", ",", "n", ")", ";", "if", "(", "n", "===", "_", ".", "size", "(", "part", ")", ")", "{", "return", "_", ".", "cons", "(", "part", ",", "p", "(", "_", ".", "drop", "(", "array", ",", "n", ")", ")", ")", ";", "}", "else", "{", "return", "pad", "?", "[", "_", ".", "take", "(", "_", ".", "cat", "(", "part", ",", "pad", ")", ",", "n", ")", "]", ":", "[", "]", ";", "}", "}", ";", "return", "p", "(", "array", ")", ";", "}" ]
Takes an array and chunks it some number of times into sub-arrays of size n. Allows and optional padding array as the third argument to fill in the tail chunk when n is not sufficient to build chunks of the same size.
[ "Takes", "an", "array", "and", "chunks", "it", "some", "number", "of", "times", "into", "sub", "-", "arrays", "of", "size", "n", ".", "Allows", "and", "optional", "padding", "array", "as", "the", "third", "argument", "to", "fill", "in", "the", "tail", "chunk", "when", "n", "is", "not", "sufficient", "to", "build", "chunks", "of", "the", "same", "size", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L57-L72
21,069
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, n, step) { step = (step != null) ? step : n; var p = function(array, n, step) { if (_.isEmpty(array)) return []; return _.cons(_.take(array, n), p(_.drop(array, step), n, step)); }; return p(array, n, step); }
javascript
function(array, n, step) { step = (step != null) ? step : n; var p = function(array, n, step) { if (_.isEmpty(array)) return []; return _.cons(_.take(array, n), p(_.drop(array, step), n, step)); }; return p(array, n, step); }
[ "function", "(", "array", ",", "n", ",", "step", ")", "{", "step", "=", "(", "step", "!=", "null", ")", "?", "step", ":", "n", ";", "var", "p", "=", "function", "(", "array", ",", "n", ",", "step", ")", "{", "if", "(", "_", ".", "isEmpty", "(", "array", ")", ")", "return", "[", "]", ";", "return", "_", ".", "cons", "(", "_", ".", "take", "(", "array", ",", "n", ")", ",", "p", "(", "_", ".", "drop", "(", "array", ",", "step", ")", ",", "n", ",", "step", ")", ")", ";", "}", ";", "return", "p", "(", "array", ",", "n", ",", "step", ")", ";", "}" ]
Takes an array and chunks it some number of times into sub-arrays of size n. If the array given cannot fill the size needs of the final chunk then a smaller chunk is used for the last.
[ "Takes", "an", "array", "and", "chunks", "it", "some", "number", "of", "times", "into", "sub", "-", "arrays", "of", "size", "n", ".", "If", "the", "array", "given", "cannot", "fill", "the", "size", "needs", "of", "the", "final", "chunk", "then", "a", "smaller", "chunk", "is", "used", "for", "the", "last", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L78-L89
21,070
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, fun) { return _.cat.apply(null, _.map(array, fun)); }
javascript
function(array, fun) { return _.cat.apply(null, _.map(array, fun)); }
[ "function", "(", "array", ",", "fun", ")", "{", "return", "_", ".", "cat", ".", "apply", "(", "null", ",", "_", ".", "map", "(", "array", ",", "fun", ")", ")", ";", "}" ]
Maps a function over an array and concatenates all of the results.
[ "Maps", "a", "function", "over", "an", "array", "and", "concatenates", "all", "of", "the", "results", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L92-L94
21,071
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, inter) { if (!_.isArray(array)) throw new TypeError; var sz = _.size(array); if (sz === 0) return array; if (sz === 1) return array; return slice.call(_.mapcat(array, function(elem) { return _.cons(elem, [inter]); }), 0, -1); }
javascript
function(array, inter) { if (!_.isArray(array)) throw new TypeError; var sz = _.size(array); if (sz === 0) return array; if (sz === 1) return array; return slice.call(_.mapcat(array, function(elem) { return _.cons(elem, [inter]); }), 0, -1); }
[ "function", "(", "array", ",", "inter", ")", "{", "if", "(", "!", "_", ".", "isArray", "(", "array", ")", ")", "throw", "new", "TypeError", ";", "var", "sz", "=", "_", ".", "size", "(", "array", ")", ";", "if", "(", "sz", "===", "0", ")", "return", "array", ";", "if", "(", "sz", "===", "1", ")", "return", "array", ";", "return", "slice", ".", "call", "(", "_", ".", "mapcat", "(", "array", ",", "function", "(", "elem", ")", "{", "return", "_", ".", "cons", "(", "elem", ",", "[", "inter", "]", ")", ";", "}", ")", ",", "0", ",", "-", "1", ")", ";", "}" ]
Returns an array with some item between each element of a given array.
[ "Returns", "an", "array", "with", "some", "item", "between", "each", "element", "of", "a", "given", "array", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L98-L107
21,072
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(/* args */) { if (!_.some(arguments)) return []; if (arguments.length == 1) return arguments[0]; return _.filter(_.flatten(_.zip.apply(null, arguments), true), function(elem) { return elem != null; }); }
javascript
function(/* args */) { if (!_.some(arguments)) return []; if (arguments.length == 1) return arguments[0]; return _.filter(_.flatten(_.zip.apply(null, arguments), true), function(elem) { return elem != null; }); }
[ "function", "(", "/* args */", ")", "{", "if", "(", "!", "_", ".", "some", "(", "arguments", ")", ")", "return", "[", "]", ";", "if", "(", "arguments", ".", "length", "==", "1", ")", "return", "arguments", "[", "0", "]", ";", "return", "_", ".", "filter", "(", "_", ".", "flatten", "(", "_", ".", "zip", ".", "apply", "(", "null", ",", "arguments", ")", ",", "true", ")", ",", "function", "(", "elem", ")", "{", "return", "elem", "!=", "null", ";", "}", ")", ";", "}" ]
Weaves two or more arrays together
[ "Weaves", "two", "or", "more", "arrays", "together" ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L110-L117
21,073
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, index) { return [_.take(array, index), _.drop(array, index)]; }
javascript
function(array, index) { return [_.take(array, index), _.drop(array, index)]; }
[ "function", "(", "array", ",", "index", ")", "{", "return", "[", "_", ".", "take", "(", "array", ",", "index", ")", ",", "_", ".", "drop", "(", "array", ",", "index", ")", "]", ";", "}" ]
Returns an array with two internal arrays built from taking an original array and spliting it at an index.
[ "Returns", "an", "array", "with", "two", "internal", "arrays", "built", "from", "taking", "an", "original", "array", "and", "spliting", "it", "at", "an", "index", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L134-L136
21,074
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, n) { var ret = []; var sz = _.size(array); if (n <= 0) return []; if (n === 1) return array; for(var index = 0; index < sz; index += n) { ret.push(array[index]); } return ret; }
javascript
function(array, n) { var ret = []; var sz = _.size(array); if (n <= 0) return []; if (n === 1) return array; for(var index = 0; index < sz; index += n) { ret.push(array[index]); } return ret; }
[ "function", "(", "array", ",", "n", ")", "{", "var", "ret", "=", "[", "]", ";", "var", "sz", "=", "_", ".", "size", "(", "array", ")", ";", "if", "(", "n", "<=", "0", ")", "return", "[", "]", ";", "if", "(", "n", "===", "1", ")", "return", "array", ";", "for", "(", "var", "index", "=", "0", ";", "index", "<", "sz", ";", "index", "+=", "n", ")", "{", "ret", ".", "push", "(", "array", "[", "index", "]", ")", ";", "}", "return", "ret", ";", "}" ]
Takes every nth item from an array, returning an array of the results.
[ "Takes", "every", "nth", "item", "from", "an", "array", "returning", "an", "array", "of", "the", "results", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L154-L166
21,075
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, fun, init) { var ret = []; var acc = init; _.each(array, function(v,k) { acc = fun(acc, array[k]); ret.push(acc); }); return ret; }
javascript
function(array, fun, init) { var ret = []; var acc = init; _.each(array, function(v,k) { acc = fun(acc, array[k]); ret.push(acc); }); return ret; }
[ "function", "(", "array", ",", "fun", ",", "init", ")", "{", "var", "ret", "=", "[", "]", ";", "var", "acc", "=", "init", ";", "_", ".", "each", "(", "array", ",", "function", "(", "v", ",", "k", ")", "{", "acc", "=", "fun", "(", "acc", ",", "array", "[", "k", "]", ")", ";", "ret", ".", "push", "(", "acc", ")", ";", "}", ")", ";", "return", "ret", ";", "}" ]
Returns an array of each intermediate stage of a call to a `reduce`-like function.
[ "Returns", "an", "array", "of", "each", "intermediate", "stage", "of", "a", "call", "to", "a", "reduce", "-", "like", "function", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L170-L180
21,076
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, pred) { return _.filter(_.map(_.range(_.size(array)), function(i) { return pred(i, array[i]); }), existy); }
javascript
function(array, pred) { return _.filter(_.map(_.range(_.size(array)), function(i) { return pred(i, array[i]); }), existy); }
[ "function", "(", "array", ",", "pred", ")", "{", "return", "_", ".", "filter", "(", "_", ".", "map", "(", "_", ".", "range", "(", "_", ".", "size", "(", "array", ")", ")", ",", "function", "(", "i", ")", "{", "return", "pred", "(", "i", ",", "array", "[", "i", "]", ")", ";", "}", ")", ",", "existy", ")", ";", "}" ]
Runs its given function on the index of the elements rather than the elements themselves, keeping all of the truthy values in the end.
[ "Runs", "its", "given", "function", "on", "the", "index", "of", "the", "elements", "rather", "than", "the", "elements", "themselves", "keeping", "all", "of", "the", "truthy", "values", "in", "the", "end", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L184-L189
21,077
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, pred) { if (!isSeq(array)) throw new TypeError; var sz = _.size(array); for (var index = 0; index < sz; index++) { if(!truthy(pred(array[index]))) { break; } } return _.take(array, index); }
javascript
function(array, pred) { if (!isSeq(array)) throw new TypeError; var sz = _.size(array); for (var index = 0; index < sz; index++) { if(!truthy(pred(array[index]))) { break; } } return _.take(array, index); }
[ "function", "(", "array", ",", "pred", ")", "{", "if", "(", "!", "isSeq", "(", "array", ")", ")", "throw", "new", "TypeError", ";", "var", "sz", "=", "_", ".", "size", "(", "array", ")", ";", "for", "(", "var", "index", "=", "0", ";", "index", "<", "sz", ";", "index", "++", ")", "{", "if", "(", "!", "truthy", "(", "pred", "(", "array", "[", "index", "]", ")", ")", ")", "{", "break", ";", "}", "}", "return", "_", ".", "take", "(", "array", ",", "index", ")", ";", "}" ]
Takes all items in an array while a given predicate returns truthy.
[ "Takes", "all", "items", "in", "an", "array", "while", "a", "given", "predicate", "returns", "truthy", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L255-L267
21,078
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, pred) { return [_.takeWhile(array, pred), _.dropWhile(array, pred)]; }
javascript
function(array, pred) { return [_.takeWhile(array, pred), _.dropWhile(array, pred)]; }
[ "function", "(", "array", ",", "pred", ")", "{", "return", "[", "_", ".", "takeWhile", "(", "array", ",", "pred", ")", ",", "_", ".", "dropWhile", "(", "array", ",", "pred", ")", "]", ";", "}" ]
Returns an array with two internal arrays built from taking an original array and spliting it at the index where a given function goes falsey.
[ "Returns", "an", "array", "with", "two", "internal", "arrays", "built", "from", "taking", "an", "original", "array", "and", "spliting", "it", "at", "the", "index", "where", "a", "given", "function", "goes", "falsey", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L286-L288
21,079
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, fun){ if (_.isEmpty(array) || !existy(array)) return []; var fst = _.first(array); var fstVal = fun(fst); var run = concat.call([fst], _.takeWhile(_.rest(array), function(e) { return _.isEqual(fstVal, fun(e)); })); return concat.call([run], _.partitionBy(_.drop(array, _.size(run)), fun)); }
javascript
function(array, fun){ if (_.isEmpty(array) || !existy(array)) return []; var fst = _.first(array); var fstVal = fun(fst); var run = concat.call([fst], _.takeWhile(_.rest(array), function(e) { return _.isEqual(fstVal, fun(e)); })); return concat.call([run], _.partitionBy(_.drop(array, _.size(run)), fun)); }
[ "function", "(", "array", ",", "fun", ")", "{", "if", "(", "_", ".", "isEmpty", "(", "array", ")", "||", "!", "existy", "(", "array", ")", ")", "return", "[", "]", ";", "var", "fst", "=", "_", ".", "first", "(", "array", ")", ";", "var", "fstVal", "=", "fun", "(", "fst", ")", ";", "var", "run", "=", "concat", ".", "call", "(", "[", "fst", "]", ",", "_", ".", "takeWhile", "(", "_", ".", "rest", "(", "array", ")", ",", "function", "(", "e", ")", "{", "return", "_", ".", "isEqual", "(", "fstVal", ",", "fun", "(", "e", ")", ")", ";", "}", ")", ")", ";", "return", "concat", ".", "call", "(", "[", "run", "]", ",", "_", ".", "partitionBy", "(", "_", ".", "drop", "(", "array", ",", "_", ".", "size", "(", "run", ")", ")", ",", "fun", ")", ")", ";", "}" ]
Takes an array and partitions it as the given predicate changes truth sense.
[ "Takes", "an", "array", "and", "partitions", "it", "as", "the", "given", "predicate", "changes", "truth", "sense", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L292-L302
21,080
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, fun) { return _.reduce(array, function(x, y) { return fun(x, y) ? x : y; }); }
javascript
function(array, fun) { return _.reduce(array, function(x, y) { return fun(x, y) ? x : y; }); }
[ "function", "(", "array", ",", "fun", ")", "{", "return", "_", ".", "reduce", "(", "array", ",", "function", "(", "x", ",", "y", ")", "{", "return", "fun", "(", "x", ",", "y", ")", "?", "x", ":", "y", ";", "}", ")", ";", "}" ]
Returns the 'best' value in an array based on the result of a given function.
[ "Returns", "the", "best", "value", "in", "an", "array", "based", "on", "the", "result", "of", "a", "given", "function", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L306-L310
21,081
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(array, fun) { if (!isSeq(array)) throw new TypeError("expected an array as the first argument"); return _.filter(_.map(array, function(e) { return fun(e); }), existy); }
javascript
function(array, fun) { if (!isSeq(array)) throw new TypeError("expected an array as the first argument"); return _.filter(_.map(array, function(e) { return fun(e); }), existy); }
[ "function", "(", "array", ",", "fun", ")", "{", "if", "(", "!", "isSeq", "(", "array", ")", ")", "throw", "new", "TypeError", "(", "\"expected an array as the first argument\"", ")", ";", "return", "_", ".", "filter", "(", "_", ".", "map", "(", "array", ",", "function", "(", "e", ")", "{", "return", "fun", "(", "e", ")", ";", "}", ")", ",", "existy", ")", ";", "}" ]
Returns an array of existy results of a function over an source array.
[ "Returns", "an", "array", "of", "existy", "results", "of", "a", "function", "over", "an", "source", "array", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L313-L319
21,082
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(obj, visitor, context) { var result; this.preorder(obj, function(value, key, parent) { if (visitor.call(context, value, key, parent)) { result = value; return stopWalk; } }, context); return result; }
javascript
function(obj, visitor, context) { var result; this.preorder(obj, function(value, key, parent) { if (visitor.call(context, value, key, parent)) { result = value; return stopWalk; } }, context); return result; }
[ "function", "(", "obj", ",", "visitor", ",", "context", ")", "{", "var", "result", ";", "this", ".", "preorder", "(", "obj", ",", "function", "(", "value", ",", "key", ",", "parent", ")", "{", "if", "(", "visitor", ".", "call", "(", "context", ",", "value", ",", "key", ",", "parent", ")", ")", "{", "result", "=", "value", ";", "return", "stopWalk", ";", "}", "}", ",", "context", ")", ";", "return", "result", ";", "}" ]
Performs a preorder traversal of `obj` and returns the first value which passes a truth test.
[ "Performs", "a", "preorder", "traversal", "of", "obj", "and", "returns", "the", "first", "value", "which", "passes", "a", "truth", "test", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L408-L417
21,083
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(obj, strategy, visitor, context) { return this.filter(obj, strategy, function(value, key, parent) { return !visitor.call(context, value, key, parent); }); }
javascript
function(obj, strategy, visitor, context) { return this.filter(obj, strategy, function(value, key, parent) { return !visitor.call(context, value, key, parent); }); }
[ "function", "(", "obj", ",", "strategy", ",", "visitor", ",", "context", ")", "{", "return", "this", ".", "filter", "(", "obj", ",", "strategy", ",", "function", "(", "value", ",", "key", ",", "parent", ")", "{", "return", "!", "visitor", ".", "call", "(", "context", ",", "value", ",", "key", ",", "parent", ")", ";", "}", ")", ";", "}" ]
Recursively traverses `obj` and returns all the elements for which a truth test fails.
[ "Recursively", "traverses", "obj", "and", "returns", "all", "the", "elements", "for", "which", "a", "truth", "test", "fails", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L433-L437
21,084
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(obj, visitor, context, traversalStrategy) { traversalStrategy = traversalStrategy || this._traversalStrategy; walkImpl(obj, traversalStrategy, null, visitor, context); }
javascript
function(obj, visitor, context, traversalStrategy) { traversalStrategy = traversalStrategy || this._traversalStrategy; walkImpl(obj, traversalStrategy, null, visitor, context); }
[ "function", "(", "obj", ",", "visitor", ",", "context", ",", "traversalStrategy", ")", "{", "traversalStrategy", "=", "traversalStrategy", "||", "this", ".", "_traversalStrategy", ";", "walkImpl", "(", "obj", ",", "traversalStrategy", ",", "null", ",", "visitor", ",", "context", ")", ";", "}" ]
Recursively traverses `obj` in a depth-first fashion, invoking the `visitor` function for each object only after traversing its children. `traversalStrategy` is intended for internal callers, and is not part of the public API.
[ "Recursively", "traverses", "obj", "in", "a", "depth", "-", "first", "fashion", "invoking", "the", "visitor", "function", "for", "each", "object", "only", "after", "traversing", "its", "children", ".", "traversalStrategy", "is", "intended", "for", "internal", "callers", "and", "is", "not", "part", "of", "the", "public", "API", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L468-L471
21,085
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(obj, visitor, leafMemo, context) { var reducer = function(value, key, parent, subResults) { return visitor(subResults || leafMemo, value, key, parent); }; return walkImpl(obj, this._traversalStrategy, null, reducer, context, true); }
javascript
function(obj, visitor, leafMemo, context) { var reducer = function(value, key, parent, subResults) { return visitor(subResults || leafMemo, value, key, parent); }; return walkImpl(obj, this._traversalStrategy, null, reducer, context, true); }
[ "function", "(", "obj", ",", "visitor", ",", "leafMemo", ",", "context", ")", "{", "var", "reducer", "=", "function", "(", "value", ",", "key", ",", "parent", ",", "subResults", ")", "{", "return", "visitor", "(", "subResults", "||", "leafMemo", ",", "value", ",", "key", ",", "parent", ")", ";", "}", ";", "return", "walkImpl", "(", "obj", ",", "this", ".", "_traversalStrategy", ",", "null", ",", "reducer", ",", "context", ",", "true", ")", ";", "}" ]
Builds up a single value by doing a post-order traversal of `obj` and calling the `visitor` function on each object in the tree. For leaf objects, the `memo` argument to `visitor` is the value of the `leafMemo` argument to `reduce`. For non-leaf objects, `memo` is a collection of the results of calling `reduce` on the object's children.
[ "Builds", "up", "a", "single", "value", "by", "doing", "a", "post", "-", "order", "traversal", "of", "obj", "and", "calling", "the", "visitor", "function", "on", "each", "object", "in", "the", "tree", ".", "For", "leaf", "objects", "the", "memo", "argument", "to", "visitor", "is", "the", "value", "of", "the", "leafMemo", "argument", "to", "reduce", ".", "For", "non", "-", "leaf", "objects", "memo", "is", "a", "collection", "of", "the", "results", "of", "calling", "reduce", "on", "the", "object", "s", "children", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L487-L492
21,086
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(fun) { var fixArgs = _.rest(arguments); var f = function() { var args = fixArgs.slice(); var arg = 0; for ( var i = 0; i < (args.length || arg < arguments.length); i++ ) { if ( args[i] === _ ) { args[i] = arguments[arg++]; } } return fun.apply(null, args); }; f._original = fun; return f; }
javascript
function(fun) { var fixArgs = _.rest(arguments); var f = function() { var args = fixArgs.slice(); var arg = 0; for ( var i = 0; i < (args.length || arg < arguments.length); i++ ) { if ( args[i] === _ ) { args[i] = arguments[arg++]; } } return fun.apply(null, args); }; f._original = fun; return f; }
[ "function", "(", "fun", ")", "{", "var", "fixArgs", "=", "_", ".", "rest", "(", "arguments", ")", ";", "var", "f", "=", "function", "(", ")", "{", "var", "args", "=", "fixArgs", ".", "slice", "(", ")", ";", "var", "arg", "=", "0", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "(", "args", ".", "length", "||", "arg", "<", "arguments", ".", "length", ")", ";", "i", "++", ")", "{", "if", "(", "args", "[", "i", "]", "===", "_", ")", "{", "args", "[", "i", "]", "=", "arguments", "[", "arg", "++", "]", ";", "}", "}", "return", "fun", ".", "apply", "(", "null", ",", "args", ")", ";", "}", ";", "f", ".", "_original", "=", "fun", ";", "return", "f", ";", "}" ]
Fixes the arguments to a function based on the parameter template defined by the presence of values and the `_` placeholder.
[ "Fixes", "the", "arguments", "to", "a", "function", "based", "on", "the", "parameter", "template", "defined", "by", "the", "presence", "of", "values", "and", "the", "_", "placeholder", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L602-L621
21,087
documentcloud/underscore-contrib
dist/underscore-contrib.js
baseMapArgs
function baseMapArgs (fun, mapFun) { return _.arity(fun.length, function () { return fun.apply(this, __map.call(arguments, mapFun)); }); }
javascript
function baseMapArgs (fun, mapFun) { return _.arity(fun.length, function () { return fun.apply(this, __map.call(arguments, mapFun)); }); }
[ "function", "baseMapArgs", "(", "fun", ",", "mapFun", ")", "{", "return", "_", ".", "arity", "(", "fun", ".", "length", ",", "function", "(", ")", "{", "return", "fun", ".", "apply", "(", "this", ",", "__map", ".", "call", "(", "arguments", ",", "mapFun", ")", ")", ";", "}", ")", ";", "}" ]
Takes a target function and a mapping function. Returns a function that applies the mapper to its arguments before evaluating the body.
[ "Takes", "a", "target", "function", "and", "a", "mapping", "function", ".", "Returns", "a", "function", "that", "applies", "the", "mapper", "to", "its", "arguments", "before", "evaluating", "the", "body", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L757-L761
21,088
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(/*, funs */){ var funs = (_.isArray(arguments[0])) ? arguments[0] : arguments; return function(seed) { return _.reduce(funs, function(l,r) { return r(l); }, seed); }; }
javascript
function(/*, funs */){ var funs = (_.isArray(arguments[0])) ? arguments[0] : arguments; return function(seed) { return _.reduce(funs, function(l,r) { return r(l); }, seed); }; }
[ "function", "(", "/*, funs */", ")", "{", "var", "funs", "=", "(", "_", ".", "isArray", "(", "arguments", "[", "0", "]", ")", ")", "?", "arguments", "[", "0", "]", ":", "arguments", ";", "return", "function", "(", "seed", ")", "{", "return", "_", ".", "reduce", "(", "funs", ",", "function", "(", "l", ",", "r", ")", "{", "return", "r", "(", "l", ")", ";", "}", ",", "seed", ")", ";", "}", ";", "}" ]
Takes some number of functions, either as an array or variadically and returns a function that takes some value as its first argument and runs it through a pipeline of the original functions given.
[ "Takes", "some", "number", "of", "functions", "either", "as", "an", "array", "or", "variadically", "and", "returns", "a", "function", "that", "takes", "some", "value", "as", "its", "first", "argument", "and", "runs", "it", "through", "a", "pipeline", "of", "the", "original", "functions", "given", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L773-L781
21,089
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(/* preds */) { var preds = arguments; return function(array) { return _.every(array, function(e) { return _.every(preds, function(p) { return p(e); }); }); }; }
javascript
function(/* preds */) { var preds = arguments; return function(array) { return _.every(array, function(e) { return _.every(preds, function(p) { return p(e); }); }); }; }
[ "function", "(", "/* preds */", ")", "{", "var", "preds", "=", "arguments", ";", "return", "function", "(", "array", ")", "{", "return", "_", ".", "every", "(", "array", ",", "function", "(", "e", ")", "{", "return", "_", ".", "every", "(", "preds", ",", "function", "(", "p", ")", "{", "return", "p", "(", "e", ")", ";", "}", ")", ";", "}", ")", ";", "}", ";", "}" ]
Composes a bunch of predicates into a single predicate that checks all elements of an array for conformance to all of the original predicates.
[ "Composes", "a", "bunch", "of", "predicates", "into", "a", "single", "predicate", "that", "checks", "all", "elements", "of", "an", "array", "for", "conformance", "to", "all", "of", "the", "original", "predicates", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L786-L796
21,090
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(/* preds */) { var preds = arguments; return function(array) { return _.some(array, function(e) { return _.some(preds, function(p) { return p(e); }); }); }; }
javascript
function(/* preds */) { var preds = arguments; return function(array) { return _.some(array, function(e) { return _.some(preds, function(p) { return p(e); }); }); }; }
[ "function", "(", "/* preds */", ")", "{", "var", "preds", "=", "arguments", ";", "return", "function", "(", "array", ")", "{", "return", "_", ".", "some", "(", "array", ",", "function", "(", "e", ")", "{", "return", "_", ".", "some", "(", "preds", ",", "function", "(", "p", ")", "{", "return", "p", "(", "e", ")", ";", "}", ")", ";", "}", ")", ";", "}", ";", "}" ]
Composes a bunch of predicates into a single predicate that checks all elements of an array for conformance to any of the original predicates.
[ "Composes", "a", "bunch", "of", "predicates", "into", "a", "single", "predicate", "that", "checks", "all", "elements", "of", "an", "array", "for", "conformance", "to", "any", "of", "the", "original", "predicates", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L801-L811
21,091
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(fun) { var funLength = fun.length; if (funLength < 1) { return fun; } else if (funLength === 1) { return function () { return fun.call(this, __slice.call(arguments, 0)); }; } else { return function () { var numberOfArgs = arguments.length, namedArgs = __slice.call(arguments, 0, funLength - 1), numberOfMissingNamedArgs = Math.max(funLength - numberOfArgs - 1, 0), argPadding = new Array(numberOfMissingNamedArgs), variadicArgs = __slice.call(arguments, fun.length - 1); return fun.apply(this, namedArgs.concat(argPadding).concat([variadicArgs])); }; } }
javascript
function(fun) { var funLength = fun.length; if (funLength < 1) { return fun; } else if (funLength === 1) { return function () { return fun.call(this, __slice.call(arguments, 0)); }; } else { return function () { var numberOfArgs = arguments.length, namedArgs = __slice.call(arguments, 0, funLength - 1), numberOfMissingNamedArgs = Math.max(funLength - numberOfArgs - 1, 0), argPadding = new Array(numberOfMissingNamedArgs), variadicArgs = __slice.call(arguments, fun.length - 1); return fun.apply(this, namedArgs.concat(argPadding).concat([variadicArgs])); }; } }
[ "function", "(", "fun", ")", "{", "var", "funLength", "=", "fun", ".", "length", ";", "if", "(", "funLength", "<", "1", ")", "{", "return", "fun", ";", "}", "else", "if", "(", "funLength", "===", "1", ")", "{", "return", "function", "(", ")", "{", "return", "fun", ".", "call", "(", "this", ",", "__slice", ".", "call", "(", "arguments", ",", "0", ")", ")", ";", "}", ";", "}", "else", "{", "return", "function", "(", ")", "{", "var", "numberOfArgs", "=", "arguments", ".", "length", ",", "namedArgs", "=", "__slice", ".", "call", "(", "arguments", ",", "0", ",", "funLength", "-", "1", ")", ",", "numberOfMissingNamedArgs", "=", "Math", ".", "max", "(", "funLength", "-", "numberOfArgs", "-", "1", ",", "0", ")", ",", "argPadding", "=", "new", "Array", "(", "numberOfMissingNamedArgs", ")", ",", "variadicArgs", "=", "__slice", ".", "call", "(", "arguments", ",", "fun", ".", "length", "-", "1", ")", ";", "return", "fun", ".", "apply", "(", "this", ",", "namedArgs", ".", "concat", "(", "argPadding", ")", ".", "concat", "(", "[", "variadicArgs", "]", ")", ")", ";", "}", ";", "}", "}" ]
Takes a function expecting an array and returns a function that takes varargs and wraps all in an array that is passed to the original function.
[ "Takes", "a", "function", "expecting", "an", "array", "and", "returns", "a", "function", "that", "takes", "varargs", "and", "wraps", "all", "in", "an", "array", "that", "is", "passed", "to", "the", "original", "function", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L845-L867
21,092
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(/* funs */) { var funs = arguments; return function(/* args */) { var args = arguments; return _.map(funs, function(f) { return f.apply(this, args); }, this); }; }
javascript
function(/* funs */) { var funs = arguments; return function(/* args */) { var args = arguments; return _.map(funs, function(f) { return f.apply(this, args); }, this); }; }
[ "function", "(", "/* funs */", ")", "{", "var", "funs", "=", "arguments", ";", "return", "function", "(", "/* args */", ")", "{", "var", "args", "=", "arguments", ";", "return", "_", ".", "map", "(", "funs", ",", "function", "(", "f", ")", "{", "return", "f", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ",", "this", ")", ";", "}", ";", "}" ]
Returns a function that returns an array of the calls to each given function for some arguments.
[ "Returns", "a", "function", "that", "returns", "an", "array", "of", "the", "calls", "to", "each", "given", "function", "for", "some", "arguments", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L898-L907
21,093
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(fun /*, defaults */) { var defaults = _.rest(arguments); return function(/*args*/) { var args = _.toArray(arguments); var sz = _.size(defaults); for(var i = 0; i < sz; i++) { if (!existy(args[i])) args[i] = defaults[i]; } return fun.apply(this, args); }; }
javascript
function(fun /*, defaults */) { var defaults = _.rest(arguments); return function(/*args*/) { var args = _.toArray(arguments); var sz = _.size(defaults); for(var i = 0; i < sz; i++) { if (!existy(args[i])) args[i] = defaults[i]; } return fun.apply(this, args); }; }
[ "function", "(", "fun", "/*, defaults */", ")", "{", "var", "defaults", "=", "_", ".", "rest", "(", "arguments", ")", ";", "return", "function", "(", "/*args*/", ")", "{", "var", "args", "=", "_", ".", "toArray", "(", "arguments", ")", ";", "var", "sz", "=", "_", ".", "size", "(", "defaults", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "sz", ";", "i", "++", ")", "{", "if", "(", "!", "existy", "(", "args", "[", "i", "]", ")", ")", "args", "[", "i", "]", "=", "defaults", "[", "i", "]", ";", "}", "return", "fun", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ";", "}" ]
Returns a function that protects a given function from receiving non-existy values. Each subsequent value provided to `fnull` acts as the default to the original function should a call receive non-existy values in the defaulted arg slots.
[ "Returns", "a", "function", "that", "protects", "a", "given", "function", "from", "receiving", "non", "-", "existy", "values", ".", "Each", "subsequent", "value", "provided", "to", "fnull", "acts", "as", "the", "default", "to", "the", "original", "function", "should", "a", "call", "receive", "non", "-", "existy", "values", "in", "the", "defaulted", "arg", "slots", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L913-L927
21,094
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(fun) { return function(/* args */) { var flipped = __slice.call(arguments); flipped[0] = arguments[1]; flipped[1] = arguments[0]; return fun.apply(this, flipped); }; }
javascript
function(fun) { return function(/* args */) { var flipped = __slice.call(arguments); flipped[0] = arguments[1]; flipped[1] = arguments[0]; return fun.apply(this, flipped); }; }
[ "function", "(", "fun", ")", "{", "return", "function", "(", "/* args */", ")", "{", "var", "flipped", "=", "__slice", ".", "call", "(", "arguments", ")", ";", "flipped", "[", "0", "]", "=", "arguments", "[", "1", "]", ";", "flipped", "[", "1", "]", "=", "arguments", "[", "0", "]", ";", "return", "fun", ".", "apply", "(", "this", ",", "flipped", ")", ";", "}", ";", "}" ]
Flips the first two args of a function
[ "Flips", "the", "first", "two", "args", "of", "a", "function" ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L930-L938
21,095
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(object, method) { if (object == null) return void 0; var func = object[method]; var args = slice.call(arguments, 2); return _.isFunction(func) ? func.apply(object, args) : void 0; }
javascript
function(object, method) { if (object == null) return void 0; var func = object[method]; var args = slice.call(arguments, 2); return _.isFunction(func) ? func.apply(object, args) : void 0; }
[ "function", "(", "object", ",", "method", ")", "{", "if", "(", "object", "==", "null", ")", "return", "void", "0", ";", "var", "func", "=", "object", "[", "method", "]", ";", "var", "args", "=", "slice", ".", "call", "(", "arguments", ",", "2", ")", ";", "return", "_", ".", "isFunction", "(", "func", ")", "?", "func", ".", "apply", "(", "object", ",", "args", ")", ":", "void", "0", ";", "}" ]
If object is not undefined or null then invoke the named `method` function with `object` as context and arguments; otherwise, return undefined.
[ "If", "object", "is", "not", "undefined", "or", "null", "then", "invoke", "the", "named", "method", "function", "with", "object", "as", "context", "and", "arguments", ";", "otherwise", "return", "undefined", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L1013-L1018
21,096
documentcloud/underscore-contrib
dist/underscore-contrib.js
unfoldWithReturn
function unfoldWithReturn (seed, unaryFn) { var state = seed, pair, value; return function () { if (state != null) { pair = unaryFn.call(state, state); value = pair[1]; state = value != null ? pair[0] : void 0; return value; } else return void 0; }; }
javascript
function unfoldWithReturn (seed, unaryFn) { var state = seed, pair, value; return function () { if (state != null) { pair = unaryFn.call(state, state); value = pair[1]; state = value != null ? pair[0] : void 0; return value; } else return void 0; }; }
[ "function", "unfoldWithReturn", "(", "seed", ",", "unaryFn", ")", "{", "var", "state", "=", "seed", ",", "pair", ",", "value", ";", "return", "function", "(", ")", "{", "if", "(", "state", "!=", "null", ")", "{", "pair", "=", "unaryFn", ".", "call", "(", "state", ",", "state", ")", ";", "value", "=", "pair", "[", "1", "]", ";", "state", "=", "value", "!=", "null", "?", "pair", "[", "0", "]", ":", "void", "0", ";", "return", "value", ";", "}", "else", "return", "void", "0", ";", "}", ";", "}" ]
note that the unfoldWithReturn behaves differently than unfold with respect to the first value returned
[ "note", "that", "the", "unfoldWithReturn", "behaves", "differently", "than", "unfold", "with", "respect", "to", "the", "first", "value", "returned" ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L1086-L1099
21,097
documentcloud/underscore-contrib
dist/underscore-contrib.js
function() { var count = _.size(arguments); if (count === 1) return true; if (count === 2) return arguments[0] < arguments[1]; for (var i = 1; i < count; i++) { if (arguments[i-1] >= arguments[i]) { return false; } } return true; }
javascript
function() { var count = _.size(arguments); if (count === 1) return true; if (count === 2) return arguments[0] < arguments[1]; for (var i = 1; i < count; i++) { if (arguments[i-1] >= arguments[i]) { return false; } } return true; }
[ "function", "(", ")", "{", "var", "count", "=", "_", ".", "size", "(", "arguments", ")", ";", "if", "(", "count", "===", "1", ")", "return", "true", ";", "if", "(", "count", "===", "2", ")", "return", "arguments", "[", "0", "]", "<", "arguments", "[", "1", "]", ";", "for", "(", "var", "i", "=", "1", ";", "i", "<", "count", ";", "i", "++", ")", "{", "if", "(", "arguments", "[", "i", "-", "1", "]", ">=", "arguments", "[", "i", "]", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Returns true if its arguments are monotonically increaing values; false otherwise.
[ "Returns", "true", "if", "its", "arguments", "are", "monotonically", "increaing", "values", ";", "false", "otherwise", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L1438-L1450
21,098
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(obj, kobj) { return _.reduce(kobj, function(o, nu, old) { if (existy(obj[old])) { o[nu] = obj[old]; return o; } else return o; }, _.omit.apply(null, concat.call([obj], _.keys(kobj)))); }
javascript
function(obj, kobj) { return _.reduce(kobj, function(o, nu, old) { if (existy(obj[old])) { o[nu] = obj[old]; return o; } else return o; }, _.omit.apply(null, concat.call([obj], _.keys(kobj)))); }
[ "function", "(", "obj", ",", "kobj", ")", "{", "return", "_", ".", "reduce", "(", "kobj", ",", "function", "(", "o", ",", "nu", ",", "old", ")", "{", "if", "(", "existy", "(", "obj", "[", "old", "]", ")", ")", "{", "o", "[", "nu", "]", "=", "obj", "[", "old", "]", ";", "return", "o", ";", "}", "else", "return", "o", ";", "}", ",", "_", ".", "omit", ".", "apply", "(", "null", ",", "concat", ".", "call", "(", "[", "obj", "]", ",", "_", ".", "keys", "(", "kobj", ")", ")", ")", ")", ";", "}" ]
Takes an object and another object of strings to strings where the second object describes the key renaming to occur in the first object.
[ "Takes", "an", "object", "and", "another", "object", "of", "strings", "to", "strings", "where", "the", "second", "object", "describes", "the", "key", "renaming", "to", "occur", "in", "the", "first", "object", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L1520-L1530
21,099
documentcloud/underscore-contrib
dist/underscore-contrib.js
function(obj, fun, ks, defaultValue) { if (!isAssociative(obj)) throw new TypeError("Attempted to update a non-associative object."); if (!existy(ks)) return fun(obj); var deepness = _.isArray(ks); var keys = deepness ? ks : [ks]; var ret = deepness ? _.snapshot(obj) : _.clone(obj); var lastKey = _.last(keys); var target = ret; _.each(_.initial(keys), function(key) { if (defaultValue && !_.has(target, key)) { target[key] = _.clone(defaultValue); } target = target[key]; }); target[lastKey] = fun(target[lastKey]); return ret; }
javascript
function(obj, fun, ks, defaultValue) { if (!isAssociative(obj)) throw new TypeError("Attempted to update a non-associative object."); if (!existy(ks)) return fun(obj); var deepness = _.isArray(ks); var keys = deepness ? ks : [ks]; var ret = deepness ? _.snapshot(obj) : _.clone(obj); var lastKey = _.last(keys); var target = ret; _.each(_.initial(keys), function(key) { if (defaultValue && !_.has(target, key)) { target[key] = _.clone(defaultValue); } target = target[key]; }); target[lastKey] = fun(target[lastKey]); return ret; }
[ "function", "(", "obj", ",", "fun", ",", "ks", ",", "defaultValue", ")", "{", "if", "(", "!", "isAssociative", "(", "obj", ")", ")", "throw", "new", "TypeError", "(", "\"Attempted to update a non-associative object.\"", ")", ";", "if", "(", "!", "existy", "(", "ks", ")", ")", "return", "fun", "(", "obj", ")", ";", "var", "deepness", "=", "_", ".", "isArray", "(", "ks", ")", ";", "var", "keys", "=", "deepness", "?", "ks", ":", "[", "ks", "]", ";", "var", "ret", "=", "deepness", "?", "_", ".", "snapshot", "(", "obj", ")", ":", "_", ".", "clone", "(", "obj", ")", ";", "var", "lastKey", "=", "_", ".", "last", "(", "keys", ")", ";", "var", "target", "=", "ret", ";", "_", ".", "each", "(", "_", ".", "initial", "(", "keys", ")", ",", "function", "(", "key", ")", "{", "if", "(", "defaultValue", "&&", "!", "_", ".", "has", "(", "target", ",", "key", ")", ")", "{", "target", "[", "key", "]", "=", "_", ".", "clone", "(", "defaultValue", ")", ";", "}", "target", "=", "target", "[", "key", "]", ";", "}", ")", ";", "target", "[", "lastKey", "]", "=", "fun", "(", "target", "[", "lastKey", "]", ")", ";", "return", "ret", ";", "}" ]
Updates the value at any depth in a nested object based on the path described by the keys given. The function provided is supplied the current value and is expected to return a value for use as the new value. If no keys are provided, then the object itself is presented to the given function.
[ "Updates", "the", "value", "at", "any", "depth", "in", "a", "nested", "object", "based", "on", "the", "path", "described", "by", "the", "keys", "given", ".", "The", "function", "provided", "is", "supplied", "the", "current", "value", "and", "is", "expected", "to", "return", "a", "value", "for", "use", "as", "the", "new", "value", ".", "If", "no", "keys", "are", "provided", "then", "the", "object", "itself", "is", "presented", "to", "the", "given", "function", "." ]
1492ffbe04a62a838da89df6ebdf77d0ed0b9844
https://github.com/documentcloud/underscore-contrib/blob/1492ffbe04a62a838da89df6ebdf77d0ed0b9844/dist/underscore-contrib.js#L1556-L1575