0.2.0 • Published 10 years ago

addressable-node v0.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
10 years ago

Build Status

Code Climate

Addressable

Small library for accessing nested properties of a Javascript object.

Install

Install via Bower or NPM.

npm install addressable-node
bower install addressable

Node Example

var obj = {
  id: 1,
  name: 'Bob',
  age: 31,
  country: {
    id: 1,
    name: 'USA'
  },
  tags: [
    { color: { name: 'blue' } },
    { color: { name: 'yellow' } }
  ]
}

var Addressable = require('addressable-node');

Addressable.find(obj, 'country.name') => 'USA'
new Addressable(obj).find('country.name') => 'USA'

Addressable.find(obj, 'tags[].color.name') => [ 'blue', 'yellow' ]

See tests for full example

Angular Example

angular.module('myApp', ['addressable']);

angular.module('myApp').factory('Person', ['Addressable', function (Addressable) {
  var Person = function () {
    this.country = {
      name: 'United States',
      shortName: 'USA'
    }
  };

  Person.prototype.countryName = function () {
    return Addressable.find(this, 'country.name');
  };

  return Person;
}]);

Build

To build the browserify module version of the gem use the npm build script.

npm run build

This builds a new version in the dist directory.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Release History

  • 0.2.0 Add Angular module
  • 0.1.1 Add Bower Package
  • 0.1.0 Initial release