Giter Club home page Giter Club logo

index-to-position's Introduction

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.

index-to-position's People

Contributors

sindresorhus avatar fisker avatar

Stargazers

Terrell Franzman avatar  avatar Nikita Kogut avatar Derrick Schwabe avatar hsnmkls avatar Muhammad Umer avatar Muah avatar Cristian Pallarés avatar  avatar  avatar Shawn Jonnet avatar  avatar Tyler Davis Mitchell avatar Nidal Ade avatar  avatar Noore Alam Shahariya avatar netop://ウエハ avatar Alex avatar Andrei Luca avatar Lawrence Onah avatar DogMan Zhan avatar Jeet Mandaliya avatar Saurabh Daware avatar Santhosh Veer avatar Zhazha_JiaYiZhen avatar  avatar Enes Kavçakar avatar Vít Rozsíval avatar Umar Hansa avatar Gustavo Giserman avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

fisker

index-to-position's Issues

Column returns `NaN` for invalid arguments

When using the indexToPosition function with invalid arguments for the "index" parameter, the "column" value is incorrectly returning NaN. It would be beneficial to review this behavior to enhance error handling and improve clarity for users when utilizing the function.

Code Examples:

console.log(indexToPosition('hello\nworld\n!'));
//=> {line: 2, column: NaN}

console.log(indexToPosition('hello\nworld\n!', 'invalid argument'));
//=> {line: 2, column: NaN}

console.log(indexToPosition('hello\nworld\n!', {}));
//=> {line: 2, column: NaN}

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.