# index-to-position

> Convert a string index to its line and column position

Latest version **1.2.0** (published 2025-09-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install index-to-position
pnpm add index-to-position
yarn add index-to-position
bun add index-to-position
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2025-09-25 |
| First published | 2023-11-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 35 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | index, position, line, column, text, coordinate, string, character, line number, column number, location |

## Links

- npm: https://www.npmjs.com/package/index-to-position
- Repository: https://github.com/sindresorhus/index-to-position
- Homepage: https://github.com/sindresorhus/index-to-position#readme
- Issues: https://github.com/sindresorhus/index-to-position/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/index-to-position

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2025-09-25
- 1.1.0 — 2025-04-08
- 1.0.0 — 2024-02-28
- 0.1.2 — 2023-11-09
- 0.1.1 — 2023-11-09
- 0.1.0 — 2023-11-02

## README

# index-to-position

> Convert a string index to its line and column position

## Install

```sh
npm install index-to-position
```

## Usage

```js
import indexToPosition from 'index-to-position';

indexToPosition('hello\nworld\n!', 7);
//=> {line: 1, column: 1}
```

## API

### `indexToPosition(text, index, options?)`

#### text

Type: `string`

The text in which to find the line and column position.

#### index

Type: `number`

The index in the string for which to find the line and column position.

#### options

Type: `object`

##### oneBased

Type: `boolean`\
Default: `false`

Whether to use 1-based or 0-based indexing for the result.

##### oneBasedLine

Type: `boolean`\
Default: `false`

Whether to use 1-based or 0-based line indexing for the result.

##### oneBasedColumn

Type: `boolean`\
Default: `false`

Whether to use 1-based or 0-based column indexing for the result.

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