@tuyo/is-same
v0.0.3
Published
Compares two values for equality. Support array, object, set, map and other types.
Downloads
4
Maintainers
Readme
@tuyo/is-same
Compares two values for equality. Support array, object, set, map and other types.
Install
npm i @tuyo/is-same
Usage
import isSame from '@tuyo/is-same'
isSame(NaN, NaN) // false
isSame(100, 100) // true
isSame(100, '100') // false
[] === [] // false
isSame([], []) // true
isSame([1, 2, 'a', 'b'], [1, 2, 'a', 'b']) // true
isSame([1, 2, 'a', 'b'], ['b', 1, 'a', 2]) // true
isSame([1, 2, [1, 2, 3]], [2, 1, [3, 2, 1]]) // true
{} === {} // false
isSame({}, {}) // true
isSame({a: 1, b: 2, c: 3}, {c:3, a:1, b: 2}) // true
new Set([]) === new Set([]) // false
isSame(new Set([]), new Set([])) // true
isSame(new Set([1, 2, 3]), new Set([3, 2, 1])) // true
new Map([]) === new Map([]) // false
isSame(new Map([]), new Map([])) // true
isSame(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']
isSame(array1, array2) // true