pax_global_header00006660000000000000000000000064127633016150014516gustar00rootroot0000000000000052 comment=bd40aff1fedecbb60d9bf0edcc950ecb937e5dbd set-value-0.4.0/000077500000000000000000000000001276330161500134245ustar00rootroot00000000000000set-value-0.4.0/.editorconfig000066400000000000000000000004051276330161500161000ustar00rootroot00000000000000root = true [*] indent_style = space end_of_line = lf charset = utf-8 indent_size = 2 trim_trailing_whitespace = true insert_final_newline = true [{**/{actual,fixtures,expected,templates}/**,*.md}] trim_trailing_whitespace = false insert_final_newline = falseset-value-0.4.0/.eslintrc.json000066400000000000000000000071251276330161500162250ustar00rootroot00000000000000{ "ecmaFeatures": { "modules": true, "experimentalObjectRestSpread": true }, "env": { "browser": false, "es6": true, "node": true, "mocha": true }, "globals": { "document": false, "navigator": false, "window": false }, "rules": { "accessor-pairs": 2, "arrow-spacing": [2, { "before": true, "after": true }], "block-spacing": [2, "always"], "brace-style": [2, "1tbs", { "allowSingleLine": true }], "comma-dangle": [2, "never"], "comma-spacing": [2, { "before": false, "after": true }], "comma-style": [2, "last"], "constructor-super": 2, "curly": [2, "multi-line"], "dot-location": [2, "property"], "eol-last": 2, "eqeqeq": [2, "allow-null"], "generator-star-spacing": [2, { "before": true, "after": true }], "handle-callback-err": [2, "^(err|error)$" ], "indent": [2, 2, { "SwitchCase": 1 }], "key-spacing": [2, { "beforeColon": false, "afterColon": true }], "keyword-spacing": [2, { "before": true, "after": true }], "new-cap": [2, { "newIsCap": true, "capIsNew": false }], "new-parens": 2, "no-array-constructor": 2, "no-caller": 2, "no-class-assign": 2, "no-cond-assign": 2, "no-const-assign": 2, "no-control-regex": 2, "no-debugger": 2, "no-delete-var": 2, "no-dupe-args": 2, "no-dupe-class-members": 2, "no-dupe-keys": 2, "no-duplicate-case": 2, "no-empty-character-class": 2, "no-eval": 2, "no-ex-assign": 2, "no-extend-native": 2, "no-extra-bind": 2, "no-extra-boolean-cast": 2, "no-extra-parens": [2, "functions"], "no-fallthrough": 2, "no-floating-decimal": 2, "no-func-assign": 2, "no-implied-eval": 2, "no-inner-declarations": [2, "functions"], "no-invalid-regexp": 2, "no-irregular-whitespace": 2, "no-iterator": 2, "no-label-var": 2, "no-labels": 2, "no-lone-blocks": 2, "no-mixed-spaces-and-tabs": 2, "no-multi-spaces": 2, "no-multi-str": 2, "no-multiple-empty-lines": [2, { "max": 1 }], "no-native-reassign": 0, "no-negated-in-lhs": 2, "no-new": 2, "no-new-func": 2, "no-new-object": 2, "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, "no-proto": 0, "no-redeclare": 2, "no-regex-spaces": 2, "no-return-assign": 2, "no-self-compare": 2, "no-sequences": 2, "no-shadow-restricted-names": 2, "no-spaced-func": 2, "no-sparse-arrays": 2, "no-this-before-super": 2, "no-throw-literal": 2, "no-trailing-spaces": 0, "no-undef": 2, "no-undef-init": 2, "no-unexpected-multiline": 2, "no-unneeded-ternary": [2, { "defaultAssignment": false }], "no-unreachable": 2, "no-unused-vars": [2, { "vars": "all", "args": "none" }], "no-useless-call": 0, "no-with": 2, "one-var": [0, { "initialized": "never" }], "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], "padded-blocks": [0, "never"], "quotes": [2, "single", "avoid-escape"], "radix": 2, "semi": [2, "always"], "semi-spacing": [2, { "before": false, "after": true }], "space-before-blocks": [2, "always"], "space-before-function-paren": [2, "never"], "space-in-parens": [2, "never"], "space-infix-ops": 2, "space-unary-ops": [2, { "words": true, "nonwords": false }], "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], "use-isnan": 2, "valid-typeof": 2, "wrap-iife": [2, "any"], "yoda": [2, "never"] } } set-value-0.4.0/.gitattributes000066400000000000000000000001771276330161500163240ustar00rootroot00000000000000# Enforce Unix newlines * text eol=lf # binaries *.ai binary *.psd binary *.jpg binary *.gif binary *.png binary *.jpeg binaryset-value-0.4.0/.gitignore000066400000000000000000000003431276330161500154140ustar00rootroot00000000000000# always ignore files *.DS_Store *.sublime-* # test related, or directories generated by tests test/actual actual coverage # npm node_modules npm-debug.log # misc _gh_pages benchmark bower_components vendor temp tmp TODO.md set-value-0.4.0/.travis.yml000066400000000000000000000003021276330161500155300ustar00rootroot00000000000000sudo: false language: node_js node_js: - '6' - '5' - '4' - '0.12' - '0.10' matrix: fast_finish: true allow_failures: - node_js: '4' - node_js: '0.10' - node_js: '0.12' set-value-0.4.0/.verb.md000066400000000000000000000010221276330161500147550ustar00rootroot00000000000000# {%= name %} {%= badge("fury") %} {%= badge("travis") %} > {%= description %} ## Install {%= include("install-npm", {save: true}) %} ## Usage ```js var set = require('{%= name %}'); var obj = {}; set(obj, 'a.b.c', 'd'); console.log(obj); //=> {a: {b: c: 'd'}} ``` ## Related projects {%= related(verb.related.list) %} ## Running tests {%= include("tests") %} ## Contributing {%= include("contributing") %} ## Author {%= include("author") %} ## License {%= copyright() %} {%= license %} *** {%= include("footer") %} set-value-0.4.0/LICENSE000066400000000000000000000020771276330161500144370ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-2016, Jon Schlinkert 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. set-value-0.4.0/README.md000066400000000000000000000056461276330161500147160ustar00rootroot00000000000000# set-value [![NPM version](https://img.shields.io/npm/v/set-value.svg)](https://www.npmjs.com/package/set-value) [![Build Status](https://img.shields.io/travis/jonschlinkert/set-value.svg)](https://travis-ci.org/jonschlinkert/set-value) > Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm i set-value --save ``` ## Usage ```js var set = require('set-value'); var obj = {}; set(obj, 'a.b.c', 'd'); console.log(obj); //=> {a: {b: c: 'd'}} ``` ## Related projects * [assign-value](https://www.npmjs.com/package/assign-value): Assign a value or extend a deeply nested property of an object using object path… [more](https://www.npmjs.com/package/assign-value) | [homepage](https://github.com/jonschlinkert/assign-value) * [get-value](https://www.npmjs.com/package/get-value): Use property paths (` a.b.c`) to get a nested value from an object. | [homepage](https://github.com/jonschlinkert/get-value) * [has-value](https://www.npmjs.com/package/has-value): Returns true if a value exists, false if empty. Works with deeply nested values using… [more](https://www.npmjs.com/package/has-value) | [homepage](https://github.com/jonschlinkert/has-value) * [merge-value](https://www.npmjs.com/package/merge-value): Similar to assign-value but deeply merges object values or nested values using object path/dot notation. | [homepage](https://github.com/jonschlinkert/merge-value) * [omit-value](https://www.npmjs.com/package/omit-value): Omit properties from an object or deeply nested property of an object using object path… [more](https://www.npmjs.com/package/omit-value) | [homepage](https://github.com/jonschlinkert/omit-value) * [set-value](https://www.npmjs.com/package/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths. | [homepage](https://github.com/jonschlinkert/set-value) * [union-value](https://www.npmjs.com/package/union-value): Set an array of unique values as the property of an object. Supports setting deeply… [more](https://www.npmjs.com/package/union-value) | [homepage](https://github.com/jonschlinkert/union-value) * [unset-value](https://www.npmjs.com/package/unset-value): Delete nested properties from an object using dot notation. | [homepage](https://github.com/jonschlinkert/unset-value) ## Running tests Install dev dependencies: ```sh $ npm i -d && npm test ``` ## Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/set-value/issues/new). ## Author **Jon Schlinkert** * [github/jonschlinkert](https://github.com/jonschlinkert) * [twitter/jonschlinkert](http://twitter.com/jonschlinkert) ## License Copyright © 2016 [Jon Schlinkert](https://github.com/jonschlinkert) Released under the MIT license. *** _This file was generated by [verb](https://github.com/verbose/verb) on January 19, 2016._set-value-0.4.0/index.js000066400000000000000000000021261276330161500150720ustar00rootroot00000000000000/*! * set-value * * Copyright (c) 2014-2015, Jon Schlinkert. * Licensed under the MIT License. */ 'use strict'; var toPath = require('to-object-path'); var extend = require('extend-shallow'); var isObject = require('is-plain-object'); module.exports = function(obj, path, val) { if (typeof obj !== 'object') { return obj; } if (Array.isArray(path)) { path = toPath(path); } if (typeof path !== 'string') { return obj; } var segs = path.split('.'); var len = segs.length, i = -1; var res = obj; var last; while (++i < len) { var key = segs[i]; while (key[key.length - 1] === '\\') { key = key.slice(0, -1) + '.' + segs[++i]; } if (i === len - 1) { last = key; break; } if (typeof obj[key] !== 'object') { obj[key] = {}; } obj = obj[key]; } if (obj.hasOwnProperty(last) && typeof obj[last] === 'object') { if (isObject(val)) { extend(obj[last], val); } else { obj[last] = val; } } else { obj[last] = val; } return res; }; set-value-0.4.0/package.json000066400000000000000000000026671276330161500157250ustar00rootroot00000000000000{ "name": "set-value", "description": "Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.", "version": "0.4.0", "homepage": "https://github.com/jonschlinkert/set-value", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "contributors": [ "Jon Schlinkert (http://twitter.com/jonschlinkert)", "Vadim Demedes (https://ava.li)" ], "repository": "jonschlinkert/set-value", "bugs": { "url": "https://github.com/jonschlinkert/set-value/issues" }, "license": "MIT", "files": [ "index.js" ], "main": "index.js", "engines": { "node": ">=0.10.0" }, "scripts": { "test": "mocha" }, "dependencies": { "extend-shallow": "^2.0.1", "is-plain-object": "^2.0.1", "to-object-path": "^0.2.0" }, "devDependencies": { "gulp-format-md": "^0.1.10", "mocha": "^3.0.2" }, "keywords": [ "get", "has", "hasown", "key", "keys", "nested", "notation", "object", "prop", "properties", "property", "props", "set", "value", "values" ], "verb": { "plugins": [ "gulp-format-md" ], "related": { "description": "", "list": [ "assign-value", "get-value", "has-value", "merge-value", "omit-value", "set-value", "union-value", "unset-value" ] } } } set-value-0.4.0/test.js000066400000000000000000000104511276330161500147420ustar00rootroot00000000000000/*! * set-value * * Copyright (c) 2014-2015, Jon Schlinkert. * Licensed under the MIT License. */ 'use strict'; require('mocha'); var assert = require('assert'); var set = require('./'); describe('set', function() { it('should return non-objects', function() { var res = set('foo', 'a.b', 'c'); assert.equal(res, 'foo'); }); it('should create a nested property if it does not already exist:', function() { var o = {}; set(o, 'a.b', 'c'); assert.equal(o.a.b, 'c'); }); it('should extend an existing value:', function() { var o = {a: {b: {c: 'd'}}}; set(o, 'a.b', {y: 'z'}); assert.deepEqual(o.a.b, {c: 'd', y: 'z'}); }); it('should update an object value:', function() { var o = {}; set(o, 'a', {b: 'c'}); set(o, 'a', {c: 'd'}); assert.deepEqual(o, {a: {b: 'c', c: 'd'}}); set(o, 'a', 'b'); assert.equal(o.a, 'b'); }); it('should extend an array:', function() { var o = {a: []}; set(o, 'a.0', {y: 'z'}); assert(Array.isArray(o.a)); assert.deepEqual(o.a[0], {y: 'z'}); }); it('should extend an object in an array:', function() { var o = {a: [{}, {}, {}]}; set(o, 'a.0.a', {y: 'z'}); set(o, 'a.1.b', {y: 'z'}); set(o, 'a.2.c', {y: 'z'}); assert(Array.isArray(o.a)); assert.deepEqual(o.a[0].a, {y: 'z'}); assert.deepEqual(o.a[1].b, {y: 'z'}); assert.deepEqual(o.a[2].c, {y: 'z'}); }); it('should create a deeply nested property if it does not already exist:', function() { var o = {}; set(o, 'a.b.c.d.e', 'c'); assert.equal(o.a.b.c.d.e, 'c'); }); it('should not create a nested property if it does already exist:', function() { var first = {name: 'Halle'}; var o = {a: first }; set(o, 'a.b', 'c'); assert.equal(o.a.b, 'c'); assert.equal(o.a, first); assert.equal(o.a.name, 'Halle'); }); it('should support immediate properties:', function() { var o = {}; set(o, 'a', 'b'); assert.equal(o.a, 'b'); }); it('should use property paths to set nested values from the source object.', function() { var o = {}; set(o, 'a.locals.name', {first: 'Brian'}); set(o, 'b.locals.name', {last: 'Woodward'}); set(o, 'b.locals.name.last', 'Woodward'); assert.deepEqual(o, { a: {locals: {name: { first: 'Brian' }} }, b: {locals: {name: { last: 'Woodward' }} }}); }); it('should add the property even if a value is not defined:', function() { var fixture = {}; assert.deepEqual(set(fixture, 'a.locals.name'), {a: {locals: { name: undefined }}}); assert.deepEqual(set(fixture, 'b.locals.name'), {b: {locals: { name: undefined }}, a: {locals: { name: undefined }}}); }); it('should set the specified property.', function() { assert.deepEqual(set({a: 'aaa', b: 'b'}, 'a', 'bbb'), {a: 'bbb', b: 'b'}); }); it('should support passing an array as the key', function() { var actual = set({a: 'a', b: {c: 'd'}}, ['b', 'c', 'd'], 'eee'); assert.deepEqual(actual, {a: 'a', b: {c: {d: 'eee'}}}); }); it('should set a deeply nested value.', function() { var actual = set({a: 'a', b: {c: 'd'}}, 'b.c.d', 'eee'); assert.deepEqual(actual, {a: 'a', b: {c: {d: 'eee'}}}); }); it('should return the entire object if no property is passed.', function() { assert.deepEqual(set({a: 'a', b: {c: 'd'}}), {a: 'a', b: {c: 'd'}}); }); it('should set a value only.', function() { assert.deepEqual(set({a: 'a', b: {c: 'd'}}, 'b.c'), {a: 'a', b: {c: undefined}}); }); it('should set non-plain objects', function(done) { var o = {}; set(o, 'a.b', new Date()); var firstDate = o.a.b.getTime(); setTimeout(function() { set(o, 'a.b', new Date()); var secondDate = o.a.b.getTime(); assert.notDeepEqual(firstDate, secondDate); done(); }, 10); }); }); describe('escaping', function() { it('should recognize escaped dots:', function() { var o = {}; set(o, 'a\\.b.c.d.e', 'c'); assert.equal(o['a.b'].c.d.e, 'c'); }); it('should work with multple escaped dots:', function() { var o = {}; set(o, 'e\\.f\\.g', 1); assert.equal(o['e.f.g'], 1); }); it('should work with multple escaped dots:', function() { var o = {}; set(o, 'e\\.f.g\\.h\\.i.j', 1); assert.deepEqual(o, { 'e.f': { 'g.h.i': { j: 1 } } }); }); });