Comparing version 2.3.0 to 2.4.0
@@ -42,2 +42,14 @@ 'use strict'; | ||
/** | ||
* Returns whether the payload is an object like a type passed in < > | ||
* | ||
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop. | ||
* | ||
* @template T this must be passed in < > | ||
* @param {*} payload | ||
* @returns {payload is T} | ||
*/ | ||
function isObjectLike(payload) { | ||
return isObject(payload); | ||
} | ||
/** | ||
* Returns whether the payload is a function | ||
@@ -166,2 +178,3 @@ * | ||
exports.isObject = isObject; | ||
exports.isObjectLike = isObjectLike; | ||
exports.isFunction = isFunction; | ||
@@ -168,0 +181,0 @@ exports.isArray = isArray; |
@@ -38,2 +38,14 @@ /** | ||
/** | ||
* Returns whether the payload is an object like a type passed in < > | ||
* | ||
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop. | ||
* | ||
* @template T this must be passed in < > | ||
* @param {*} payload | ||
* @returns {payload is T} | ||
*/ | ||
function isObjectLike(payload) { | ||
return isObject(payload); | ||
} | ||
/** | ||
* Returns whether the payload is a function | ||
@@ -158,2 +170,2 @@ * | ||
export { getType, isUndefined, isNull, isObject, isFunction, isArray, isString, isNumber, isBoolean, isRegExp, isDate, isSymbol, isPrimitive, isType }; | ||
export { getType, isUndefined, isNull, isObject, isObjectLike, isFunction, isArray, isString, isNumber, isBoolean, isRegExp, isDate, isSymbol, isPrimitive, isType }; |
{ | ||
"name": "is-what", | ||
"version": "2.3.0", | ||
"version": "2.4.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", |
@@ -27,5 +27,6 @@ # is What? 🙉 | ||
**Exception:**<br> | ||
Checking for `isNumber` and `isDate` will return `false` if the payload is `NaN` or an invalid date. | ||
#### Useful number & date exception: | ||
Checking for `isNumber` and `isDate` will return `false` if the payload is `NaN` or an invalid date. This is done intentionally and especially useful when you need to check if numbers or dates are correct in your functions! | ||
```js | ||
@@ -48,2 +49,15 @@ isNumber(NaN) // returns false | ||
One other useful function especially for TypeScript is `isObjectLike`: | ||
```TypeScript | ||
function isObjectLike<T extends object> (payload: any): payload is T { | ||
return isObject(payload) | ||
} | ||
// Eg. check if it's an object and has the `id` prop: | ||
if (isObjectLike<{id: any}>(payload)) { | ||
return payload.id | ||
} | ||
// with regular isObject() it will give an error that the prop `id` does not exist on the object. | ||
``` | ||
### Source code | ||
@@ -50,0 +64,0 @@ |
@@ -43,2 +43,15 @@ | ||
/** | ||
* Returns whether the payload is an object like a type passed in < > | ||
* | ||
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop. | ||
* | ||
* @template T this must be passed in < > | ||
* @param {*} payload | ||
* @returns {payload is T} | ||
*/ | ||
export function isObjectLike<T extends object> (payload: any): payload is T { | ||
return isObject(payload) | ||
} | ||
/** | ||
* Returns whether the payload is a function | ||
@@ -45,0 +58,0 @@ * |
@@ -30,2 +30,12 @@ /** | ||
/** | ||
* Returns whether the payload is an object like a type passed in < > | ||
* | ||
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop. | ||
* | ||
* @template T this must be passed in < > | ||
* @param {*} payload | ||
* @returns {payload is T} | ||
*/ | ||
export declare function isObjectLike<T extends object>(payload: any): payload is T; | ||
/** | ||
* Returns whether the payload is a function | ||
@@ -32,0 +42,0 @@ * |
module.exports = function (wallaby) { | ||
return { | ||
files: [ | ||
'src/**/*.js', | ||
'src/**/*.ts', | ||
'dist/**/*.js' | ||
@@ -15,11 +15,10 @@ ], | ||
compilers: { | ||
'+(src|test)/**/*.js': wallaby.compilers.babel( | ||
// { | ||
// presets: ['@babel/preset-env', '@ava/babel-preset-stage-4'] | ||
// } | ||
) | ||
'**/*.+(js|ts)': wallaby.compilers.typeScript({allowJs: true, outDir: './bin'}) | ||
}, | ||
preprocessors: { | ||
'**/*.jsts': file => file.changeExt('js').content | ||
}, | ||
testFramework: 'jest', | ||
debug: true | ||
} | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27935
832
88
0