-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheq.coffee
39 lines (28 loc) · 828 Bytes
/
eq.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# @ts-check
import $getType from './getType'
import $includes from './includes'
import $isArray from './isArray'
import $isObject from './isObject'
import $length from './length'
$eq =
###* @type import('../type/module').Eq ###
(value, other) ->
$typeA = $getType value
$typeB = $getType other
unless $typeA == $typeB then return false
if $includes ['function', 'number', 'string'], $typeA
return value == other
$lengthA = $length value
$lengthB = $length other
unless $lengthA == $lengthB then return false
if $isArray value
for $it, $i in value
unless $eq $it, other[$i] then return false
return true
# object
if $isObject value
for $k, $v of value
unless $eq $v, other[$k] then return false
return true
throw "$.eq: invalid type '#{$typeA}'"
export default $eq