Skip to content

Commit

Permalink
switch to use just kind-of-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Jun 30, 2015
1 parent 783ee55 commit 67b7692
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 56 deletions.
74 changes: 24 additions & 50 deletions index.js
Expand Up @@ -7,25 +7,19 @@

'use strict'

var isGens = require('is-es6-generators')
var isPromise = require('is-promise')
var isHybrid = require('is-hybrid')
var isStream = require('is-stream')
var kindOf = require('kind-of')

module.exports = IsKindof
var kindOf = require('kind-of-extra')

function IsKindof (val, types) {
if (arguments.length === 2) {
types = kindOf(types) === 'array' ? types : [types]
types = arrayify(types)

var ret = false
var len = types.length
var i = 0

while (i < len) {
var type = types[i++]
if (check(val, type)) {
if (kindCheck(val, type)) {
ret = true
break
}
Expand All @@ -42,29 +36,30 @@ function IsKindof (val, types) {
return false
}

function check (val, type) {
if (type === 'promise') {
return isPromise(val)
}
if (type === 'hybrid') {
return isHybrid(val)
}
if (type === 'stream') {
return isStream(val)
}
if (type === 'error') {
return isError(val)
}
if (type === 'generator') {
return isGens.isGenerator(val)
}
function arrayify (val) {
return Array.isArray(val) ? val : [val]
}

function kindCheck (val, type) {
if (isGeneratorFnType(type)) {
return isGens.isGeneratorFunction(val)
return kindOf(val) === 'generatorfunction'
}

return kindOf(val) === type
}

function isGeneratorFnType (type) {
return type === 'generatorFunction' ||
type === 'generatorfunction' ||
type === 'generator function' ||
type === 'generator fn' ||
type === 'generatorFn' ||
type === 'generatorfn' ||
type === 'gen function' ||
type === 'gen fn' ||
type === 'genfn'
}

[
'null',
'set',
Expand Down Expand Up @@ -92,12 +87,12 @@ function check (val, type) {

function isType (val) {
if (arguments.length === 1) {
return check(val, type)
return kindCheck(val, type)
}
if (this.marker === undefined) {
return false
}
return check(this.value, type)
return kindCheck(this.value, type)
}

IsKindof[type] = isType
Expand All @@ -110,25 +105,4 @@ IsKindof.generator.fn = IsKindof.generatorFunction
IsKindof.prototype.generatorFn = IsKindof.prototype.generatorFunction
IsKindof.prototype.generator.fn = IsKindof.prototype.generatorFunction

function isError (val) {
return isObjectLike(val) &&
typeof val.message === 'string' &&
String(val).indexOf('Error') !== -1
}

function isObjectLike (val) {
return !!val && typeof val === 'object'
}

function isGeneratorFnType (type) {
return type === 'generatorFunction' ||
type === 'generatorfunction' ||
type === 'generator function' ||
type === 'generator fn' ||
type === 'generatorFn' ||
type === 'generatorfn' ||
type === 'gen function' ||
type === 'gen fn' ||
type === 'genfn'
}

module.exports = IsKindof
8 changes: 2 additions & 6 deletions package.json
Expand Up @@ -10,15 +10,11 @@
"test": "standard && node test.js"
},
"dependencies": {
"is-es6-generators": "~1.0.2",
"is-hybrid": "~1.0.0",
"is-promise": "~2.0.0",
"is-stream": "~1.0.1",
"kind-of": "~2.0.0"
"kind-of-extra": "~1.0.0"
},
"devDependencies": {
"assertit": "^0.1.0",
"got": "^3.2.0",
"got": "^3.3.0",
"got-promise": "^4.1.0",
"plugin-error": "^0.1.2",
"then-got": "^1.0.7"
Expand Down

0 comments on commit 67b7692

Please sign in to comment.