index-to-position
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

index-to-position

Convert a string index to its line and column position

Install

npm install index-to-position

Usage

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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    38
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    38
  • 0.1.2
    651,606
  • 0.1.1
    179
  • 0.1.0
    23,194

Package Sidebar

Install

npm i index-to-position

Weekly Downloads

548,419

Version

1.0.0

License

MIT

Unpacked Size

4.21 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus