-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathType.equals.js
More file actions
39 lines (39 loc) · 1.06 KB
/
Type.equals.js
File metadata and controls
39 lines (39 loc) · 1.06 KB
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
var Function = require('./Type').Function;
var Tuple = require('./Type').Tuple;
function equals(t, s) {
return (
typeof t == 'string' && typeof s == 'string'
&& t == s
||
t instanceof Function && s instanceof Function
&& equals(t.argument, s.argument)
&& equals(t.result, s.result)
||
t instanceof Array && s instanceof Array
&& equals(t[0], s[0])
||
t instanceof Tuple && s instanceof Tuple
&& t.element.length == s.element.length
&& t.element.every((t, i) => equals(t, s.element[i]))
||
typeof t == 'object' && !(t instanceof Array) && !(t instanceof Tuple) && !(t instanceof Function)
&&
typeof s == 'object' && !(s instanceof Array) && !(s instanceof Tuple) && !(s instanceof Function)
&& (() => {
for (var key in t)
if (t[key].type)
if (
!(key in s)
||
!s[key].type
||
!equals(t[key].type, s[key].type)
)
return false;
if (Object.values(t).filter(v => v.type).length != Object.values(s).filter(v => v.type).length)
return false;
return true;
})()
);
}
module.exports = equals;