Socket
Socket
Sign inDemoInstall

lines-and-columns

Package Overview
Dependencies
0
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    lines-and-columns

Maps lines and columns to character offsets and back.


Version published
Weekly downloads
38M
increased by1.33%
Maintainers
1
Install size
7.51 kB
Created
Weekly downloads
 

Package description

What is lines-and-columns?

The lines-and-columns npm package is used to map between lines and columns to character offsets within a string, which is particularly useful when dealing with source code or any structured text format where line and column positions are commonly used.

What are lines-and-columns's main functionalities?

Index to Position

This feature allows you to convert a line and column position into a character offset index. It is useful when you have a line and column number and you want to find the corresponding position in a flat string.

{"const LinesAndColumns = require('lines-and-columns');\nconst lines = new LinesAndColumns('Hello\nWorld');\nconst location = lines.indexForLocation({ line: 1, column: 2 }); // returns 9"}

Position to Index

This feature allows you to convert a character offset index back into a line and column position. It is useful when you have an index in a string and you need to find out which line and column it corresponds to.

{"const LinesAndColumns = require('lines-and-columns');\nconst lines = new LinesAndColumns('Hello\nWorld');\nconst position = lines.locationForIndex(7); // returns { line: 1, column: 0 }"}

Other packages similar to lines-and-columns

Readme

Source

lines-and-columns

Maps lines and columns to character offsets and back. This is useful for parsers and other text processors that deal in character ranges but process text with meaningful lines and columns.

Install

$ npm install [--save] lines-and-columns

Usage

import { LinesAndColumns } from 'lines-and-columns'

const lines = new LinesAndColumns(
  `table {
  border: 0
}`
)

lines.locationForIndex(9)
// { line: 1, column: 1 }

lines.indexForLocation({ line: 1, column: 2 })
// 10

License

MIT

Keywords

FAQs

Last updated on 07 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc