** Basic
#+BEGIN_SRC javascript
var restruct = require('restruct-data');
var struct = restruct.structure({
"Hello": "< text"
});
var result = struct({
text: "World"
});
// result = { "Hello": "World!" };
#+END_SRC
** Frame
#+BEGIN_SRC javascript
var Restruct = require('restruct-data');
var restruct = Restruct();
restruct.method('frame_info', function() {
if (this.index === 0) {
this.index // 0
this.data // { "id": 1, "name": "Chuck Norris" }
// 'this.data' is the same as 'this.source[this.index]'
this.parent // parent Frame( [ { "id": 1, ...}, { "id": 2, ...} ] )
this.source() // "this.parent.data" but returns null if no parent
this.keys() // [ 'id', 'name' ]
this.values() // [ 1, 'Chuck Norris' ]
this.child('id') // Frame(1)
this.child('name') // Frame('Chuck Norris')
this.children() // [ Frame(1), Frame('Chuck Norris') ]
this.restruct // restruct instance
this.restruct.root // root Frame(...), which would be 'this.parent' in this case
}
});
var collection = restruct.collection([
{
"id": 1,
"name": "Chuck Norris"
},{
"id": 2,
"name": "Robin Williams"
}
]);
var result = collection.format({
"< id": "= frame_info()"
});
#+END_SRC