0.5.12 • Published 3 years ago

exm v0.5.12

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

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"
    ]
}
0.5.10

3 years ago

0.5.11

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.9

3 years ago

0.5.12

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.4.0

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.0.1

10 years ago