# text-cusor-helper

> This library provides fast ways to deal with the text cursor when editing in input, textarea, and div (`contenteditable = true`) elements: * Get position of the text cursor on the Oxy coordinate axis * Move the text cursor to the end of input fields

Latest version **1.0.7** (published 2023-12-31) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install text-cusor-helper
pnpm add text-cusor-helper
yarn add text-cusor-helper
bun add text-cusor-helper
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2023-12-31 |
| First published | 2023-12-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sum Duong |
| Maintainers | sumsv50 |

## Links

- npm: https://www.npmjs.com/package/text-cusor-helper
- npm.io page: https://npm.io/package/text-cusor-helper

## Recent versions

- 1.0.7 (latest) — 2023-12-31
- 1.0.6 — 2023-12-31
- 1.0.5 — 2023-12-31
- 1.0.4 — 2023-12-31
- 1.0.3 — 2023-12-31
- 1.0.2 — 2023-12-31
- 1.0.1 — 2023-12-31
- 1.0.0 — 2023-12-23

## README

# Text Cursor Helper
This library provides fast ways to deal with the text cursor when editing in input, textarea, and div (`contenteditable = true`) elements:
* Get position of the text cursor on the Oxy coordinate axis
* Move the text cursor to the end of input fields

## Installing

Using npm

```bash
  npm i text-cusor-helper
```

Using yarn

```bash
  yarn add text-cusor-helper
```

Once the package is installed, you can import using ES Modules:

```js
import textCursorHelper from 'text-cusor-helper';
```
## Quick Start

### Get position of the text cursor 

Returns X, Y coordinates for positioning of a text cursor within a given text input at a given selection point

#### Parameters:

|Order|Name|Description|Type|
|---|---|---|---|
|1|`input`|The text input that need deal with text cursor inside it|Element|
|2|`anchor`|The element serves as a reference for coordinates calculation (The origin of Oxy coordinates)|textCursorHelper.ANCHOR: <ul><li>`ROOT` [Default]</li><li>`POSITIONED_PARENT`: the nearest parent element having the position attribute is **relative** or **absolute** </li></ul>|

#### Example:

```js

const inputElement = document.querySelector(".comment-input")
const position = textCursorHelper.getCursorXY(
  inputElement,
  textCursorHelper.ANCHOR.POSITIONED_PARENT
);

console.log(position)
// { x: 50: y : 50 }

```

---
_Source: https://npm.io/package/text-cusor-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
