cover all

This commit is contained in:
harttle
2017-08-14 22:07:08 +08:00
parent 7904f823a8
commit 72597c52e5
14 changed files with 268 additions and 205 deletions
-3
View File
@@ -2,9 +2,6 @@ const AssertionError = require('./error.js').AssertionError
function assert (predicate, message) {
if (!predicate) {
if (message instanceof Error) {
throw message
}
message = message || `expect ${predicate} to be true`
throw new AssertionError(message)
}
+13 -1
View File
@@ -1,3 +1,5 @@
const toStr = Object.prototype.toString
/*
* Checks if value is classified as a String primitive or object.
* @param {any} value The value to check.
@@ -7,6 +9,15 @@ function isString (value) {
return value instanceof String || typeof value === 'string'
}
function isNil (value) {
return value === null || value === undefined
}
function isArray (value) {
// be compatible with IE 8
return toStr.call(value) === '[object Array]'
}
function isError (value) {
var signature = Object.prototype.toString.call(value)
// [object XXXError]
@@ -53,7 +64,6 @@ function assign (object) {
}
function _assignBinary (dst, src) {
if (!dst) return dst
forOwn(src, function (v, k) {
dst[k] = v
})
@@ -115,6 +125,8 @@ function range (start, stop, step) {
exports.isString = isString
exports.isObject = isObject
exports.isArray = isArray
exports.isNil = isNil
exports.isError = isError
exports.range = range