aboutsummaryrefslogtreecommitdiff
path: root/node_modules/set-getter
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/set-getter')
-rw-r--r--node_modules/set-getter/LICENSE21
-rw-r--r--node_modules/set-getter/README.md109
-rw-r--r--node_modules/set-getter/index.js83
-rw-r--r--node_modules/set-getter/package.json47
4 files changed, 260 insertions, 0 deletions
diff --git a/node_modules/set-getter/LICENSE b/node_modules/set-getter/LICENSE
new file mode 100644
index 000000000..3f525ab13
--- /dev/null
+++ b/node_modules/set-getter/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016, Brian Woodward.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/node_modules/set-getter/README.md b/node_modules/set-getter/README.md
new file mode 100644
index 000000000..072d3eaca
--- /dev/null
+++ b/node_modules/set-getter/README.md
@@ -0,0 +1,109 @@
+# set-getter [![NPM version](https://img.shields.io/npm/v/set-getter.svg?style=flat)](https://www.npmjs.com/package/set-getter) [![NPM downloads](https://img.shields.io/npm/dm/set-getter.svg?style=flat)](https://npmjs.org/package/set-getter) [![Build Status](https://img.shields.io/travis/doowb/set-getter.svg?style=flat)](https://travis-ci.org/doowb/set-getter)
+
+> Create nested getter properties and any intermediary dot notation (`'a.b.c'`) paths
+
+## Install
+
+Install with [npm](https://www.npmjs.com/):
+
+```sh
+$ npm install set-getter --save
+```
+
+## Usage
+
+```js
+var getter = require('set-getter');
+```
+
+set-getter works like [set-value](https://github.com/jonschlinkert/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**
+
+```js
+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](index.js#L27)
+
+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**
+
+```js
+var obj = {};
+getter(obj, 'foo', function() {
+ return 'bar';
+});
+```
+
+## Contributing
+
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/doowb/set-getter/issues/new).
+
+## Building docs
+
+Generate readme and API documentation with [verb](https://github.com/verbose/verb):
+
+```sh
+$ npm install verb && npm run docs
+```
+
+Or, if [verb](https://github.com/verbose/verb) is installed globally:
+
+```sh
+$ verb
+```
+
+## Running tests
+
+Install dev dependencies:
+
+```sh
+$ npm install -d && npm test
+```
+
+## Author
+
+**Brian Woodward**
+
+* [github/doowb](https://github.com/doowb)
+* [twitter/doowb](http://twitter.com/doowb)
+
+## License
+
+Copyright © 2016, [Brian Woodward](https://github.com/doowb).
+Released under the [MIT license](https://github.com/doowb/set-getter/blob/master/LICENSE).
+
+***
+
+_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 29, 2016._ \ No newline at end of file
diff --git a/node_modules/set-getter/index.js b/node_modules/set-getter/index.js
new file mode 100644
index 000000000..ce9a6a0d4
--- /dev/null
+++ b/node_modules/set-getter/index.js
@@ -0,0 +1,83 @@
+/*!
+ * set-getter (https://github.com/doowb/set-getter)
+ *
+ * Copyright (c) 2016, Brian Woodward.
+ * Licensed under the MIT License.
+ */
+
+'use strict';
+
+var toPath = require('to-object-path');
+
+/**
+ * Defines a getter function on an object using property path notation.
+ *
+ * ```js
+ * var obj = {};
+ * getter(obj, 'foo', function() {
+ * return 'bar';
+ * });
+ * ```
+ * @param {Object} `obj` Object to add property to.
+ * @param {String|Array} `prop` Property string or array to add.
+ * @param {Function} `getter` Getter function to add as a property.
+ * @api public
+ */
+
+function setGetter(obj, prop, getter) {
+ var key = toPath(arguments);
+ return define(obj, key, getter);
+}
+
+/**
+ * Define getter function on object or object hierarchy using dot notation.
+ *
+ * @param {Object} `obj` Object to define getter property on.
+ * @param {String} `prop` Property string to define.
+ * @param {Function} `getter` Getter function to define.
+ * @return {Object} Returns original object.
+ */
+
+function define(obj, prop, getter) {
+ if (!~prop.indexOf('.')) {
+ defineProperty(obj, prop, getter);
+ return obj;
+ }
+
+ var keys = prop.split('.');
+ var last = keys.pop();
+ var target = obj;
+ var key;
+
+ while ((key = keys.shift())) {
+ while (key.slice(-1) === '\\') {
+ key = key.slice(0, -1) + '.' + keys.shift();
+ }
+ target = target[key] || (target[key] = {});
+ }
+
+ defineProperty(target, last, getter);
+ return obj;
+}
+
+/**
+ * Define getter function on object as a configurable and enumerable property.
+ *
+ * @param {Object} `obj` Object to define property on.
+ * @param {String} `prop` Property to define.
+ * @param {Function} `getter` Getter function to define.
+ */
+
+function defineProperty(obj, prop, getter) {
+ Object.defineProperty(obj, prop, {
+ configurable: true,
+ enumerable: true,
+ get: getter
+ });
+}
+
+/**
+ * Expose `setGetter`
+ */
+
+module.exports = setGetter;
diff --git a/node_modules/set-getter/package.json b/node_modules/set-getter/package.json
new file mode 100644
index 000000000..cb8a03589
--- /dev/null
+++ b/node_modules/set-getter/package.json
@@ -0,0 +1,47 @@
+{
+ "name": "set-getter",
+ "description": "Create nested getter properties and any intermediary dot notation (`'a.b.c'`) paths",
+ "version": "0.1.0",
+ "homepage": "https://github.com/doowb/set-getter",
+ "author": "Brian Woodward (https://github.com/doowb)",
+ "repository": "doowb/set-getter",
+ "bugs": {
+ "url": "https://github.com/doowb/set-getter/issues"
+ },
+ "license": "MIT",
+ "files": [
+ "index.js"
+ ],
+ "main": "index.js",
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "mocha"
+ },
+ "dependencies": {
+ "to-object-path": "^0.3.0"
+ },
+ "devDependencies": {
+ "gulp-format-md": "^0.1.9",
+ "mocha": "^2.4.5"
+ },
+ "keywords": [],
+ "verb": {
+ "plugins": [
+ "gulp-format-md"
+ ],
+ "reflinks": [
+ "verb",
+ "set-value"
+ ],
+ "layout": "default",
+ "toc": false,
+ "tasks": [
+ "readme"
+ ],
+ "lint": {
+ "reflinks": true
+ }
+ }
+}