Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(promise): add promise kind and tests #8

Merged
merged 1 commit into from May 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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