constantina

v0.1.1
Recursive, namespaced, key-mirror without `foo: null`.
recursive namespace keymirror key mirror

constantina

Recursive, namespaced key mirror without foo: null.

keymirror is cool, recursive key mirrors are better, but I don't like that mess with *: null:

require('keymirror')({
    "foo": null,
    "bar": null,
    "baz": null
});

Recursive key-mirrors exist but none, to my knowledge, avoid the null stuff.

constantinas approach is different:

var constantina = require('constantina');

constantina({
    "foo": ["bar", "baz"],
    "quux": "beep"
});

// or use this syntax...
constantina([
    { "foo": ["bar", "baz"] },
    { "quux": "beep"}
]);

// => { "foo": { "bar" : "bar@foo", "baz" : "baz@foo" }, "quux": { "beep": "beep@quux" } }

More examples:

$ node
> var f = require('constantina');
undefined
> f
[Function: ƒ]
> f({"foo": ["bar", "baz"], "quux": "beep"});
{ foo: { bar: 'bar@foo', baz: 'baz@foo' },
  quux: { beep: 'beep@quux' } }
> f([{foo: ["bar", "baz"]}, { "quux": "beep" }]);
{ foo: { bar: 'bar@foo', baz: 'baz@foo' },
  quux: { beep: 'beep@quux' } }
> f(["one", "two", "three"]);
{ one: 'one', two: 'two', three: 'three' }
> f({"foo": [{ "bar": ["one", "two", "three"]}, "baz", {"bazzier": "bazziest"}], "quux": {"beep": "boop"}});
{ foo: 
   { bar: 
      { one: '[email protected]',
        two: '[email protected]',
        three: '[email protected]' },
     baz: 'baz@foo',
     bazzier: { bazziest: '[email protected]' } },
  quux: { beep: { boop: '[email protected]' } } }
> 
npm i constantina

Metadata

  • MIT
  • Whatever
  • sterpe
  • released 9/28/2015

Downloads

Maintainers