0.0.5 • Published 2 years ago

is-same-value v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Tips

No longer update. To use @tuyo/is-same

is-same-value

Compares two values for equality. Support array, object, set, map and other types.

Install

npm i is-same-value

Usage

import isSameValue from 'is-same-value'

isSameValue(NaN, NaN) // false

isSameValue(100, 100) // true
isSameValue(100, '100') // false

[] === [] // false
isSameValue([], []) // true
isSameValue([1, 2, 'a', 'b'], [1, 2, 'a', 'b']) // true
isSameValue([1, 2, 'a', 'b'], ['b', 1, 'a', 2]) // true
isSameValue([1, 2, [1, 2, 3]], [2, 1, [3, 2, 1]]) // true

{} === {} // false
isSameValue({}, {}) // true
isSameValue({a: 1, b: 2, c: 3}, {c:3, a:1, b: 2}) // true

new Set([]) === new Set([]) // false
isSameValue(new Set([]), new Set([])) // true
isSameValue(new Set([1, 2, 3]), new Set([3, 2, 1])) // true

new Map([]) === new Map([]) // false
isSameValue(new Map([]), new Map([])) // true
isSameValue(new Map([['a', [1,2,3]], ['b', '123']]), new Map([['b', '123'],['a', [1,3,2]]])) // true

const array1 = [1,'z',[100, ['a', 'b']], {a: 'z'}, new Set([new Map([['a', 'z']])]), new Map([['a', [1,2,3],['b', new Set([])]]])]
const array2 = [new Map([['a', [3,2,1],['b', new Set([])]]]), [100, ['a', 'b']], {a: 'z'}, new Set([new Map([['a', 'z']])]), 1,'z']
isSameValue(array1, array2) // true