object-rollback
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

object-rollback

Go to the latest release page on npm License: MIT Supported Node.js version: >=8.3.0 Type Definitions: TypeScript Install Size Details Dependencies Status Build Status Maintainability Status

Cancel changes to JavaScript object values (add/update/delete properties, add item into Map/Set, etc.)

Install

npm install object-rollback

Usage

const { ObjectState } = require('object-rollback');
 
const someValue = {
  a: 1,
  b: 2,
  c: [ 1, 2, 3 ],
};
 
console.log(someValue); // { a: 1, b: 2, c: [ 1, 2, 3 ] }
 
const state = new ObjectState(someValue);
 
someValue.b = 200;
someValue.x = 42;
someValue.c.push(9);
 
console.log(someValue); // { a: 1, b: 200, c: [ 1, 2, 3, 9 ], x: 42 }
 
state.rollback();
 
console.log(someValue); // { a: 1, b: 2, c: [ 1, 2, 3 ] }

Tested objects

Standard Built-in ECMAScript 2019 Objects

  • Error - test code
    • Error
    • EvalError
    • RangeError
    • ReferenceError
    • SyntaxError
    • TypeError
    • URIError
  • Date - test code
  • RegExp - test code
  • Array - test code
  • Map - test code
  • Set - test code
  • TypedArray - test code
    • Int8Array
    • Uint8Array
    • Uint8ClampedArray
    • Int16Array
    • Uint16Array
    • Int32Array
    • Uint32Array
    • BigInt64Array
    • BigUint64Array
    • Float32Array
    • Float64Array
  • DataView - test code

Node.js Built-in Objects

Tests

To run the test suite, first install the dependencies, then run npm test:

npm install
npm test

Contributing

see CONTRIBUTING.md

Readme

Keywords

none

Package Sidebar

Install

npm i object-rollback

Weekly Downloads

92

Version

1.0.0

License

MIT

Unpacked Size

30.7 kB

Total Files

36

Last publish

Collaborators

  • sounisi5011