[Pkg-javascript-commits] [node-unset-value] 01/06: Import Upstream version 0.1.1

Sruthi Chandran srud-guest at moszumanska.debian.org
Thu Oct 27 14:26:42 UTC 2016


This is an automated email from the git hooks/post-receive script.

srud-guest pushed a commit to branch master
in repository node-unset-value.

commit 761f4b3fc28fec6c623e741baaaa0c0380ae20f7
Author: Sruthi <srud at disroot.org>
Date:   Thu Oct 27 19:35:40 2016 +0530

    Import Upstream version 0.1.1
---
 .editorconfig  |  22 ++++++++++++
 .gitattributes |  10 ++++++
 .gitignore     |  15 ++++++++
 .jshintrc      |  19 ++++++++++
 .travis.yml    |   5 +++
 .verb.md       |  89 +++++++++++++++++++++++++++++++++++++++++++++
 LICENSE        |  21 +++++++++++
 README.md      | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 index.js       |  32 +++++++++++++++++
 package.json   |  56 +++++++++++++++++++++++++++++
 test.js        |  69 +++++++++++++++++++++++++++++++++++
 11 files changed, 450 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..1ff40e6
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,22 @@
+# http://editorconfig.org
+root = true
+
+[*]
+indent_style = space
+end_of_line = lf
+charset = utf-8
+indent_size = 2
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false
+insert_final_newline = false
+
+[{,test/}{actual,fixtures}/**]
+trim_trailing_whitespace = false
+insert_final_newline = false
+
+[templates/**]
+trim_trailing_whitespace = false
+insert_final_newline = false
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..660957e
--- /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
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..80a228c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,15 @@
+*.DS_Store
+*.sublime-*
+_gh_pages
+bower_components
+node_modules
+npm-debug.log
+actual
+test/actual
+temp
+tmp
+TODO.md
+vendor
+.idea
+benchmark
+coverage
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..1d9d592
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,19 @@
+{
+  "asi": false,
+  "boss": true,
+  "curly": false,
+  "eqeqeq": true,
+  "eqnull": true,
+  "esnext": true,
+  "immed": true,
+  "latedef": false,
+  "laxbreak": true,
+  "laxcomma": false,
+  "mocha": true,
+  "newcap": true,
+  "noarg": true,
+  "node": true,
+  "sub": true,
+  "undef": true,
+  "unused": true
+}
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..d7a0715
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+  - "stable"
+  - "0.12"
+  - "0.10"
diff --git a/.verb.md b/.verb.md
new file mode 100644
index 0000000..212bbe9
--- /dev/null
+++ b/.verb.md
@@ -0,0 +1,89 @@
+# {%= name %} {%= badge("fury") %}
+
+> {%= description %}
+
+## Install
+{%= include("install-npm", {save: true}) %}
+
+## Usage
+
+```js
+var unset = require('{%= name %}');
+
+var obj = {a: {b: {c: 'd', e: 'f'}}};
+unset(obj, 'a.b.c');
+console.log(obj);
+//=> {a: {b: {e: 'f'}}};
+```
+
+## Examples
+
+### Updates the object when a property is deleted
+
+```js
+var obj = {a: 'b'};
+unset(obj, 'a');
+console.log(obj);
+//=> {}
+```
+
+### Returns true when a property is deleted
+
+```js
+unset({a: 'b'}, 'a') // true
+```
+
+### Returns `true` when a property does not exist
+
+This is consistent with `delete` behavior in that it does not
+throw when a property does not exist. 
+
+```js
+unset({a: {b: {c: 'd'}}}, 'd') // true
+```
+
+### delete nested values
+
+```js
+var one = {a: {b: {c: 'd'}}};
+unset(one, 'a.b');
+console.log(one);
+//=> {a: {}}
+
+var two = {a: {b: {c: 'd'}}};
+unset(two, 'a.b.c');
+console.log(two);
+//=> {a: {b: {}}}
+
+var three = {a: {b: {c: 'd', e: 'f'}}};
+unset(three, 'a.b.c');
+console.log(three);
+//=> {a: {b: {e: 'f'}}}
+```
+
+### throws on invalid args
+
+```js
+unset();
+// 'expected an object.'
+```
+
+## Related projects
+{%= related(verb.related.list, {remove: name}) %}  
+
+## 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..65f90ac
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2015, 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..8329f95
--- /dev/null
+++ b/README.md
@@ -0,0 +1,112 @@
+# unset-value [![NPM version](https://badge.fury.io/js/unset-value.svg)](http://badge.fury.io/js/unset-value)
+
+> Delete nested properties from an object using dot notation.
+
+## Install
+
+Install with [npm](https://www.npmjs.com/)
+
+```sh
+$ npm i unset-value --save
+```
+
+## Usage
+
+```js
+var unset = require('unset-value');
+
+var obj = {a: {b: {c: 'd', e: 'f'}}};
+unset(obj, 'a.b.c');
+console.log(obj);
+//=> {a: {b: {e: 'f'}}};
+```
+
+## Examples
+
+### Updates the object when a property is deleted
+
+```js
+var obj = {a: 'b'};
+unset(obj, 'a');
+console.log(obj);
+//=> {}
+```
+
+### Returns true when a property is deleted
+
+```js
+unset({a: 'b'}, 'a') // true
+```
+
+### Returns `true` when a property does not exist
+
+This is consistent with `delete` behavior in that it does not
+throw when a property does not exist.
+
+```js
+unset({a: {b: {c: 'd'}}}, 'd') // true
+```
+
+### delete nested values
+
+```js
+var one = {a: {b: {c: 'd'}}};
+unset(one, 'a.b');
+console.log(one);
+//=> {a: {}}
+
+var two = {a: {b: {c: 'd'}}};
+unset(two, 'a.b.c');
+console.log(two);
+//=> {a: {b: {}}}
+
+var three = {a: {b: {c: 'd', e: 'f'}}};
+unset(three, 'a.b.c');
+console.log(three);
+//=> {a: {b: {e: 'f'}}}
+```
+
+### throws on invalid args
+
+```js
+unset();
+// 'expected an object.'
+```
+
+## Related projects
+
+* [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)
+* [get-values](https://www.npmjs.com/package/get-values): Return an array of all values from the given object. | [homepage](https://github.com/jonschlinkert/get-values)
+* [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)
+* [put-value](https://www.npmjs.com/package/put-value): Update only existing values from an object, works with dot notation paths like `  a.b.c` and… [more](https://www.npmjs.com/package/put-value) | [homepage](https://github.com/tunnckocore/put-value#readme)
+* [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)
+* [upsert-value](https://www.npmjs.com/package/upsert-value): Update or set nested values and any intermediaries with dot notation (`'a.b.c'`) paths. | [homepage](https://github.com/doowb/upsert-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/unset-value/issues/new).
+
+## Author
+
+**Jon Schlinkert**
+
++ [github/jonschlinkert](https://github.com/jonschlinkert)
++ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+
+## License
+
+Copyright © 2015 Jon Schlinkert
+Released under the MIT license.
+
+***
+
+_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 30, 2015._
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..ed5660e
--- /dev/null
+++ b/index.js
@@ -0,0 +1,32 @@
+/*!
+ * unset-value <https://github.com/jonschlinkert/unset-value>
+ *
+ * Copyright (c) 2015, Jon Schlinkert.
+ * Licensed under the MIT License.
+ */
+
+'use strict';
+
+var isObject = require('isobject');
+var has = require('has-value');
+
+module.exports = function unset(obj, prop) {
+  if (!isObject(obj)) {
+    throw new TypeError('expected an object.');
+  }
+  if (obj.hasOwnProperty(prop)) {
+    delete obj[prop];
+    return true;
+  }
+
+  if (has(obj, prop)) {
+    var segs = prop.split('.');
+    var last = segs.pop();
+    while (segs.length && segs[segs.length - 1].slice(-1) === '\\') {
+      last = segs.pop().slice(0, -1) + '.' + last;
+    }
+    while (segs.length) obj = obj[prop = segs.shift()];
+    return (delete obj[last]);
+  }
+  return true;
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..5a27bd0
--- /dev/null
+++ b/package.json
@@ -0,0 +1,56 @@
+{
+  "name": "unset-value",
+  "description": "Delete nested properties from an object using dot notation.",
+  "version": "0.1.1",
+  "homepage": "https://github.com/jonschlinkert/unset-value",
+  "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
+  "repository": "jonschlinkert/unset-value",
+  "bugs": {
+    "url": "https://github.com/jonschlinkert/unset-value/issues"
+  },
+  "license": "MIT",
+  "files": [
+    "index.js"
+  ],
+  "main": "index.js",
+  "engines": {
+    "node": ">=0.10.0"
+  },
+  "scripts": {
+    "test": "mocha"
+  },
+  "dependencies": {
+    "has-value": "^0.2.1",
+    "isobject": "^2.0.0"
+  },
+  "devDependencies": {
+    "mocha": "*",
+    "should": "*"
+  },
+  "verb": {
+    "related": {
+      "description": "",
+      "list": [
+        "get-value",
+        "get-values",
+        "omit-value",
+        "put-value",
+        "set-value",
+        "union-value",
+        "upsert-value"
+      ]
+    }
+  },
+  "keywords": [
+    "del",
+    "delete",
+    "key",
+    "object",
+    "omit",
+    "prop",
+    "property",
+    "remove",
+    "unset",
+    "value"
+  ]
+}
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..ba7344a
--- /dev/null
+++ b/test.js
@@ -0,0 +1,69 @@
+/*!
+ * unset <https://github.com/jonschlinkert/unset>
+ *
+ * Copyright (c) 2015 .
+ * Licensed under the MIT license.
+ */
+
+'use strict';
+
+/* deps: mocha */
+var assert = require('assert');
+var should = require('should');
+var unset = require('./');
+
+describe('unset', function () {
+  it('should update the given object when a property is deleted:', function () {
+    var obj = {a: 'b'};
+    unset(obj, 'a');
+    obj.should.eql({});
+  });
+
+  it('should return true when a property is deleted:', function () {
+    unset({a: 'b'}, 'a').should.eql(true);
+  });
+
+  it('should return true when the given property does not exist:', function () {
+    unset({a: 'b'}, 'z').should.eql(true);
+  });
+
+  it('should delete nested values:', function () {
+    var one = {a: {b: {c: 'd'}}};
+    unset(one, 'a.b');
+    one.should.eql({a: {}});
+
+    var two = {a: {b: {c: 'd'}}};
+    unset(two, 'a.b.c');
+    two.should.eql({a: {b: {}}});
+
+    var three = {a: {b: {c: 'd', e: 'f'}}};
+    unset(three, 'a.b.c');
+    three.should.eql({a: {b: {e: 'f'}}});
+  });
+
+  it('should delete...:', function () {
+    var three = {'a.b': 'c', d: 'e'};
+    unset(three, 'a.b');
+    three.should.eql({d: 'e'});
+  });
+
+  it('should delete nested escaped values:', function () {
+    var one = {a: {'b.c': 'd'}};
+    unset(one, 'a.b\\.c');
+    one.should.eql({a: {}});
+
+    var two = {'a.b.c': 'd'};
+    unset(two, 'a\\.b\\.c');
+    two.should.eql({});
+
+    var three = {'a.b': 'c', d: 'e'};
+    unset(three, 'a\\.b');
+    three.should.eql({d: 'e'});
+  });
+
+  it('should throw an error when invalid args are passed:', function () {
+    (function () {
+      unset();
+    }).should.throw('expected an object.');
+  });
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-unset-value.git



More information about the Pkg-javascript-commits mailing list