code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
doParallelLimit = function(limit, fn) { return function () { var args = Array.prototype.slice.call(arguments); return fn.apply(null, [_eachLimit(limit)].concat(args)); }; }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
doParallelLimit
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
doSeries = function (fn) { return function () { var args = Array.prototype.slice.call(arguments); return fn.apply(null, [async.eachSeries].concat(args)); }; }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
doSeries
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_asyncMap = function (eachfn, arr, iterator, callback) { var results = []; arr = _map(arr, function (x, i) { return {index: i, value: x}; }); eachfn(arr, function (x, callback) { iterator(x.value, function (err, v) { results[x.index] = v; callback(err); }); }, function (err) { callback(err, results); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_asyncMap
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_mapLimit = function(limit) { return doParallelLimit(limit, _asyncMap); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_mapLimit
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_filter = function (eachfn, arr, iterator, callback) { var results = []; arr = _map(arr, function (x, i) { return {index: i, value: x}; }); eachfn(arr, function (x, callback) { iterator(x.value, function (v) { if (v) { results.push(x); } callback(); }); }, function (err) { callback(_map(results.sort(function (a, b) { return a.index - b.index; }), function (x) { return x.value; })); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_filter
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_reject = function (eachfn, arr, iterator, callback) { var results = []; arr = _map(arr, function (x, i) { return {index: i, value: x}; }); eachfn(arr, function (x, callback) { iterator(x.value, function (v) { if (!v) { results.push(x); } callback(); }); }, function (err) { callback(_map(results.sort(function (a, b) { return a.index - b.index; }), function (x) { return x.value; })); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_reject
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_detect = function (eachfn, arr, iterator, main_callback) { eachfn(arr, function (x, callback) { iterator(x, function (result) { if (result) { main_callback(x); main_callback = function () {}; } else { callback(); } }); }, function (err) { main_callback(); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_detect
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
fn = function (left, right) { var a = left.criteria, b = right.criteria; return a < b ? -1 : a > b ? 1 : 0; }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
fn
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
removeListener = function (fn) { for (var i = 0; i < listeners.length; i += 1) { if (listeners[i] === fn) { listeners.splice(i, 1); return; } } }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
removeListener
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
taskComplete = function () { _each(listeners.slice(0), function (fn) { fn(); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
taskComplete
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
taskCallback = function (err) { var args = Array.prototype.slice.call(arguments, 1); if (args.length <= 1) { args = args[0]; } if (err) { var safeResults = {}; _each(_keys(results), function(rkey) { safeResults[rkey] = results[rkey]; }); safeResults[k] = args; callback(err, safeResults); // stop subsequent errors hitting callback multiple times callback = function () {}; } else { results[k] = args; async.setImmediate(taskComplete); } }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
taskCallback
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
ready = function () { return _reduce(requires, function (a, x) { return (a && results.hasOwnProperty(x)); }, true) && !results.hasOwnProperty(k); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
ready
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
listener = function () { if (ready()) { removeListener(listener); task[task.length - 1](taskCallback, results); } }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
listener
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
wrapIterator = function (iterator) { return function (err) { if (err) { callback.apply(null, arguments); callback = function () {}; } else { var args = Array.prototype.slice.call(arguments, 1); var next = iterator.next(); if (next) { args.push(wrapIterator(next)); } else { args.push(callback); } async.setImmediate(function () { iterator.apply(null, args); }); } }; }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
wrapIterator
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_parallel = function(eachfn, tasks, callback) { callback = callback || function () {}; if (tasks.constructor === Array) { eachfn.map(tasks, function (fn, callback) { if (fn) { fn(function (err) { var args = Array.prototype.slice.call(arguments, 1); if (args.length <= 1) { args = args[0]; } callback.call(null, err, args); }); } }, callback); } else { var results = {}; eachfn.each(_keys(tasks), function (k, callback) { tasks[k](function (err) { var args = Array.prototype.slice.call(arguments, 1); if (args.length <= 1) { args = args[0]; } results[k] = args; callback(err); }); }, function (err) { callback(err, results); }); } }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_parallel
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
makeCallback = function (index) { var fn = function () { if (tasks.length) { tasks[index].apply(null, arguments); } return fn.next(); }; fn.next = function () { return (index < tasks.length - 1) ? makeCallback(index + 1): null; }; return fn; }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
makeCallback
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
fn = function () { if (tasks.length) { tasks[index].apply(null, arguments); } return fn.next(); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
fn
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_concat = function (eachfn, arr, fn, callback) { var r = []; eachfn(arr, function (x, cb) { fn(x, function (err, y) { r = r.concat(y || []); cb(err); }); }, function (err) { callback(err, r); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_concat
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function _insert(q, data, pos, callback) { if(data.constructor !== Array) { data = [data]; } _each(data, function(task) { var item = { data: task, callback: typeof callback === 'function' ? callback : null }; if (pos) { q.tasks.unshift(item); } else { q.tasks.push(item); } if (q.saturated && q.tasks.length === concurrency) { q.saturated(); } async.setImmediate(q.process); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_insert
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
next = function () { workers -= 1; if (task.callback) { task.callback.apply(task, arguments); } if (q.drain && q.tasks.length + workers === 0) { q.drain(); } q.process(); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
next
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_console_fn = function (name) { return function (fn) { var args = Array.prototype.slice.call(arguments, 1); fn.apply(null, args.concat([function (err) { var args = Array.prototype.slice.call(arguments, 1); if (typeof console !== 'undefined') { if (err) { if (console.error) { console.error(err); } } else if (console[name]) { _each(args, function (x) { console[name](x); }); } } }])); }; }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_console_fn
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
memoized = function () { var args = Array.prototype.slice.call(arguments); var callback = args.pop(); var key = hasher.apply(null, args); if (key in memo) { callback.apply(null, memo[key]); } else if (key in queues) { queues[key].push(callback); } else { queues[key] = [callback]; fn.apply(null, args.concat([function () { memo[key] = arguments; var q = queues[key]; delete queues[key]; for (var i = 0, l = q.length; i < l; i++) { q[i].apply(null, arguments); } }])); } }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
memoized
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_applyEach = function (eachfn, fns /*args...*/) { var go = function () { var that = this; var args = Array.prototype.slice.call(arguments); var callback = args.pop(); return eachfn(fns, function (fn, cb) { fn.apply(that, args.concat([cb])); }, callback); }; if (arguments.length > 2) { var args = Array.prototype.slice.call(arguments, 2); return go.apply(this, args); } else { return go; } }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_applyEach
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
go = function () { var that = this; var args = Array.prototype.slice.call(arguments); var callback = args.pop(); return eachfn(fns, function (fn, cb) { fn.apply(that, args.concat([cb])); }, callback); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
go
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function next(err) { if (err) { if (callback) { return callback(err); } throw err; } fn(next); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
next
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function AVLTree (options) { this.tree = new _AVLTree(options); }
Constructor We can't use a direct pointer to the root node (as in the simple binary search tree) as the root will change during tree rotations @param {Boolean} options.unique Whether to enforce a 'unique' constraint on the key or not @param {Function} options.compareKeys Initialize this BST's compareKeys
AVLTree
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function _AVLTree (options) { options = options || {}; this.left = null; this.right = null; this.parent = options.parent !== undefined ? options.parent : null; if (options.hasOwnProperty('key')) { this.key = options.key; } this.data = options.hasOwnProperty('value') ? [options.value] : []; this.unique = options.unique || false; this.compareKeys = options.compareKeys || customUtils.defaultCompareKeysFunction; this.checkValueEquality = options.checkValueEquality || customUtils.defaultCheckValueEquality; }
Constructor of the internal AVLTree @param {Object} options Optional @param {Boolean} options.unique Whether to enforce a 'unique' constraint on the key or not @param {Key} options.key Initialize this BST's key with key @param {Value} options.value Initialize this BST's data with [value] @param {Function} options.compareKeys Initialize this BST's compareKeys
_AVLTree
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function BinarySearchTree (options) { options = options || {}; this.left = null; this.right = null; this.parent = options.parent !== undefined ? options.parent : null; if (options.hasOwnProperty('key')) { this.key = options.key; } this.data = options.hasOwnProperty('value') ? [options.value] : []; this.unique = options.unique || false; this.compareKeys = options.compareKeys || customUtils.defaultCompareKeysFunction; this.checkValueEquality = options.checkValueEquality || customUtils.defaultCheckValueEquality; }
Constructor @param {Object} options Optional @param {Boolean} options.unique Whether to enforce a 'unique' constraint on the key or not @param {Key} options.key Initialize this BST's key with key @param {Value} options.value Initialize this BST's data with [value] @param {Function} options.compareKeys Initialize this BST's compareKeys
BinarySearchTree
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function append (array, toAppend) { var i; for (i = 0; i < toAppend.length; i += 1) { array.push(toAppend[i]); } }
Return a function that tells whether a given key matches an upper bound
append
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function getRandomArray (n) { var res, next; if (n === 0) { return []; } if (n === 1) { return [0]; } res = getRandomArray(n - 1); next = Math.floor(Math.random() * n); res.splice(next, 0, n - 1); // Add n-1 at a random position in the array return res; }
Return an array with the numbers from 0 to n-1, in a random order
getRandomArray
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function defaultCompareKeysFunction (a, b) { if (a < b) { return -1; } if (a > b) { return 1; } if (a === b) { return 0; } var err = new Error("Couldn't compare elements"); err.a = a; err.b = b; throw err; }
Return an array with the numbers from 0 to n-1, in a random order
defaultCompareKeysFunction
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function defaultCheckValueEquality (a, b) { return a === b; }
Check whether two values are equal (used in non-unique deletion)
defaultCheckValueEquality
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function resolve(child) { if (child.charAt(0) !== '.') { return child; } var parts = child.split("/"); var parentBase = name.split("/").slice(0, -1); for (var i=0, l=parts.length; i<l; i++) { var part = parts[i]; if (part === '..') { parentBase.pop(); } else if (part === '.') { continue; } else { parentBase.push(part); } } return parentBase.join("/"); }
Check whether two values are equal (used in non-unique deletion)
resolve
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function all(promises) { /*jshint validthis:true */ var Promise = this; if (!isArray(promises)) { throw new TypeError('You must pass an array to all.'); } return new Promise(function(resolve, reject) { var results = [], remaining = promises.length, promise; if (remaining === 0) { resolve([]); } function resolver(index) { return function(value) { resolveAll(index, value); }; } function resolveAll(index, value) { results[index] = value; if (--remaining === 0) { resolve(results); } } for (var i = 0; i < promises.length; i++) { promise = promises[i]; if (promise && isFunction(promise.then)) { promise.then(resolver(i), reject); } else { resolveAll(i, promise); } } }); }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
all
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function resolver(index) { return function(value) { resolveAll(index, value); }; }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
resolver
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function resolveAll(index, value) { results[index] = value; if (--remaining === 0) { resolve(results); } }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
resolveAll
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function useNextTick() { return function() { process.nextTick(flush); }; }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
useNextTick
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function useMutationObserver() { var iterations = 0; var observer = new BrowserMutationObserver(flush); var node = document.createTextNode(''); observer.observe(node, { characterData: true }); return function() { node.data = (iterations = ++iterations % 2); }; }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
useMutationObserver
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function useSetTimeout() { return function() { local.setTimeout(flush, 1); }; }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
useSetTimeout
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function flush() { for (var i = 0; i < queue.length; i++) { var tuple = queue[i]; var callback = tuple[0], arg = tuple[1]; callback(arg); } queue = []; }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
flush
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function asap(callback, arg) { var length = queue.push([callback, arg]); if (length === 1) { // If length is 1, that means that we need to schedule an async flush. // If additional callbacks are queued before the queue is flushed, they // will be processed by this flush that we are scheduling. scheduleFlush(); } }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
asap
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function configure(name, value) { if (arguments.length === 2) { config[name] = value; } else { return config[name]; } }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
configure
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function polyfill() { var local; if (typeof global !== 'undefined') { local = global; } else if (typeof window !== 'undefined' && window.document) { local = window; } else { local = self; } var es6PromiseSupport = "Promise" in local && // Some of these methods are missing from // Firefox/Chrome experimental implementations "resolve" in local.Promise && "reject" in local.Promise && "all" in local.Promise && "race" in local.Promise && // Older version of the spec had a resolver object // as the arg rather than a function (function() { var resolve; new local.Promise(function(r) { resolve = r; }); return isFunction(resolve); }()); if (!es6PromiseSupport) { local.Promise = RSVPPromise; } }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
polyfill
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function Promise(resolver) { if (!isFunction(resolver)) { throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); } if (!(this instanceof Promise)) { throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."); } this._subscribers = []; invokeResolver(resolver, this); }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
Promise
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function invokeResolver(resolver, promise) { function resolvePromise(value) { resolve(promise, value); } function rejectPromise(reason) { reject(promise, reason); } try { resolver(resolvePromise, rejectPromise); } catch(e) { rejectPromise(e); } }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
invokeResolver
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function resolvePromise(value) { resolve(promise, value); }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
resolvePromise
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function rejectPromise(reason) { reject(promise, reason); }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
rejectPromise
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function invokeCallback(settled, promise, callback, detail) { var hasCallback = isFunction(callback), value, error, succeeded, failed; if (hasCallback) { try { value = callback(detail); succeeded = true; } catch(e) { failed = true; error = e; } } else { value = detail; succeeded = true; } if (handleThenable(promise, value)) { return; } else if (hasCallback && succeeded) { resolve(promise, value); } else if (failed) { reject(promise, error); } else if (settled === FULFILLED) { resolve(promise, value); } else if (settled === REJECTED) { reject(promise, value); } }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
invokeCallback
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function subscribe(parent, child, onFulfillment, onRejection) { var subscribers = parent._subscribers; var length = subscribers.length; subscribers[length] = child; subscribers[length + FULFILLED] = onFulfillment; subscribers[length + REJECTED] = onRejection; }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
subscribe
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function publish(promise, settled) { var child, callback, subscribers = promise._subscribers, detail = promise._detail; for (var i = 0; i < subscribers.length; i += 3) { child = subscribers[i]; callback = subscribers[i + settled]; invokeCallback(settled, child, callback, detail); } promise._subscribers = null; }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
publish
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function handleThenable(promise, value) { var then = null, resolved; try { if (promise === value) { throw new TypeError("A promises callback cannot return that same promise."); } if (objectOrFunction(value)) { then = value.then; if (isFunction(then)) { then.call(value, function(val) { if (resolved) { return true; } resolved = true; if (value !== val) { resolve(promise, val); } else { fulfill(promise, val); } }, function(val) { if (resolved) { return true; } resolved = true; reject(promise, val); }); return true; } } } catch (error) { if (resolved) { return true; } reject(promise, error); return true; } return false; }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
handleThenable
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function resolve(promise, value) { if (promise === value) { fulfill(promise, value); } else if (!handleThenable(promise, value)) { fulfill(promise, value); } }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
resolve
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function fulfill(promise, value) { if (promise._state !== PENDING) { return; } promise._state = SEALED; promise._detail = value; config.async(publishFulfillment, promise); }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
fulfill
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function reject(promise, reason) { if (promise._state !== PENDING) { return; } promise._state = SEALED; promise._detail = reason; config.async(publishRejection, promise); }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
reject
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function publishFulfillment(promise) { publish(promise, promise._state = FULFILLED); }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
publishFulfillment
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function publishRejection(promise) { publish(promise, promise._state = REJECTED); }
Returns a promise that is fulfilled when all the given promises have been fulfilled, or rejected if any of them become rejected. The return promise is fulfilled with an array that gives all the values in the order they were passed in the `promises` array argument. Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.resolve(2); var promise3 = RSVP.resolve(3); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` If any of the `promises` given to `RSVP.all` are rejected, the first promise that is rejected will be given as an argument to the returned promises's rejection handler. For example: Example: ```javascript var promise1 = RSVP.resolve(1); var promise2 = RSVP.reject(new Error("2")); var promise3 = RSVP.reject(new Error("3")); var promises = [ promise1, promise2, promise3 ]; RSVP.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` @method all @for RSVP @param {Array} promises @param {String} label @return {Promise} promise that is fulfilled when all `promises` have been fulfilled, or rejected if any of them become rejected.
publishRejection
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function race(promises) { /*jshint validthis:true */ var Promise = this; if (!isArray(promises)) { throw new TypeError('You must pass an array to race.'); } return new Promise(function(resolve, reject) { var results = [], promise; for (var i = 0; i < promises.length; i++) { promise = promises[i]; if (promise && typeof promise.then === 'function') { promise.then(resolve, reject); } else { resolve(promise); } } }); }
`RSVP.race` allows you to watch a series of promises and act as soon as the first promise given to the `promises` argument fulfills or rejects. Example: ```javascript var promise1 = new RSVP.Promise(function(resolve, reject){ setTimeout(function(){ resolve("promise 1"); }, 200); }); var promise2 = new RSVP.Promise(function(resolve, reject){ setTimeout(function(){ resolve("promise 2"); }, 100); }); RSVP.race([promise1, promise2]).then(function(result){ // result === "promise 2" because it was resolved before promise1 // was resolved. }); ``` `RSVP.race` is deterministic in that only the state of the first completed promise matters. For example, even if other promises given to the `promises` array argument are resolved, but the first completed promise has become rejected before the other promises became fulfilled, the returned promise will become rejected: ```javascript var promise1 = new RSVP.Promise(function(resolve, reject){ setTimeout(function(){ resolve("promise 1"); }, 200); }); var promise2 = new RSVP.Promise(function(resolve, reject){ setTimeout(function(){ reject(new Error("promise 2")); }, 100); }); RSVP.race([promise1, promise2]).then(function(result){ // Code here never runs because there are rejected promises! }, function(reason){ // reason.message === "promise2" because promise 2 became rejected before // promise 1 became fulfilled }); ``` @method race @for RSVP @param {Array} promises array of promises to observe @param {String} label optional string for describing the promise returned. Useful for tooling. @return {Promise} a promise that becomes fulfilled with the value the first completed promises is resolved with if the first completed promise was fulfilled, or rejected with the reason that the first completed promise was rejected with.
race
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function reject(reason) { /*jshint validthis:true */ var Promise = this; return new Promise(function (resolve, reject) { reject(reason); }); }
`RSVP.reject` returns a promise that will become rejected with the passed `reason`. `RSVP.reject` is essentially shorthand for the following: ```javascript var promise = new RSVP.Promise(function(resolve, reject){ reject(new Error('WHOOPS')); }); promise.then(function(value){ // Code here doesn't run because the promise is rejected! }, function(reason){ // reason.message === 'WHOOPS' }); ``` Instead of writing the above, your code now simply becomes the following: ```javascript var promise = RSVP.reject(new Error('WHOOPS')); promise.then(function(value){ // Code here doesn't run because the promise is rejected! }, function(reason){ // reason.message === 'WHOOPS' }); ``` @method reject @for RSVP @param {Any} reason value that the returned promise will be rejected with. @param {String} label optional string for identifying the returned promise. Useful for tooling. @return {Promise} a promise that will become rejected with the given `reason`.
reject
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function resolve(value) { /*jshint validthis:true */ if (value && typeof value === 'object' && value.constructor === this) { return value; } var Promise = this; return new Promise(function(resolve) { resolve(value); }); }
`RSVP.reject` returns a promise that will become rejected with the passed `reason`. `RSVP.reject` is essentially shorthand for the following: ```javascript var promise = new RSVP.Promise(function(resolve, reject){ reject(new Error('WHOOPS')); }); promise.then(function(value){ // Code here doesn't run because the promise is rejected! }, function(reason){ // reason.message === 'WHOOPS' }); ``` Instead of writing the above, your code now simply becomes the following: ```javascript var promise = RSVP.reject(new Error('WHOOPS')); promise.then(function(value){ // Code here doesn't run because the promise is rejected! }, function(reason){ // reason.message === 'WHOOPS' }); ``` @method reject @for RSVP @param {Any} reason value that the returned promise will be rejected with. @param {String} label optional string for identifying the returned promise. Useful for tooling. @return {Promise} a promise that will become rejected with the given `reason`.
resolve
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function objectOrFunction(x) { return isFunction(x) || (typeof x === "object" && x !== null); }
`RSVP.reject` returns a promise that will become rejected with the passed `reason`. `RSVP.reject` is essentially shorthand for the following: ```javascript var promise = new RSVP.Promise(function(resolve, reject){ reject(new Error('WHOOPS')); }); promise.then(function(value){ // Code here doesn't run because the promise is rejected! }, function(reason){ // reason.message === 'WHOOPS' }); ``` Instead of writing the above, your code now simply becomes the following: ```javascript var promise = RSVP.reject(new Error('WHOOPS')); promise.then(function(value){ // Code here doesn't run because the promise is rejected! }, function(reason){ // reason.message === 'WHOOPS' }); ``` @method reject @for RSVP @param {Any} reason value that the returned promise will be rejected with. @param {String} label optional string for identifying the returned promise. Useful for tooling. @return {Promise} a promise that will become rejected with the given `reason`.
objectOrFunction
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function isFunction(x) { return typeof x === "function"; }
`RSVP.reject` returns a promise that will become rejected with the passed `reason`. `RSVP.reject` is essentially shorthand for the following: ```javascript var promise = new RSVP.Promise(function(resolve, reject){ reject(new Error('WHOOPS')); }); promise.then(function(value){ // Code here doesn't run because the promise is rejected! }, function(reason){ // reason.message === 'WHOOPS' }); ``` Instead of writing the above, your code now simply becomes the following: ```javascript var promise = RSVP.reject(new Error('WHOOPS')); promise.then(function(value){ // Code here doesn't run because the promise is rejected! }, function(reason){ // reason.message === 'WHOOPS' }); ``` @method reject @for RSVP @param {Any} reason value that the returned promise will be rejected with. @param {String} label optional string for identifying the returned promise. Useful for tooling. @return {Promise} a promise that will become rejected with the given `reason`.
isFunction
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function isArray(x) { return Object.prototype.toString.call(x) === "[object Array]"; }
`RSVP.reject` returns a promise that will become rejected with the passed `reason`. `RSVP.reject` is essentially shorthand for the following: ```javascript var promise = new RSVP.Promise(function(resolve, reject){ reject(new Error('WHOOPS')); }); promise.then(function(value){ // Code here doesn't run because the promise is rejected! }, function(reason){ // reason.message === 'WHOOPS' }); ``` Instead of writing the above, your code now simply becomes the following: ```javascript var promise = RSVP.reject(new Error('WHOOPS')); promise.then(function(value){ // Code here doesn't run because the promise is rejected! }, function(reason){ // reason.message === 'WHOOPS' }); ``` @method reject @for RSVP @param {Any} reason value that the returned promise will be rejected with. @param {String} label optional string for identifying the returned promise. Useful for tooling. @return {Promise} a promise that will become rejected with the given `reason`.
isArray
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function require(name) { var module = require.modules[name]; if (!module) throw new Error('failed to require "' + name + '"'); if (!('exports' in module) && typeof module.definition === 'function') { module.client = module.component = true; module.definition.call(this, module.exports = {}, module); delete module.definition; } return module.exports; }
Require the module at `name`. @param {String} name @return {Object} exports @api public
require
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function showError(name) { throw new Error('failed to find latest module of "' + name + '"'); }
Find and require a module which name starts with the provided name. If multiple modules exists, the highest semver is used. This function can only be used for remote dependencies. @param {String} name - module name: `user~repo` @param {Boolean} returnPath - returns the canonical require path if true, otherwise it returns the epxorted module
showError
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function exclude () { var excludes = [].slice.call(arguments); function excludeProps (res, obj) { Object.keys(obj).forEach(function (key) { if (!~excludes.indexOf(key)) res[key] = obj[key]; }); } return function extendExclude () { var args = [].slice.call(arguments) , i = 0 , res = {}; for (; i < args.length; i++) { excludeProps(res, args[i]); } return res; }; }
Define a module's exports immediately with `exports`. @param {String} name @param {Generic} exports @api private
exclude
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function excludeProps (res, obj) { Object.keys(obj).forEach(function (key) { if (!~excludes.indexOf(key)) res[key] = obj[key]; }); }
Define a module's exports immediately with `exports`. @param {String} name @param {Generic} exports @api private
excludeProps
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function AssertionError (message, _props, ssf) { var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON') , props = extend(_props || {}); // default values this.message = message || 'Unspecified AssertionError'; this.showDiff = false; // copy from properties for (var key in props) { this[key] = props[key]; } // capture stack trace ssf = ssf || arguments.callee; if (ssf && Error.captureStackTrace) { Error.captureStackTrace(this, ssf); } }
### AssertionError An extension of the JavaScript `Error` constructor for assertion and validation scenarios. @param {String} message @param {Object} properties to include (optional) @param {callee} start stack function (optional)
AssertionError
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function getType (obj) { var str = Object.prototype.toString.call(obj); if (natives[str]) return natives[str]; if (obj === null) return 'null'; if (obj === undefined) return 'undefined'; if (obj === Object(obj)) return 'object'; return typeof obj; }
### typeOf (obj) Use several different techniques to determine the type of object being tested. @param {Mixed} object @return {String} object type @api public
getType
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function Library () { this.tests = {}; }
### Library Create a repository for custom type detection. ```js var lib = new type.Library; ```
Library
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function deepEqual(a, b, m) { if (sameValue(a, b)) { return true; } else if ('date' === type(a)) { return dateEqual(a, b); } else if ('regexp' === type(a)) { return regexpEqual(a, b); } else if (Buffer.isBuffer(a)) { return bufferEqual(a, b); } else if ('arguments' === type(a)) { return argumentsEqual(a, b, m); } else if (!typeEqual(a, b)) { return false; } else if (('object' !== type(a) && 'object' !== type(b)) && ('array' !== type(a) && 'array' !== type(b))) { return sameValue(a, b); } else { return objectEqual(a, b, m); } }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
deepEqual
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function sameValue(a, b) { if (a === b) return a !== 0 || 1 / a === 1 / b; return a !== a && b !== b; }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
sameValue
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function typeEqual(a, b) { return type(a) === type(b); }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
typeEqual
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function dateEqual(a, b) { if ('date' !== type(b)) return false; return sameValue(a.getTime(), b.getTime()); }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
dateEqual
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function regexpEqual(a, b) { if ('regexp' !== type(b)) return false; return sameValue(a.toString(), b.toString()); }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
regexpEqual
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function argumentsEqual(a, b, m) { if ('arguments' !== type(b)) return false; a = [].slice.call(a); b = [].slice.call(b); return deepEqual(a, b, m); }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
argumentsEqual
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function enumerable(a) { var res = []; for (var key in a) res.push(key); return res; }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
enumerable
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function iterableEqual(a, b) { if (a.length !== b.length) return false; var i = 0; var match = true; for (; i < a.length; i++) { if (a[i] !== b[i]) { match = false; break; } } return match; }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
iterableEqual
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function bufferEqual(a, b) { if (!Buffer.isBuffer(b)) return false; return iterableEqual(a, b); }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
bufferEqual
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function isValue(a) { return a !== null && a !== undefined; }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
isValue
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function objectEqual(a, b, m) { if (!isValue(a) || !isValue(b)) { return false; } if (a.prototype !== b.prototype) { return false; } var i; if (m) { for (i = 0; i < m.length; i++) { if ((m[i][0] === a && m[i][1] === b) || (m[i][0] === b && m[i][1] === a)) { return true; } } } else { m = []; } try { var ka = enumerable(a); var kb = enumerable(b); } catch (ex) { return false; } ka.sort(); kb.sort(); if (!iterableEqual(ka, kb)) { return false; } m.push([ a, b ]); var key; for (i = ka.length - 1; i >= 0; i--) { key = ka[i]; if (!deepEqual(a[key], b[key], m)) { return false; } } return true; }
Assert super-strict (egal) equality between two objects of any type. @param {Mixed} a @param {Mixed} b @param {Array} memoised (optional) @return {Boolean} equal match
objectEqual
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function Assertion (obj, msg, stack) { flag(this, 'ssfi', stack || arguments.callee); flag(this, 'object', obj); flag(this, 'message', msg); }
# .use(function) Provides a way to extend the internals of Chai @param {Function} @returns {this} for chaining @api public
Assertion
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function an (type, msg) { if (msg) flag(this, 'message', msg); type = type.toLowerCase(); var obj = flag(this, 'object') , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a '; this.assert( type === _.type(obj) , 'expected #{this} to be ' + article + type , 'expected #{this} not to be ' + article + type ); }
### .a(type) The `a` and `an` assertions are aliases that can be used either as language chains or to assert a value's type. // typeof expect('test').to.be.a('string'); expect({ foo: 'bar' }).to.be.an('object'); expect(null).to.be.a('null'); expect(undefined).to.be.an('undefined'); // language chain expect(foo).to.be.an.instanceof(Foo); @name a @alias an @param {String} type @param {String} message _optional_ @api public
an
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function includeChainingBehavior () { flag(this, 'contains', true); }
### .include(value) The `include` and `contain` assertions can be used as either property based language chains or as methods to assert the inclusion of an object in an array or a substring in a string. When used as language chains, they toggle the `contains` flag for the `keys` assertion. expect([1,2,3]).to.include(2); expect('foobar').to.contain('foo'); expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo'); @name include @alias contain @alias includes @alias contains @param {Object|String|Number} obj @param {String} message _optional_ @api public
includeChainingBehavior
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function include (val, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); var expected = false; if (_.type(obj) === 'array' && _.type(val) === 'object') { for (var i in obj) { if (_.eql(obj[i], val)) { expected = true; break; } } } else if (_.type(val) === 'object') { if (!flag(this, 'negate')) { for (var k in val) new Assertion(obj).property(k, val[k]); return; } var subset = {}; for (var k in val) subset[k] = obj[k]; expected = _.eql(subset, val); } else { expected = obj && ~obj.indexOf(val); } this.assert( expected , 'expected #{this} to include ' + _.inspect(val) , 'expected #{this} to not include ' + _.inspect(val)); }
### .include(value) The `include` and `contain` assertions can be used as either property based language chains or as methods to assert the inclusion of an object in an array or a substring in a string. When used as language chains, they toggle the `contains` flag for the `keys` assertion. expect([1,2,3]).to.include(2); expect('foobar').to.contain('foo'); expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo'); @name include @alias contain @alias includes @alias contains @param {Object|String|Number} obj @param {String} message _optional_ @api public
include
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function checkArguments () { var obj = flag(this, 'object') , type = Object.prototype.toString.call(obj); this.assert( '[object Arguments]' === type , 'expected #{this} to be arguments but got ' + type , 'expected #{this} to not be arguments' ); }
### .arguments Asserts that the target is an arguments object. function test () { expect(arguments).to.be.arguments; } @name arguments @alias Arguments @api public
checkArguments
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertEqual (val, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); if (flag(this, 'deep')) { return this.eql(val); } else { this.assert( val === obj , 'expected #{this} to equal #{exp}' , 'expected #{this} to not equal #{exp}' , val , this._obj , true ); } }
### .equal(value) Asserts that the target is strictly equal (`===`) to `value`. Alternately, if the `deep` flag is set, asserts that the target is deeply equal to `value`. expect('hello').to.equal('hello'); expect(42).to.equal(42); expect(1).to.not.equal(true); expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' }); expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' }); @name equal @alias equals @alias eq @alias deep.equal @param {Mixed} value @param {String} message _optional_ @api public
assertEqual
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertEql(obj, msg) { if (msg) flag(this, 'message', msg); this.assert( _.eql(obj, flag(this, 'object')) , 'expected #{this} to deeply equal #{exp}' , 'expected #{this} to not deeply equal #{exp}' , obj , this._obj , true ); }
### .eql(value) Asserts that the target is deeply equal to `value`. expect({ foo: 'bar' }).to.eql({ foo: 'bar' }); expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]); @name eql @alias eqls @param {Mixed} value @param {String} message _optional_ @api public
assertEql
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertAbove (n, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); if (flag(this, 'doLength')) { new Assertion(obj, msg).to.have.property('length'); var len = obj.length; this.assert( len > n , 'expected #{this} to have a length above #{exp} but got #{act}' , 'expected #{this} to not have a length above #{exp}' , n , len ); } else { this.assert( obj > n , 'expected #{this} to be above ' + n , 'expected #{this} to be at most ' + n ); } }
### .above(value) Asserts that the target is greater than `value`. expect(10).to.be.above(5); Can also be used in conjunction with `length` to assert a minimum length. The benefit being a more informative error message than if the length was supplied directly. expect('foo').to.have.length.above(2); expect([ 1, 2, 3 ]).to.have.length.above(2); @name above @alias gt @alias greaterThan @param {Number} value @param {String} message _optional_ @api public
assertAbove
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertLeast (n, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); if (flag(this, 'doLength')) { new Assertion(obj, msg).to.have.property('length'); var len = obj.length; this.assert( len >= n , 'expected #{this} to have a length at least #{exp} but got #{act}' , 'expected #{this} to have a length below #{exp}' , n , len ); } else { this.assert( obj >= n , 'expected #{this} to be at least ' + n , 'expected #{this} to be below ' + n ); } }
### .least(value) Asserts that the target is greater than or equal to `value`. expect(10).to.be.at.least(10); Can also be used in conjunction with `length` to assert a minimum length. The benefit being a more informative error message than if the length was supplied directly. expect('foo').to.have.length.of.at.least(2); expect([ 1, 2, 3 ]).to.have.length.of.at.least(3); @name least @alias gte @param {Number} value @param {String} message _optional_ @api public
assertLeast
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertBelow (n, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); if (flag(this, 'doLength')) { new Assertion(obj, msg).to.have.property('length'); var len = obj.length; this.assert( len < n , 'expected #{this} to have a length below #{exp} but got #{act}' , 'expected #{this} to not have a length below #{exp}' , n , len ); } else { this.assert( obj < n , 'expected #{this} to be below ' + n , 'expected #{this} to be at least ' + n ); } }
### .below(value) Asserts that the target is less than `value`. expect(5).to.be.below(10); Can also be used in conjunction with `length` to assert a maximum length. The benefit being a more informative error message than if the length was supplied directly. expect('foo').to.have.length.below(4); expect([ 1, 2, 3 ]).to.have.length.below(4); @name below @alias lt @alias lessThan @param {Number} value @param {String} message _optional_ @api public
assertBelow
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertMost (n, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); if (flag(this, 'doLength')) { new Assertion(obj, msg).to.have.property('length'); var len = obj.length; this.assert( len <= n , 'expected #{this} to have a length at most #{exp} but got #{act}' , 'expected #{this} to have a length above #{exp}' , n , len ); } else { this.assert( obj <= n , 'expected #{this} to be at most ' + n , 'expected #{this} to be above ' + n ); } }
### .most(value) Asserts that the target is less than or equal to `value`. expect(5).to.be.at.most(5); Can also be used in conjunction with `length` to assert a maximum length. The benefit being a more informative error message than if the length was supplied directly. expect('foo').to.have.length.of.at.most(4); expect([ 1, 2, 3 ]).to.have.length.of.at.most(3); @name most @alias lte @param {Number} value @param {String} message _optional_ @api public
assertMost
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertInstanceOf (constructor, msg) { if (msg) flag(this, 'message', msg); var name = _.getName(constructor); this.assert( flag(this, 'object') instanceof constructor , 'expected #{this} to be an instance of ' + name , 'expected #{this} to not be an instance of ' + name ); }
### .instanceof(constructor) Asserts that the target is an instance of `constructor`. var Tea = function (name) { this.name = name; } , Chai = new Tea('chai'); expect(Chai).to.be.an.instanceof(Tea); expect([ 1, 2, 3 ]).to.be.instanceof(Array); @name instanceof @param {Constructor} constructor @param {String} message _optional_ @alias instanceOf @api public
assertInstanceOf
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertOwnProperty (name, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); this.assert( obj.hasOwnProperty(name) , 'expected #{this} to have own property ' + _.inspect(name) , 'expected #{this} to not have own property ' + _.inspect(name) ); }
### .ownProperty(name) Asserts that the target has an own property `name`. expect('test').to.have.ownProperty('length'); @name ownProperty @alias haveOwnProperty @param {String} name @param {String} message _optional_ @api public
assertOwnProperty
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertLengthChain () { flag(this, 'doLength', true); }
### .length(value) Asserts that the target's `length` property has the expected value. expect([ 1, 2, 3]).to.have.length(3); expect('foobar').to.have.length(6); Can also be used as a chain precursor to a value comparison for the length property. expect('foo').to.have.length.above(2); expect([ 1, 2, 3 ]).to.have.length.above(2); expect('foo').to.have.length.below(4); expect([ 1, 2, 3 ]).to.have.length.below(4); expect('foo').to.have.length.within(2,4); expect([ 1, 2, 3 ]).to.have.length.within(2,4); @name length @alias lengthOf @param {Number} length @param {String} message _optional_ @api public
assertLengthChain
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertLength (n, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); new Assertion(obj, msg).to.have.property('length'); var len = obj.length; this.assert( len == n , 'expected #{this} to have a length of #{exp} but got #{act}' , 'expected #{this} to not have a length of #{act}' , n , len ); }
### .length(value) Asserts that the target's `length` property has the expected value. expect([ 1, 2, 3]).to.have.length(3); expect('foobar').to.have.length(6); Can also be used as a chain precursor to a value comparison for the length property. expect('foo').to.have.length.above(2); expect([ 1, 2, 3 ]).to.have.length.above(2); expect('foo').to.have.length.below(4); expect([ 1, 2, 3 ]).to.have.length.below(4); expect('foo').to.have.length.within(2,4); expect([ 1, 2, 3 ]).to.have.length.within(2,4); @name length @alias lengthOf @param {Number} length @param {String} message _optional_ @api public
assertLength
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertKeys (keys) { var obj = flag(this, 'object') , str , ok = true , mixedArgsMsg = 'keys must be given single argument of Array|Object|String, or multiple String arguments'; switch (_.type(keys)) { case "array": if (arguments.length > 1) throw (new Error(mixedArgsMsg)); break; case "object": if (arguments.length > 1) throw (new Error(mixedArgsMsg)); keys = Object.keys(keys); break; default: keys = Array.prototype.slice.call(arguments); } if (!keys.length) throw new Error('keys required'); var actual = Object.keys(obj) , expected = keys , len = keys.length , any = flag(this, 'any') , all = flag(this, 'all'); if (!any && !all) { all = true; } // Has any if (any) { var intersection = expected.filter(function(key) { return ~actual.indexOf(key); }); ok = intersection.length > 0; } // Has all if (all) { ok = keys.every(function(key){ return ~actual.indexOf(key); }); if (!flag(this, 'negate') && !flag(this, 'contains')) { ok = ok && keys.length == actual.length; } } // Key string if (len > 1) { keys = keys.map(function(key){ return _.inspect(key); }); var last = keys.pop(); if (all) { str = keys.join(', ') + ', and ' + last; } if (any) { str = keys.join(', ') + ', or ' + last; } } else { str = _.inspect(keys[0]); } // Form str = (len > 1 ? 'keys ' : 'key ') + str; // Have / include str = (flag(this, 'contains') ? 'contain ' : 'have ') + str; // Assertion this.assert( ok , 'expected #{this} to ' + str , 'expected #{this} to not ' + str , expected.slice(0).sort() , actual.sort() , true ); }
### .keys(key1, [key2], [...]) Asserts that the target contains any or all of the passed-in keys. Use in combination with `any`, `all`, `contains`, or `have` will affect what will pass. When used in conjunction with `any`, at least one key that is passed in must exist in the target object. This is regardless whether or not the `have` or `contain` qualifiers are used. Note, either `any` or `all` should be used in the assertion. If neither are used, the assertion is defaulted to `all`. When both `all` and `contain` are used, the target object must have at least all of the passed-in keys but may have more keys not listed. When both `all` and `have` are used, the target object must both contain all of the passed-in keys AND the number of keys in the target object must match the number of keys passed in (in other words, a target object must have all and only all of the passed-in keys). expect({ foo: 1, bar: 2 }).to.have.any.keys('foo', 'baz'); expect({ foo: 1, bar: 2 }).to.have.any.keys('foo'); expect({ foo: 1, bar: 2 }).to.contain.any.keys('bar', 'baz'); expect({ foo: 1, bar: 2 }).to.contain.any.keys(['foo']); expect({ foo: 1, bar: 2 }).to.contain.any.keys({'foo': 6}); expect({ foo: 1, bar: 2 }).to.have.all.keys(['bar', 'foo']); expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo', 7}); expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(['bar', 'foo']); expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys([{'bar': 6}}]); @name keys @alias key @param {String...|Array|Object} keys @api public
assertKeys
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function isSubsetOf(subset, superset, cmp) { return subset.every(function(elem) { if (!cmp) return superset.indexOf(elem) !== -1; return superset.some(function(elem2) { return cmp(elem, elem2); }); }) }
### .closeTo(expected, delta) Asserts that the target is equal `expected`, to within a +/- `delta` range. expect(1.5).to.be.closeTo(1, 0.5); @name closeTo @param {Number} expected @param {Number} delta @param {String} message _optional_ @api public
isSubsetOf
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertChanges (object, prop, msg) { if (msg) flag(this, 'message', msg); var fn = flag(this, 'object'); new Assertion(object, msg).to.have.property(prop); new Assertion(fn).is.a('function'); var initial = object[prop]; fn(); this.assert( initial !== object[prop] , 'expected .' + prop + ' to change' , 'expected .' + prop + ' to not change' ); }
### .change(function) Asserts that a function changes an object property var obj = { val: 10 }; var fn = function() { obj.val += 3 }; var noChangeFn = function() { return 'foo' + 'bar'; } expect(fn).to.change(obj, 'val'); expect(noChangFn).to.not.change(obj, 'val') @name change @alias changes @alias Change @param {String} object @param {String} property name @param {String} message _optional_ @api public
assertChanges
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertIncreases (object, prop, msg) { if (msg) flag(this, 'message', msg); var fn = flag(this, 'object'); new Assertion(object, msg).to.have.property(prop); new Assertion(fn).is.a('function'); var initial = object[prop]; fn(); this.assert( object[prop] - initial > 0 , 'expected .' + prop + ' to increase' , 'expected .' + prop + ' to not increase' ); }
### .increase(function) Asserts that a function increases an object property var obj = { val: 10 }; var fn = function() { obj.val = 15 }; expect(fn).to.increase(obj, 'val'); @name increase @alias increases @alias Increase @param {String} object @param {String} property name @param {String} message _optional_ @api public
assertIncreases
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT
function assertDecreases (object, prop, msg) { if (msg) flag(this, 'message', msg); var fn = flag(this, 'object'); new Assertion(object, msg).to.have.property(prop); new Assertion(fn).is.a('function'); var initial = object[prop]; fn(); this.assert( object[prop] - initial < 0 , 'expected .' + prop + ' to decrease' , 'expected .' + prop + ' to not decrease' ); }
### .decrease(function) Asserts that a function decreases an object property var obj = { val: 10 }; var fn = function() { obj.val = 5 }; expect(fn).to.decrease(obj, 'val'); @name decrease @alias decreases @alias Decrease @param {String} object @param {String} property name @param {String} message _optional_ @api public
assertDecreases
javascript
louischatriot/nedb
browser-version/test/chai.js
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
MIT