1.0.2 • Published 11 years ago

expands v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
11 years ago

expands

NPM version Build status Coveralls status Support us

Expands variable placeholders in objects.

Installation

This module can be installed easily with npm:

$ npm install expands

Usage

These examples show you how expands works:

var assert = require('assert');
var expand = require('expands');

// Expands string
assert.deepEqual(expand({
  message: 'Welcome {name}!',
  name: 'intruder'
}), {
  message: 'Welcome intruder!',
  name: 'intruder'
});

// Expands array
assert.deepEqual(expand({
  messages: [
    'Welcome {name}!',
    'You are {age} years old.',
    12345
  ],
  name: 'intruder',
  age: 1000
}), {
  messages: [
    'Welcome intruder!',
    'You are 1000 years old.',
    12345
  ],
  name: 'intruder',
  age: 1000
});

// Expands deep path
assert.deepEqual(expand({
  foo: {
    bar: {
      one: '1',
      two: '2'
    },
    message: 'One is {foo.bar.one} and two is {foo.bar.two}.'
  }
}), {
  foo: {
    bar: {
      one: '1',
      two: '2'
    },
    message: 'One is 1 and two is 2.'
  }
});

// Expands circle dependency
assert.deepEqual(expand({
  a: 'from {b}', // expanding is top-down so `a` will be expanded first
  b: 'from {c}',
  c: 'from {a}', // `a` is not expanded completely, resolved to 'from ',
}), {
  a: 'from from from from ',
  b: 'from from from ',
  c: 'from from '
});

Contributing

Before create a pull request, make sure that you:

To execute all tests, simply run:

$ npm test

Contributors

License

This module is released under MIT license.

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago