{"_id":"undoredo.js","_rev":"8-28479f36dd40c11da1b95951c80954a4","name":"undoredo.js","dist-tags":{"latest":"1.2.0"},"versions":{"1.1.0":{"name":"undoredo.js","version":"1.1.0","description":"A powerful and simple Javascript library provides a history for undo/redo functionality. Just like a time machine! 🕐","main":"./src/undoredo.js","repository":{"type":"git","url":"git+https://github.com/iMrDJAi/UndoRedo.js.git"},"keywords":["js","undo-redo","dom","nodejs","history","undo","redo"],"author":{"name":"${Mr.DJA}"},"license":"MIT","bugs":{"url":"https://github.com/iMrDJAi/UndoRedo.js/issues"},"homepage":"https://github.com/iMrDJAi/UndoRedo.js#readme","_id":"undoredo.js@1.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"mr_dja","email":"imrdjai@yahoo.com"},"dist":{"integrity":"sha512-pJf9HPvdV1sSvIzt3zpHQ5FlE/R0lNemjMgNVbCsLodytnywcRmVJ2NFwTpHRioIBqJeE1O88vNf6jjudv1o5g==","shasum":"d07365651134cd0d2b13541d7f60cf3af9ae5221","tarball":"https://registry.npmjs.org/undoredo.js/-/undoredo.js-1.1.0.tgz","fileCount":5,"unpackedSize":12757,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfEb5bCRA9TVsSAnZWagAAzbMQAJQdjZ6sUMhIo9ZJREY0\nEwFgJvLDHYxvuw5EV/Ourg6tRW15/8kdRJ9i9G7N3M6d0qWn1jP/ndoXG0tm\noOPCGp/OaWqgAviCJzMz2Du0e1gmFX9njlHqIiJOzpqslXUL+6UmsN5ZzapB\nEsYcxxpm02jTLykKSlBjiNnrinD6amc9EdCVvACmcuQtiYzeUmQ8QQlOBZdr\niUQK6c++wAlbBqRpNxr3tzFJGKls3+9waJTCmjO+K7ZA12gdkBQcKet71yS0\n42vS+DkHrHTuMAkdOwJ6Vjguy9pBadsjqUnL4qWcJYhhu39iYmpYl6b7a59B\noaazMPaiBET3jdlJ0qBOgh77IPvawRD7GwfHd2dZnf+O50j+QErNBwCsHuBX\nmH1agZAHEVMfgFdFaIEJXanarnR/OD/7vyXHU73sxSwoE8gwzfciFX0x6PCY\njDaJZezevRR/WED3EVYcvgkduMSUA7Js4Hu4F1k3WAcKuXD3bSd/3XW8IzQL\ngErhL9dCe5m4CZUmj9Ocst1rjdDnjXrXIl7RP4W/Q4ADiobu5sSt5OPzFRdK\n+CVSkrUBFc5WLI0EEJ7j1vfiaaWKTKnZayobl3Xx5sPmmEmtFVSnTTyilMEy\n9aowRYpKiHw43mFdTs2Wwc2VwHImWtyE7KSFTkELoh273PCk+owqEdb/PUPA\ny5QJ\r\n=Tou6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFwQ1Z5Kpju6eBpUQGT81v7ZLtrmo9dUICiEufCXy3bxAiARhh0AP5z5aylCeZwK68B+bMnj9VuCjVne5vUK3jDGKA=="}]},"maintainers":[{"name":"mr_dja","email":"imrdjai@yahoo.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/undoredo.js_1.1.0_1594998362941_0.3517285183147516"},"_hasShrinkwrap":false},"1.2.0":{"name":"undoredo.js","version":"1.2.0","description":"A powerful and simple Javascript library provides a history for undo/redo functionality. Just like a time machine! 🕐","main":"./src/undoredo.js","repository":{"type":"git","url":"git+https://github.com/iMrDJAi/UndoRedo.js.git"},"keywords":["js","undo-redo","dom","nodejs","history","undo","redo"],"author":{"name":"${Mr.DJA}"},"license":"MIT","bugs":{"url":"https://github.com/iMrDJAi/UndoRedo.js/issues"},"homepage":"https://github.com/iMrDJAi/UndoRedo.js#readme","gitHead":"f6bcdce2501ecee8e4e496c7b00774c3db322224","_id":"undoredo.js@1.2.0","_nodeVersion":"12.22.1","_npmVersion":"6.14.12","dist":{"integrity":"sha512-TnYI3ObFLg0rpiExHKRrRZnlJg4o8WoN0zYpV0Ym9OdDwCVqE7nBoh8iCyoofleTaXucI3dngWBznm/7K+i8XA==","shasum":"687349697f673c84501c1ad4c0254ff1a3255aa0","tarball":"https://registry.npmjs.org/undoredo.js/-/undoredo.js-1.2.0.tgz","fileCount":5,"unpackedSize":13327,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgdw+ICRA9TVsSAnZWagAA9BYP/1t76kdBrypkLDLjWgj6\ndvbKRpLTTpfehT9uBt7CqyrEU4bnfshCql6RiNTaAAZ/AwbAy7MPJCT10w+B\nTwF20irrS9j1dwHkUyOpos1xrCsGUIGXy0XhqHtmDcZxoqzZgwo9YkVGw6Gi\nU7VFoMzB1gyq/IROrSlKgMpn5sOFPzUPJ+LH0CqhGNnJ0GHgE48PK40Snk7D\nj0DZ5b3yN82qEyuEUZ++hMNIAeHUtWQki0wSXa42FVt8hopnFo0Jv71L43X6\nGtsCxpHnX7l7Q+I3TWT4D9nZedNd338IjYQKgV4MOWo2/TLkeBSn3is164p1\nt6W7YoG10W2Ne7B2QbKBzmXlInty7/ts2akcYjAGTjGb1/unTTOoJVdY+KSV\nma1Q1OmV87ii2R7d1moZFR2WCHtjrP6zFEkGb8a4zWpMu/ND4Y5MXzRYPtCw\n/yK/tEShAKP2d8XvBj3niTrjc2VdOyoS5///yNwlDNxNls1V8EjBlW/8YMMt\nOQ0AlsLz9x8kh2D2VcAbXfeJSYGrqsoJvnbt6w4nxk6hpn9Sgp14badduUX0\nJ12Rcrmqw3uROvXelxPVoBMuI63t5NYx1XXxxrhbQKlIm72GaXaSy/aOtcwj\nm0lavR/RuJLn5idGDV+39x8yW42g8suEggT0/DsQ0Nu41hevVvYle+qczwll\noEOm\r\n=QZkp\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDYJIvYCchcrRUSWxg/LYtZ1Ix+qTbqO6N7ldb7lCXSmgIgbcYiuS34lq9sNF8eSkcI9sdpPSQbgjmiWvYy/WrCjSI="}]},"_npmUser":{"name":"mr_dja","email":"imrdjai@yahoo.com"},"directories":{},"maintainers":[{"name":"mr_dja","email":"imrdjai@yahoo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/undoredo.js_1.2.0_1618415494139_0.2559199810462722"},"_hasShrinkwrap":false}},"time":{"created":"2020-01-24T18:30:00.941Z","1.0.0":"2020-01-24T18:30:01.088Z","modified":"2022-05-22T18:05:46.669Z","1.0.1":"2020-01-24T18:32:02.267Z","1.0.2":"2020-04-01T16:10:53.755Z","1.1.0":"2020-07-17T15:06:03.124Z","1.2.0":"2021-04-14T15:51:34.331Z"},"maintainers":[{"name":"mr_dja","email":"imrdjai@yahoo.com"}],"description":"A powerful and simple Javascript library provides a history for undo/redo functionality. Just like a time machine! 🕐","homepage":"https://github.com/iMrDJAi/UndoRedo.js#readme","keywords":["js","undo-redo","dom","nodejs","history","undo","redo"],"repository":{"type":"git","url":"git+https://github.com/iMrDJAi/UndoRedo.js.git"},"author":{"name":"${Mr.DJA}"},"bugs":{"url":"https://github.com/iMrDJAi/UndoRedo.js/issues"},"license":"MIT","readme":"# UndoRedo.js \n[![npm](https://img.shields.io/npm/v/undoredo.js?color=red)](https://www.npmjs.com/package/undoredo.js)\n\nA powerful and simple Javascript library provides a history for undo/redo functionality. Just like a time machine! 🕐\n***\n## Installation:\n**Node.js**:\n\nUse this command to install the node module:\n```bash\nnpm install undoredo.js --save\n```\nThen simply require it:\n```js\nconst UndoRedojs = require(\"undoredo.js\")\n```\n\n**Browser**:\n\nYou can get the `UndoRedo.js` file from [JsDeliver CDN](https://cdn.jsdelivr.net/gh/iMrDJAi/UndoRedo.js/src/UndoRedo.js):\n```html\n<script src='https://cdn.jsdelivr.net/gh/iMrDJAi/UndoRedo.js/src/UndoRedo.js'></script>\n```\n\nYou can download it and use it locally:\n```\n📄index.html\n📁js\n ↳ 📄UndoRedo.js\n```\n\nThis time it will be:\n```html\n<script src='./js/UndorRedo.js'></script>\n```\n\nBy the same way you can use `UndoRedo.min.js` instead, which is a minified version of `UndoRedo.js`. [JsDeliver CDN link](https://cdn.jsdelivr.net/gh/iMrDJAi/UndoRedo.js/src/UndoRedo.min.js).\n\nThe main function will be declared as `window.UndoRedojs`:\n```js\nconst UndoRedojs = window.UndoRedojs\n```\n\nYou can also bundle it into your project using [Webpack](https://webpack.js.org/guides/getting-started/). You can use it in anyway you want, it's just another npm packege after all! 😅\n\n## Usage:\nThis package is useful for any step-by-step task, for example:\n\n- Undo/Redo functionality for a text input.\n- Something like a browser history.\n- A settings page.\n- A files explorer.\n- A calculator (why not xD).\n- And more...\n\n**Basic usage**:\n\nLets setup our history:\n```js\n const myHistory = new UndoRedojs(5)\n```\nThis will return a class object with the methods and the properties that we will use later.\n\nAs you can see, we added the number **5** as a parameter, this will be used for cooldowns, keep reading for more details.\n\nTo push new elements to the history, use the `record` method:\n```js\nmyHistory.record('1')\nmyHistory.record('12')\nmyHistory.record('123')\nmyHistory.record('1234')\nmyHistory.record('12345')\nmyHistory.record('123456')\nmyHistory.record('1234567', true)\n```\nTo get the history array, use the `stack` property:\n```js\nconsole.log(myHistory.stack)\n// output => Array(4) [ \"\", \"12345\", \"123456\", \"1234567\" ]\n```\nYou can get the current history position using the `currentIndex` property:\n```js\nconsole.log(myHistory.currentIndex)\n// output => 3\n```\nRemember that arrays always start from **0**, so the number **3** here is actually the **4th** element, wanna check?\n```js\nconsole.log(myHistory.stack[myHistory.currentIndex])\n// output => \"1234567\"\n```\nThere is another way to get the current element, using the `current` method:\n```js\nconsole.log(myHistory.current())\n// output => \"1234567\"\n```\nThe history array always starts with an empty element, this can be very helpful for text areas.\n\nSo we called the `record` method 7 times, but we only got 3 recorded elements (without the 1st empty one). Why?\n\nWe used the number **5** as a parameter for the `UndoRedojs` function, it's just like saying: 'Record every 5 calls', that makes cooldowns. We call this parameter: `cooldown`.\n\nSo during cooldowns the `record` method will not gonna push new elements to the history stack, instead of that it will update the current element with the new one.\n\nTo disable that, just use the number **1**, or keep it empty because the default `cooldown` is **1**:\n```js\n const myHistory = UndoRedojs()\n```\n\nBut we see that the `\"1234567\"` element is recorded during a cooldown. Why?\n\nThe difference here is that we added `true` as a 2nd parameter for the `record` method, it's just like saying: 'Force to record', that will make it bypass the cooldown. We call this parameter: `force`.\n\nTo undo, just use the `undo` method:\n```js\nconst undo = myHistory.undo()\nconsole.log(undo)\n// output => \"123456\"\nconsole.log(myHistory.current())\n// output => \"123456\"\n```\nSo the `undo` method will make you step back once inside the array and will return the previous element.\n\nWhat if we add `true` as a parameter?\n```js\nconst undo = myHistory.undo(true);\nconsole.log(undo);\n// output => \"123456\"\nconsole.log(myHistory.current());\n// output => \"1234567\"\n```\nAs you can see the current element stays `\"1234567\"`, so this time it returns the previous element without stepping back. We call this parameter: `readOnly`.\n\nTo redo, just use the `redo` method:\n```js\nconst redo = myHistory.redo()\nconsole.log(redo)\n// output => \"1234567\"\nconsole.log(myHistory.current())\n// output => \"1234567\"\n```\nSo the `redo` method will make you step forward once inside the array and will return the next element.\n\nWhat if we add `true` as a parameter?\n```js\nconst redo = myHistory.redo(true);\nconsole.log(redo);\n// output => \"1234567\"\nconsole.log(myHistory.current());\n// output => \"123456\"\n```\nAs you can see the current element stays `\"123456\"`, so this time it returns the next element without stepping forward. We call this parameter: `readOnly`.\n\nWhat if we undo then record then redo again?\n```js\nmyHistory.undo()\nmyHistory.record('12345678')\nconsole.log(myHistory.redo())\n// output => undefined\n```\nWhy? Because the `record` method will remove every next element.\n\nYou can update the current element using the `current` method:\n```js\nconsole.log(myHistory.current('1234567'));\n// output => \"1234567\"\n```\n## Examples:\nYou can find a good example of a textarea with working undo/redo buttons [here](https://github.com/iMrDJAi/UndoRedo.js/blob/master/index.html).\n\nThat's a [live demo](https://imrdjai.github.io/UndoRedo.js).\n\n## Dependents Projects:\nWanna use **UndoRedo.js** on your next big project? Let me now and it will be listed here! :)\n\n## Special Thanks:\n- CSS Script website for sharing this project <3 (https://www.cssscript.com/undo-redo-history).\n\n## Notes:\n- This is my first package, leave a star if you like it <3.\n- You are free to suggest anything and I will try to add it soon if I found it useful.\n- If you found any mistake (including the README file) feel free to help to fix it.\n- Please report any bugs.\n- **Made with ❤ in Algeria 🇩🇿**.\n","readmeFilename":"README.md"}