Comparing version 2.5.0 to 3.0.0
@@ -33,3 +33,3 @@ 'use strict'; | ||
/** | ||
* Returns whether the payload is an object | ||
* Returns whether the payload is an plain JavaScript object (excluding special classes or objects with other prototypes) | ||
* | ||
@@ -40,2 +40,14 @@ * @param {*} payload | ||
function isObject(payload) { | ||
var isObject = getType(payload) === 'Object'; | ||
if (!isObject) | ||
return false; | ||
return (payload.constructor === Object && Object.getPrototypeOf(payload) === Object.prototype); | ||
} | ||
/** | ||
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes) | ||
* | ||
* @param {*} payload | ||
* @returns {payload is {[key: string]: any}} | ||
*/ | ||
function isAnyObject(payload) { | ||
return getType(payload) === 'Object'; | ||
@@ -170,2 +182,3 @@ } | ||
exports.isObject = isObject; | ||
exports.isAnyObject = isAnyObject; | ||
exports.isObjectLike = isObjectLike; | ||
@@ -172,0 +185,0 @@ exports.isFunction = isFunction; |
@@ -29,3 +29,3 @@ /** | ||
/** | ||
* Returns whether the payload is an object | ||
* Returns whether the payload is an plain JavaScript object (excluding special classes or objects with other prototypes) | ||
* | ||
@@ -36,2 +36,14 @@ * @param {*} payload | ||
function isObject(payload) { | ||
var isObject = getType(payload) === 'Object'; | ||
if (!isObject) | ||
return false; | ||
return (payload.constructor === Object && Object.getPrototypeOf(payload) === Object.prototype); | ||
} | ||
/** | ||
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes) | ||
* | ||
* @param {*} payload | ||
* @returns {payload is {[key: string]: any}} | ||
*/ | ||
function isAnyObject(payload) { | ||
return getType(payload) === 'Object'; | ||
@@ -162,2 +174,2 @@ } | ||
export { getType, isUndefined, isNull, isObject, isObjectLike, isFunction, isArray, isString, isNumber, isBoolean, isRegExp, isDate, isSymbol, isPrimitive, isType }; | ||
export { getType, isUndefined, isNull, isObject, isAnyObject, isObjectLike, isFunction, isArray, isString, isNumber, isBoolean, isRegExp, isDate, isSymbol, isPrimitive, isType }; |
{ | ||
"name": "is-what", | ||
"version": "2.5.0", | ||
"version": "3.0.0", | ||
"description": "JS type check (TypeScript supported) functions like `isObject() isArray()` etc. A simple & small integration.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js", |
@@ -58,6 +58,6 @@ # is What? 🙉 | ||
```TypeScript | ||
function isObject (payload: any): payload is {[key: any]: any} { | ||
function isObject (payload: any): payload is {[key: string]: any} { | ||
return isObject(payload) | ||
} | ||
// The reason to return `{[key: any]: any}` is to be able to do | ||
// The reason to return `{[key: string]: any}` is to be able to do | ||
if (isObject(payload) && payload.id) return payload.id | ||
@@ -64,0 +64,0 @@ // if isObject() would return `payload is object` then it would give an error at `payload.id` |
@@ -32,3 +32,3 @@ /** | ||
/** | ||
* Returns whether the payload is an object | ||
* Returns whether the payload is an plain JavaScript object (excluding special classes or objects with other prototypes) | ||
* | ||
@@ -39,2 +39,14 @@ * @param {*} payload | ||
export function isObject (payload: any): payload is {[key: string]: any} { | ||
const isObject = getType(payload) === 'Object' | ||
if (!isObject) return false | ||
return (payload.constructor === Object && Object.getPrototypeOf(payload) === Object.prototype) | ||
} | ||
/** | ||
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes) | ||
* | ||
* @param {*} payload | ||
* @returns {payload is {[key: string]: any}} | ||
*/ | ||
export function isAnyObject (payload: any): payload is {[key: string]: any} { | ||
return getType(payload) === 'Object' | ||
@@ -41,0 +53,0 @@ } |
@@ -23,3 +23,3 @@ /** | ||
/** | ||
* Returns whether the payload is an object | ||
* Returns whether the payload is an plain JavaScript object (excluding special classes or objects with other prototypes) | ||
* | ||
@@ -33,2 +33,11 @@ * @param {*} payload | ||
/** | ||
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes) | ||
* | ||
* @param {*} payload | ||
* @returns {payload is {[key: string]: any}} | ||
*/ | ||
export declare function isAnyObject(payload: any): payload is { | ||
[key: string]: any; | ||
}; | ||
/** | ||
* Returns whether the payload is an object like a type passed in < > | ||
@@ -35,0 +44,0 @@ * |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29938
846