Socket
Socket
Sign inDemoInstall

@composi/are-equal

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @composi/are-equal

Function to get the type of the provided value. This is not the same as 'typeof'. It returns the capitalized type: Number, String, Array, Object, Data, RegExp, Symbol, etc.


Version published
Maintainers
1
Install size
13.9 kB
Created

Readme

Source

@composi/are-equal

A function that test the provided values to see if they are equal. If the values are primitive types the comparison is the same as using ===. For complex types, such as arrays and objects, it also makes the comparison by value instead of by reference. By default JavaScript compares objects by reference. areEqual lets you compare them by value.

Install

npm install --save-dev @composi/uuid

Using

You compare primitive types or complex types:

let num1 = 1
let num2 = 1
areEqual(num1, num2) // returns true

let str1 = 'Some text'
let str2 = 'Some text'
areEqual(str1, str2) // returns true

let bool1 = true
let bool2 = true
areEqual(bool1, bool2) // returns true

let nullVal = null
let undefinedVal
areEqual(nullVal, undefinedVal) // returns false

areEqual(0/0, NaN) // returns true

You can compare arrays to see if they hold the same values:

// 
const array1 = [1, 2, 3]
const array2 = [1, 2, 3]
array1 === array2 // returns false because they are by reference.
areEqual(array1, array2) // returns true because this is by value.

You can compare objects to see if their properties and values are equal:

const obj1 = {name: 'Joe'}
const obj2 = {name: 'Joe'}

obj1 === obj2 // returns false
obj1 == obj2 // returns false
areEqual(obj1, obj2) // returns true

Keywords

FAQs

Last updated on 27 Apr 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc