-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathremoted.js
60 lines (60 loc) · 1.95 KB
/
remoted.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function remoted(object) {
return function $(object, current, remote) {
Object.keys(object).forEach(function (key) {
var value = object[key];
var path = current.concat(key);
if (typeof value === 'function') {
remote[key] = /^[A-Z]/.test(key) ?
{
type: 'class',
path: path,
methods: Object.getOwnPropertyNames(value.prototype)
.filter(no(['constructor']))
.concat('destroy'),
statics: Object.getOwnPropertyNames(value)
.filter(no([
'arguments', 'callee', 'caller',
'length', 'name', 'prototype'
]))
.reduce(
function (info, key) {
if (typeof value[key] === 'function') {
info.methods.push(key);
} else {
info.values.push([key, value[key]]);
}
return info;
},
{
methods: [],
values: []
}
)
} :
{
type: 'function',
path: path
};
} else if (remote.toString.call(value) === '[object Object]') {
remote[key] = {
type: 'object',
path: path,
value: {}
};
$(value, path, remote[key].value);
} else if (value !== void 0) {
remote[key] = {
type: 'any',
path: path,
value: value
};
}
});
return remote;
}(object, [], {});
function no(within) {
return function (what) {
return within.indexOf(what) < 0;
};
}
}