-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson2entity.coffee
More file actions
86 lines (60 loc) · 1.46 KB
/
json2entity.coffee
File metadata and controls
86 lines (60 loc) · 1.46 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
fs = require 'fs'
path = require 'path'
optimist = require 'optimist'
argv = optimist.argv
source = fs.readFileSync(path.resolve(argv._[0]), "utf8")
o = JSON.parse source
clone = (obj) ->
if not obj? or typeof obj isnt 'object'
return obj
if obj instanceof Date
return new Date(obj.getTime())
if obj instanceof RegExp
flags = ''
flags += 'g' if obj.global?
flags += 'i' if obj.ignoreCase?
flags += 'm' if obj.multiline?
flags += 'y' if obj.sticky?
return new RegExp(obj.source, flags)
newInstance = new obj.constructor()
for key of obj
newInstance[key] = clone obj[key]
return newInstance
ent = { x: 10 }
log = console.log
log ent
log ent.prototype
ent2 = {}
ent2.__proto__ = ent
log ent2.x
for k, v of ent2
log k, v
count = 0
for id, version of o
log id
log version.bilateral['Version Originator']
log version.bilateral['Contract State']
for k of version.bilateral
count++
log count
count = 0
for id, version of o
ent = {}
ent.__proto__ = prev
for k, v of version.bilateral
if k not of ent or ent[k] != v
ent[k] = v
count++
prev = ent
log count
showDelta = (o) ->
for k, v of o
if not o.hasOwnProperty k
log k, v
showAllDelta = (o) ->
while o?
showDelta o
o = o.__proto__
#showDelta ent
# console.log ent
# console.log o