An open API service indexing awesome lists of open source software.

https://github.com/doowb/stash-object

Stash the current state of an object and restore at a later time.
https://github.com/doowb/stash-object

Last synced: about 1 year ago
JSON representation

Stash the current state of an object and restore at a later time.

Awesome Lists containing this project

README

          

# stash-object [![NPM version](https://img.shields.io/npm/v/stash-object.svg?style=flat)](https://www.npmjs.com/package/stash-object) [![NPM downloads](https://img.shields.io/npm/dm/stash-object.svg?style=flat)](https://npmjs.org/package/stash-object) [![Build Status](https://img.shields.io/travis/doowb/stash-object.svg?style=flat)](https://travis-ci.org/doowb/stash-object)

Stash the current state of an object and restore at a later time.

## Install

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

```sh
$ npm install --save stash-object
```

## Usage

```js
var stash = require('stash-object');
```

## API

### [stash](index.js#L22)

Create a new stash for an object. This will return an object with [.stash](#stash-1) and [.restore](#restore) methods used for stashing and restoring states of the original object.

**Params**

* `obj` **{Object}**: Object to use for original state.
* `returns` **{Object}**: New instance used for stashing and restoring object state.

**Example**

```js
var options = {};
var optionStash = stash(options);
```

### [.stash](index.js#L49)

Stash the current object state on a named stack. Pass a property path as the second argument to only stash part of the object.

**Params**

* `name` **{String}**: Name of the stack to push the object state onto.
* `prop` **{String|Array}**: Optional property path to stash
* `returns` **{Object}** `this`: for chaining

**Example**

```js
optionStash.stash('foo');
optionStash.stash('foo', 'bar.baz');
```

### [.restore](index.js#L81)

Restore a stashed object from the stack. Pass a property path as the second argument to only restore part of the object.

**Params**

* `name` **{String}**: Name of the stack to retore the object state from.
* `prop` **{String|Array}**: Optional property path to restore
* `returns` **{Object}**: Restored object. This is returned in case the original object reference needs to be reset.

**Example**

```js
var obj = optionsStash.restore('foo');
var obj = optionsStash.restore('foo', 'bar.baz');
```

## About

### Related projects

* [clone-deep](https://www.npmjs.com/package/clone-deep): Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. | [homepage](https://github.com/jonschlinkert/clone-deep "Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.")
* [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.")
* [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.")

### Contributing

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

### Building docs

_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_

To generate the readme and API documentation with [verb](https://github.com/verbose/verb):

```sh
$ npm install -g verb verb-generate-readme && verb
```

### Running tests

Install dev dependencies:

```sh
$ npm install -d && npm test
```

### Author

**Brian Woodward**

* [github/doowb](https://github.com/doowb)
* [twitter/doowb](http://twitter.com/doowb)

### License

Copyright © 2016, [Brian Woodward](https://github.com/doowb).
Released under the [MIT license](https://github.com/doowb/stash-object/blob/master/LICENSE).

***

_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on July 28, 2016._