From 2071a7d3089c73919b955002136aaf9287318324 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Thu, 1 Oct 2015 20:47:32 +0200 Subject: [PATCH] Use kindof instead of typeof where appropriate. --- packages/xo-collection/package.json | 1 + packages/xo-collection/src/collection.js | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/xo-collection/package.json b/packages/xo-collection/package.json index 5401699c2..f7f6a18f0 100644 --- a/packages/xo-collection/package.json +++ b/packages/xo-collection/package.json @@ -23,6 +23,7 @@ ], "dependencies": { "babel-runtime": "^5.6.11", + "kindof": "^2.0.0", "lodash.bind": "^3.1.0", "lodash.callback": "^3.3.0", "lodash.foreach": "^3.0.3", diff --git a/packages/xo-collection/src/collection.js b/packages/xo-collection/src/collection.js index e50341909..d404fce51 100644 --- a/packages/xo-collection/src/collection.js +++ b/packages/xo-collection/src/collection.js @@ -1,4 +1,5 @@ import forEach from 'lodash.foreach' +import kindOf from 'kindof' import {BaseError} from 'make-error' import {EventEmitter} from 'events' @@ -33,13 +34,13 @@ export class DuplicateItem extends BaseError { export class IllegalTouch extends BaseError { constructor (value) { - super('only an object value can be touched (found a ' + typeof value + ')') + super('only an object value can be touched (found a ' + kindOf(value) + ')') } } export class InvalidKey extends BaseError { constructor (key) { - super('invalid key of type ' + typeof key) + super('invalid key of type ' + kindOf(key)) } } @@ -138,7 +139,7 @@ export default class Collection extends EventEmitter { const [key] = this._resolveItem(keyOrObjectWithId) this._assertHas(key) const value = this.get(key) - if (typeof value !== 'object' || value === null) { + if (kindOf(value) !== 'object') { throw new IllegalTouch(value) }