Skip to content

SmushyTaco/index-to-position

 
 

Repository files navigation

index-to-position

Convert a string index to its line and column position

Install

npm install @smushytaco/index-to-position

Usage

import indexToPosition from '@smushytaco/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.

About

Convert a string index to its line and column position

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 71.6%
  • JavaScript 28.4%