stash-object

0.1.1 • Public • Published

stash-object NPM version NPM downloads Build Status

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

Install

Install with npm:

$ npm install --save stash-object

Usage

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

API

stash

Create a new stash for an object. This will return an object with .stash and .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

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

.stash

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

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

.restore

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

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

About

Related projects

  • clone-deep: Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. | homepage
  • get-value: Use property paths (a.b.c) to get a nested value from an object. | homepage
  • set-value: Create nested values and any intermediaries using dot notation ('a.b.c') paths. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

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

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Brian Woodward

License

Copyright © 2016, Brian Woodward. Released under the MIT license.


This file was generated by verb, v0.9.0, on July 28, 2016.

Package Sidebar

Install

npm i stash-object

Weekly Downloads

0

Version

0.1.1

License

MIT

Last publish

Collaborators

  • jonschlinkert
  • doowb