Skip to content

Commit

Permalink
refactor(simplify): update boilerplate and simplify
Browse files Browse the repository at this point in the history
BREAKING CHANGE: exports and module.exports only methods for types - is.string(val),

is.function(val), is.object(val) and etc. because before that it was too complex and needless. Now

it is clean and explicit.
  • Loading branch information
tunnckoCore committed Nov 5, 2016
1 parent 9c3af8d commit ef6a9d6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
13 changes: 13 additions & 0 deletions index.js
Expand Up @@ -6,3 +6,16 @@
*/

'use strict'

var utils = require('./utils')

function check (type) {
return function is (val) {
return utils.typeOf(val) === type
}
}

utils.types.forEach(function each (type) {
exports[type] = check(type)
module.exports[type] = check(type)
})
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -33,7 +33,8 @@
"nyc": "^8.3.2",
"pre-commit": "^1.1.3",
"standard": "^8.5.0",
"standard-version": "^3.0.0"
"standard-version": "^3.0.0",
"through2": "^2.0.1"
},
"files": [
"index.js",
Expand Down Expand Up @@ -67,4 +68,4 @@
"reflinks": true
}
}
}
}
38 changes: 37 additions & 1 deletion test.js
Expand Up @@ -10,7 +10,43 @@
'use strict'

var test = require('mukla')
var is = require('./index')
var through2 = require('through2')

test(function (done) {
var keys = Object.keys(is)

var actual = {
'array': [1, 2],
'boolean': true,
'buffer': new Buffer('foo'),
'date': new Date(),
'error': new Error('foo'),
'function': function noop () {},
'generator': (function * () { yield 42 })(),
'generatorfunction': function * () {},
'map': new Map(),
'null': null,
'number': 123,
'object': { a: 'b' },
'promise': Promise.resolve(123),
'regexp': new RegExp('aa'),
'set': new Set(),
'stream': through2(),
'string': 'fooo',
'symbol': Symbol(),
'undefined': undefined,
'weakmap': new WeakMap(),
'weakset': new WeakSet()
}

test('should export >=22 methods', function (done) {
test.ok(keys.length > 21)
done()
})

Object.keys(actual).forEach(function (name) {
test('is.' + name + '(val) work', function (done) {
test.ok(is[name](actual[name]), name + ' should work')
done()
}, true)
})

0 comments on commit ef6a9d6

Please sign in to comment.