Socket
Socket
Sign inDemoInstall

is-what

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-what - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0

13

dist/index.cjs.js

@@ -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;

14

dist/index.esm.js

@@ -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 };

2

package.json
{
"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
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc