exm v0.5.12
exm
A (hobby) library to support the encoding of Javascript object inheritance in JSON. This library is not yet available via NPM, and is under active pre-release development.
Inserting external values
You can insert external values into object fields if the value for any key starts with the dot-space '. <url>'
notation.
/** example.js */
var exm = require('exm');
var blueprint = {
"hello" : ". http://example.com/hello"
};
exm(blueprint, function(err, result) {
console.log( JSON.stringify(result) );
});
/** http://example.com/hello */
{
"name": "Gulliver",
"title": "Mr.",
"aliases", [ "Manfred", "Allen", "Bob" ]
}
/** result */
{
"hello" : {
"name": "Gulliver",
"title": "Mr.",
"aliases", [ "Manfred", "Allen", "Bob" ]
}
}
Insert in place
Using a variation on the dot-space notion, you can use exm to inherit from external objects. When an object key is "."
, the value is used as the external URL.
/** blueprint */
{
"." : "http://example.com/hello"
"title" : "Sgt.",
"phone" : "301-555-1234"
}
/** result */
{
"name": "Gulliver",
"title" : "Sgt.",
"phone" : "301-555-1234",
"aliases", [ "Manfred", "Allen", "Bob" ]
}
Notice that the value for inhertited field title
was overridden, and the new field phone
was added.
Inserting in place can be used anywhere in the blueprint object.
/** blueprint */
{
"foo" : "bar",
"hello" : {
"." : "http://example.com/hello"
}
}
/** result */
{
"foo" : "bar",
"hello" : {
"name": "Gulliver",
"title": "Mr."
},
"aliases", [ "Manfred", "Allen", "Bob" ]
}
Arrays
UNDER DEVELOPMENT
Because order in array values is important, there are additional notions that allow you to control what
{
"hello" : [
"..",
"0..n",
"0..2",
". http://foobar"
]
}
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
10 years ago