Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kanety/insert-text


https://github.com/kanety/insert-text

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# insert-text

Insert text to input or contenteditable element.

## Installation

Install from npm:

$ npm install @kanety/insert-text --save

## Usage

Insert text to `textarea`:

```html
sample text
```

```javascript
import InsertText from '@kanety/insert-text';
InsertText.run('textarea', 'YOUR TEXT');
```

Insert text to `contenteditable` element:

```html

sample text

```

```javascript
import InsertText from '@kanety/insert-text';
InsertText.run('div[contenteditable]', 'YOUR TEXT');
```

Text is inserted at caret position by default.

### Options

Insert text at first position:

```javascript
InsertText.run('textarea', 'YOUR TEXT', 'first');
```

Insert text at last position:

```javascript
InsertText.run('textarea', 'YOUR TEXT', 'last');
```

## License

The library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).