-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
34 lines (25 loc) · 859 Bytes
/
demo.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
const { mapper } = require('psdad')
const m = mapper() // maybe call it vocab?
class Circle {
constructor (state) {
Object.assign(this, state)
}
}
class Line {
constructor (state) {
Object.assign(this, state)
}
}
// maybe call it m.define(...)
m.add(Circle, 'There is a circle of radius [number radius] at position ([number x], [number y]).')
m.add(Line, 'There is a line from ([number x0], [number y0]) to ([number x1], [number y1]).')
const mydata = [
new Circle({ radius: 1, x: 10, y: 20 }),
new Line({ x0: 10, y0: 20, x1: 15, y1: 25 }),
new Circle({ radius: 2, x: 15, y: 25 })
]
console.log('\n## mydata=\n%O', mydata)
const str = m.stringify(mydata)
console.log('\n## stringify(mydata)=\n%s', str.slice(0, -1)) // console adds \n
const mydata2 = m.parse(str)
console.log('## parse(stringified(mydata))=\n%O', [...mydata2])