| module.exports = require('./lib/nessy'); |
| 'use strict'; | ||
| module.exports = function (selector, value, obj) { | ||
| obj = obj || {}; | ||
| var result = obj; | ||
| check(selector); | ||
| selector.split('.').forEach(function (name, i, arr) { | ||
| if (i === arr.length - 1) obj[name] = value;else if (!obj[name]) obj[name] = {}; | ||
| obj = obj[name]; | ||
| }); | ||
| return result; | ||
| }; | ||
| function check(selector) { | ||
| if (typeof selector !== 'string') throw Error('selector should be string!'); | ||
| } |
+19
-13
| 'use strict'; | ||
| module.exports = function (selector, value, obj) { | ||
| module.exports = (selector, value, obj) => { | ||
| obj = obj || {}; | ||
| var result = obj; | ||
| const result = obj; | ||
| check(selector); | ||
| selector.split('.').forEach(function (name, i, arr) { | ||
| if (i === arr.length - 1) obj[name] = value;else if (!obj[name]) obj[name] = {}; | ||
| obj = obj[name]; | ||
| }); | ||
| selector.split('.') | ||
| .forEach((name, i, arr) => { | ||
| if (i === arr.length - 1) | ||
| obj[name] = value; | ||
| else if (!obj[name]) | ||
| obj[name] = {}; | ||
| obj = obj[name]; | ||
| }); | ||
| return result; | ||
@@ -20,3 +24,5 @@ }; | ||
| function check(selector) { | ||
| if (typeof selector !== 'string') throw Error('selector should be string!'); | ||
| } | ||
| if (typeof selector !== 'string') | ||
| throw Error('selector should be string!'); | ||
| } | ||
+13
-12
| { | ||
| "name": "nessy", | ||
| "version": "1.1.1", | ||
| "version": "2.0.0", | ||
| "description": "set value in nested object", | ||
@@ -8,20 +8,21 @@ "main": "lib/nessy.js", | ||
| "test": "tape test/*.js", | ||
| "watcher": "nodemon -w test -w lib --exec", | ||
| "watch:test": "npm run watcher -- npm test", | ||
| "watcher": "nodemon -w test -w src --exec", | ||
| "init": "mkdirp lib", | ||
| "jscs": "jscs --esnext src test", | ||
| "jshint": "jshint src test", | ||
| "codestyle": "redrun jshint jscs", | ||
| "build": "redrun init clean 6to5 bundle bundle:es6 minify", | ||
| "jscs": "jscs --esnext lib test", | ||
| "jshint": "jshint lib test", | ||
| "lint": "redrun jshint jscs", | ||
| "build": "redrun clean init 6to5 legacy:* bundle bundle:es6 minify", | ||
| "minify": "minify dist/nessy.js > dist/nessy.min.js", | ||
| "6to5": "babel -d lib src", | ||
| "wisdom": "npm run build", | ||
| "jscs-fix": "npm run jscs --fix", | ||
| "clean": "rimraf lib/* dist/*", | ||
| "init": "mkdirp dist legacy", | ||
| "clean": "rimraf legacy dist", | ||
| "bundle:base": "browserify -s nessy --ng false", | ||
| "bundle": "npm run bundle:base -- -r ./lib/nessy.js:nessy ./lib/nessy.js -o dist/nessy.js", | ||
| "bundle:es6:base": "npm run bundle:base -- -r ./src/nessy.js:nessy ./src/nessy.js", | ||
| "bundle": "npm run bundle:base -- -r ./legacy/lib/nessy.js:nessy ./legacy/lib/nessy.js -o dist/nessy.js", | ||
| "bundle:es6:base": "npm run bundle:base -- -r ./lib/nessy.js:nessy ./lib/nessy.js", | ||
| "bundle:es6": "npm run bundle:es6:base -- -o dist/nessy.es6.js", | ||
| "coverage": "nyc npm test", | ||
| "report": "nyc report --reporter=text-lcov | coveralls" | ||
| "report": "nyc report --reporter=text-lcov | coveralls", | ||
| "6to5": "babel lib -d legacy/lib", | ||
| "legacy:index": "echo \"module.exports = require('./lib/nessy');\" > legacy/index.js" | ||
| }, | ||
@@ -28,0 +29,0 @@ "repository": { |
+14
-1
| # Nessy [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL] | ||
| Set value in nested object. Use [jessy](https://github.com/coderaiser/jessy "jessy") to get value. | ||
| Set value in nested object. | ||
@@ -32,2 +32,15 @@ ## Install | ||
| ## Environments | ||
| In old `node.js` environments that not fully supports `es2015`, `nessy` could be used with: | ||
| ```js | ||
| var nessy = require('nessy/legacy'); | ||
| ``` | ||
| ## Related | ||
| - [jessy](https://github.com/coderaiser/jessy "jessy") - get value by object property. | ||
| - [all-object-keys](https://github.com/coderaiser/all-object-keys "all-object-keys") - get all keys of object. | ||
| ## License | ||
@@ -34,0 +47,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6487
17.73%7
16.67%33
153.85%60
27.66%