set-getter
Create nested getter properties and any intermediary dot notation (`'a.b.c'`) paths
Last updated 8 years ago by doowb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install set-getter 
SYNC missed versions from official npm registry.

set-getter NPM version NPM monthly downloads NPM total downloads Linux Build Status

Create nested getter properties and any intermediary dot notation ('a.b.c') paths

Please consider following this project's author, Brian Woodward, and consider starring the project to show your :heart: and support.

Install

Install with npm:

$ npm install --save set-getter

Usage

var getter = require('set-getter');

set-getter works like set-value by adding a property to an object or an object hierarchy using dot notation. The main difference is that the property is added using Object.defineProperty and is expected to be a getter function that returns a value.

Example

var obj = {};

// root level property
getter(obj, 'foo', function() {
  return 'bar';
});
console.log(obj.foo);
//=> 'bar'

// property dot notation
getter(obj, 'bar.baz', function() {
  return 'qux';
});
console.log(obj.bar.baz);
//=> 'qux'

// property array notation
getter(obj, ['beep', 'boop'], function() {
  return 'bop';
});
console.log(obj.beep.boop);
//=> 'bop'

API

setGetter

Defines a getter function on an object using property path notation.

Params

  • obj {Object}: Object to add property to.
  • prop {String|Array}: Property string or array to add.
  • getter {Function}: Getter function to add as a property.

Example

var obj = {};
getter(obj, 'foo', function() {
  return 'bar';
});

About

<summary>Contributing</summary>

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

<summary>Running Tests</summary>

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
<summary>Building docs</summary>

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Author

Brian Woodward

License

Copyright © 2021, Brian Woodward. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on June 18, 2021.

Current Tags

  • 0.1.1                                ...           latest (3 years ago)

2 Versions

  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           8 years ago
Maintainers (2)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)

Copyright 2013 - present © cnpmjs.org | Home |