[Pkg-javascript-commits] [node-set-value] 01/03: Import Upstream version 0.4.0
Praveen Arimbrathodiyil
praveen at moszumanska.debian.org
Thu Oct 27 13:15:36 UTC 2016
This is an automated email from the git hooks/post-receive script.
praveen pushed a commit to branch master
in repository node-set-value.
commit 8624bee50a44d774d72cf5fff551259dba6836c7
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date: Thu Oct 27 18:13:26 2016 +0530
Import Upstream version 0.4.0
---
.editorconfig | 13 +++++
.eslintrc.json | 122 ++++++++++++++++++++++++++++++++++++++++++++++
.gitattributes | 10 ++++
.gitignore | 21 ++++++++
.travis.yml | 14 ++++++
.verb.md | 37 ++++++++++++++
LICENSE | 21 ++++++++
README.md | 61 +++++++++++++++++++++++
index.js | 61 +++++++++++++++++++++++
package.json | 70 +++++++++++++++++++++++++++
test.js | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 files changed, 580 insertions(+)
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..818e072
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,13 @@
+root = 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 = false
\ No newline at end of file
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..948dbdb
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,122 @@
+{
+ "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"]
+ }
+}
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..4a3f1d3
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,10 @@
+# Enforce Unix newlines
+* text eol=lf
+
+# binaries
+*.ai binary
+*.psd binary
+*.jpg binary
+*.gif binary
+*.png binary
+*.jpeg binary
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7988154
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,21 @@
+# 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
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..3932eaa
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,14 @@
+sudo: 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'
diff --git a/.verb.md b/.verb.md
new file mode 100644
index 0000000..c3be28f
--- /dev/null
+++ b/.verb.md
@@ -0,0 +1,37 @@
+# {%= 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") %}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..842218c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The 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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0fa9e96
--- /dev/null
+++ b/README.md
@@ -0,0 +1,61 @@
+# 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._
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..2a99a98
--- /dev/null
+++ b/index.js
@@ -0,0 +1,61 @@
+/*!
+ * set-value <https://github.com/jonschlinkert/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;
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..b112ff8
--- /dev/null
+++ b/package.json
@@ -0,0 +1,70 @@
+{
+ "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 <jon.schlinkert at sellside.com> (http://twitter.com/jonschlinkert)",
+ "Vadim Demedes <vdemedes at gmail.com> (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"
+ ]
+ }
+ }
+}
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..3c3f4de
--- /dev/null
+++ b/test.js
@@ -0,0 +1,150 @@
+/*!
+ * set-value <https://github.com/jonschlinkert/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 } } });
+ });
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-set-value.git
More information about the Pkg-javascript-commits
mailing list