Projekt

Obecné

Profil

Stáhnout (5.12 KB) Statistiky
| Větev: | Revize:
1
# unset-value [![NPM version](https://img.shields.io/npm/v/unset-value.svg?style=flat)](https://www.npmjs.com/package/unset-value) [![NPM monthly downloads](https://img.shields.io/npm/dm/unset-value.svg?style=flat)](https://npmjs.org/package/unset-value)  [![NPM total downloads](https://img.shields.io/npm/dt/unset-value.svg?style=flat)](https://npmjs.org/package/unset-value) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/unset-value.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/unset-value)
2

    
3
> Delete nested properties from an object using dot notation.
4

    
5
## Install
6

    
7
Install with [npm](https://www.npmjs.com/):
8

    
9
```sh
10
$ npm install --save unset-value
11
```
12

    
13
## Usage
14

    
15
```js
16
var unset = require('unset-value');
17

    
18
var obj = {a: {b: {c: 'd', e: 'f'}}};
19
unset(obj, 'a.b.c');
20
console.log(obj);
21
//=> {a: {b: {e: 'f'}}};
22
```
23

    
24
## Examples
25

    
26
### Updates the object when a property is deleted
27

    
28
```js
29
var obj = {a: 'b'};
30
unset(obj, 'a');
31
console.log(obj);
32
//=> {}
33
```
34

    
35
### Returns true when a property is deleted
36

    
37
```js
38
unset({a: 'b'}, 'a') // true
39
```
40

    
41
### Returns `true` when a property does not exist
42

    
43
This is consistent with `delete` behavior in that it does not
44
throw when a property does not exist.
45

    
46
```js
47
unset({a: {b: {c: 'd'}}}, 'd') // true
48
```
49

    
50
### delete nested values
51

    
52
```js
53
var one = {a: {b: {c: 'd'}}};
54
unset(one, 'a.b');
55
console.log(one);
56
//=> {a: {}}
57

    
58
var two = {a: {b: {c: 'd'}}};
59
unset(two, 'a.b.c');
60
console.log(two);
61
//=> {a: {b: {}}}
62

    
63
var three = {a: {b: {c: 'd', e: 'f'}}};
64
unset(three, 'a.b.c');
65
console.log(three);
66
//=> {a: {b: {e: 'f'}}}
67
```
68

    
69
### throws on invalid args
70

    
71
```js
72
unset();
73
// 'expected an object.'
74
```
75

    
76
## About
77

    
78
### Related projects
79

    
80
* [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 "Use property paths (`a.b.c`) to get a nested value from an object.")
81
* [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 "Return an array of all values from the given object.")
82
* [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://github.com/jonschlinkert/omit-value) | [homepage](https://github.com/jonschlinkert/omit-value "Omit properties from an object or deeply nested property of an object using object path notation.")
83
* [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://github.com/tunnckocore/put-value#readme) | [homepage](https://github.com/tunnckocore/put-value#readme "Update only existing values from an object, works with dot notation paths like `a.b.c` and support deep nesting.")
84
* [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 "Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.")
85
* [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://github.com/jonschlinkert/union-value) | [homepage](https://github.com/jonschlinkert/union-value "Set an array of unique values as the property of an object. Supports setting deeply nested properties using using object-paths/dot notation.")
86
* [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 "Update or set nested values and any intermediaries with dot notation (`'a.b.c'`) paths.")
87

    
88
### Contributing
89

    
90
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
91

    
92
### Contributors
93

    
94
| **Commits** | **Contributor** | 
95
| --- | --- |
96
| 6 | [jonschlinkert](https://github.com/jonschlinkert) |
97
| 2 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
98

    
99
### Building docs
100

    
101
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
102

    
103
To generate the readme, run the following command:
104

    
105
```sh
106
$ npm install -g verbose/verb#dev verb-generate-readme && verb
107
```
108

    
109
### Running tests
110

    
111
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
112

    
113
```sh
114
$ npm install && npm test
115
```
116

    
117
### Author
118

    
119
**Jon Schlinkert**
120

    
121
* [github/jonschlinkert](https://github.com/jonschlinkert)
122
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
123

    
124
### License
125

    
126
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
127
Released under the [MIT License](LICENSE).
128

    
129
***
130

    
131
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 25, 2017._
(2-2/4)