Skip to content

Commit

Permalink
feat(promise): add promise kind and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Dec 11, 2016
1 parent 2a83cac commit 971e507
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
31 changes: 19 additions & 12 deletions browser.js
Expand Up @@ -60,6 +60,9 @@ module.exports = function kindOf(val) {
if (type === '[object Error]') {
return 'error';
}
if (type === '[object Promise]') {
return 'promise';
}

// buffer
if (typeof Buffer !== 'undefined' && isBuffer(val)) {
Expand Down Expand Up @@ -117,22 +120,26 @@ module.exports = function kindOf(val) {
};

},{"is-buffer":2}],2:[function(require,module,exports){
/**
* Determine if an object is Buffer
/*!
* Determine if an object is a Buffer
*
* Author: Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* License: MIT
*
* `npm install is-buffer`
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* @license MIT
*/

// The _isBuffer check is for Safari 5-7 support, because it's missing
// Object.prototype.constructor. Remove this eventually
module.exports = function (obj) {
return !!(obj != null &&
(obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor)
(obj.constructor &&
typeof obj.constructor.isBuffer === 'function' &&
obj.constructor.isBuffer(obj))
))
return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
}

function isBuffer (obj) {
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
}

// For Node v0.10 support. Remove this eventually.
function isSlowBuffer (obj) {
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
}

},{}]},{},[1])(1)
Expand Down
3 changes: 3 additions & 0 deletions index.js
Expand Up @@ -59,6 +59,9 @@ module.exports = function kindOf(val) {
if (type === '[object Error]') {
return 'error';
}
if (type === '[object Promise]') {
return 'promise';
}

// buffer
if (typeof Buffer !== 'undefined' && isBuffer(val)) {
Expand Down
11 changes: 11 additions & 0 deletions test/es6/index.js
Expand Up @@ -6,6 +6,17 @@ var kindOf = require('../..');

module.exports = function() {
describe('es6 features', function() {
it('should work for resolved promises', function() {
var promise = Promise.resolve(123);
assert.strictEqual(kindOf(promise), 'promise');
});

it('should work for rejected promises', function() {
var promise = Promise.reject(new Error('foo bar'));
promise.catch(function() {})
assert.strictEqual(kindOf(promise), 'promise');
});

it('should work for generators', function() {
var gen = function * named() {return true;};
assert.equal(kindOf(gen), 'function');
Expand Down

0 comments on commit 971e507

Please sign in to comment.