array-restore.js

1.0.1 • Public • Published

Array restore

Description:

Store and restore values which you popped, unshifted or deleted from an array.

What is the purpose?

Lately I was thinking that once we remove value from an array, we can't recover it and we're just going to lose it. I ended up writing that function for an array. I know we can create our own array in the code and just store removed values there. It's not the point, my thinking was that we should have specific function for that to keep the composition, functional programming and clean code.

That is the reason why I've wrote Array.restore functions.

Documentation

Array.restore is really small function that you can use to store your removed data.

1. arrayRestore.storeValue(removedValue, key)

arrayRestore.storeValue(5, 'Five');

arrayRestore.storeValue takes two arguments, removed value and key. You can't rewrite the value that you added before. If you want to do it, you have to use arrayRestore.changeValue() function.

Above function adds key and removed value as a object literal and store it there.

2. arrayRestore.getValue()

arrayRestore.getValue();

Above function doesn't take any arguments and returns currently stored value.

3. arrayRestore.changeValue(removedValue, key)

arrayRestore.changeValue(60, 'Sixty');

Above function changes the value and key that is currently stored inside.

4. arrayRestore.pushValue(arrayName, index)

Argument - index is optional

const array = [1,2,3,4,5];
arrayRestore.pushValue(array);

Above function will push currently stored value into chosen array as a last element.

If you want to push currently stored value at specific index, use second optional argument.

const array = [1,2,3,4,5];
arrayRestore.pushValue(array, 2); // array = [1,2,60,3,4,5];

Above function with optional index argument included returns an array with currently stored value at chosen index.

Contact

Well this is it! I'm planning to write more that small functions.
If you want to contact me, have any questions: wozniakj.robert@gmail.com

Readme

Keywords

Package Sidebar

Install

npm i array-restore.js

Weekly Downloads

1

Version

1.0.1

License

ISC

Last publish

Collaborators

  • robertjwozniak