psdad.js
JavaScript implementation of psdad, for node.js or browsers
Example
Example (in demo.js)
const mapper = const vocab = { Object } { Object } vocabvocab const mydata = radius: 1 x: 10 y: 20 x0: 10 y0: 20 x1: 15 y1: 25 radius: 2 x: 15 y: 25 const str = vocabconsole/* =>There is a circle of radius 1 at position (10, 20). There is a line from (10, 20) to (15, 25). There is a circle of radius 2 at position (15, 25). */ const mydata2 = vocabconsole/* =>[ Circle { radius: 1, x: 10, y: 20 }, Line { x0: 10, y0: 20, x1: 15, y1: 25 }, Circle { radius: 2, x: 15, y: 25 } ]*/
Performance
Some quick tests show stringify() running about 1m objects per second, and parse() running about about 150k objects per second. That's not as fast as the native JSON functions (maybe 50% of JSON on stringify and 10% on parse), but it's still probably fast enough. The parsing is all done with one compiled regexp. It will be interesting to see how it's affect by having larger definitions and more classes.