# undate
Undoable update for HTMLTextAreaElement
[](https://www.npmjs.com/package/undate)
[](https://travis-ci.org/yuku-t/undate)
[](https://codeclimate.com/github/yuku-t/undate)
## Install
```bash
npm install --save undate
```
## Usage
```js
import {update, wrapCursor} from 'undate';
const textareaElement = document.getElementById('textarea');
textareaElement.value; //=> ''
// Update whole value
update(textareaElement, 'string before cursor', 'optional string after cursor');
textareaElement.value; //=> 'string before cursoroptional string after cursor'
// Update around the cursor
wrapCursor(textareaElement, ' _', '_ ');
textareaElement.value; //=> 'string before cursor __ optional string after cursor'
// Press cmd-z
textareaElement.value; //=> 'string before cursoroptional string after cursor'
textareaElement.setSelectionRange(14, 27);
textareaElement.value; //=> 'string before cursoroptional string after cursor'
// ^^^^^^^^^^^^^^ selected
wrapCursor(textareaElement, '**', '**');
textareaElement.value; //=> 'string before **cursoroptional** string after cursor'
// ^^^^^^^^^^^^^^ selected
// Press cmd-z
textareaElement.value; //=> 'string before cursoroptional string after cursor'
// ^^^^^^^^^^^^^^ selected
// Press cmd-z
textareaElement.value; //=> ''
```
## License
The [MIT](https://github.com/yuku-t/undate/blob/master/LICENSE) License