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 3.0.0 to 3.0.1

2

dist/index.cjs.js

@@ -63,3 +63,3 @@ 'use strict';

function isObjectLike(payload) {
return isObject(payload);
return isAnyObject(payload);
}

@@ -66,0 +66,0 @@ /**

@@ -59,3 +59,3 @@ /**

function isObjectLike(payload) {
return isObject(payload);
return isAnyObject(payload);
}

@@ -62,0 +62,0 @@ /**

{
"name": "is-what",
"version": "3.0.0",
"version": "3.0.1",
"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,2 +27,29 @@ # is What? 🙉

#### isObject vs isAnyObject
Checking for a JavaScript object can be really difficult. In JavaScript you can create classes that will behave just like JavaScript objects but might have completely different prototypes. With is-what I opted for a **strict** check on isObject only returning `true` on plain JavaScript objects and not on classes or others. `isAnyObject` will be more loose and return `true` even if the object is not a regular JavaScript object.
```js
const plainObject = {hello: 'I am a good old object.'}
class SpecialObject {
constructor (somethingSpecial) {
this.speciality = somethingSpecial
}
}
const specialObject = new SpecialObject('I am a special object! I am a class!!!')
// let's check:
import { isObject, isAnyObject, getType } from 'is-what'
// plainObject
isObject(plainObject) // returns true
isAnyObject(plainObject) // returns true
getType(plainObject) // returns 'Object'
// specialObject
isObject(specialObject) // returns false !!!!!!!!!
isAnyObject(specialObject) // returns true
getType(specialObject) // returns 'Object'
```
> Please note that `isObject` will only return `true` for normal plain JavaScript object.
#### Useful number & date exception:

@@ -56,8 +83,7 @@

`isObject` with TypeScript will declare the payload to be an object type with any props:
`isObject` and `isAnyObject` with TypeScript will declare the payload to be an object type with any props:
```TypeScript
function isObject (payload: any): payload is {[key: string]: any} {
return isObject(payload)
}
function isObject (payload: any): payload is {[key: string]: any}
function isAnyObject (payload: any): payload is {[key: string]: any}
// The reason to return `{[key: string]: any}` is to be able to do

@@ -72,3 +98,3 @@ if (isObject(payload) && payload.id) return payload.id

function isObjectLike<T extends object> (payload: any): payload is T {
return isObject(payload)
return isAnyObject(payload)
}

@@ -95,3 +121,3 @@ // usage examples:

}
function isObject (payload) {
function isAnyObject (payload) {
return getType(payload) === 'Object'

@@ -98,0 +124,0 @@ }

@@ -63,3 +63,3 @@ /**

export function isObjectLike<T extends object> (payload: any): payload is T {
return isObject(payload)
return isAnyObject(payload)
}

@@ -66,0 +66,0 @@

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