Security News
How Threat Actors are Abusing GitHub’s File Upload Feature to Host Malware
GitHub is susceptible to a CDN flaw that allows attackers to host malware on any public repository.
lines-and-columns
Advanced tools
Package description
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.
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 }"}
The columnify package creates text-based columns suitable for console output, similar to how tables might be formatted in printed material. It differs from lines-and-columns in that it focuses on aligning columns of text rather than mapping positions within a text.
The line-column package provides similar functionality to lines-and-columns, allowing you to find the line and column position from a character offset and vice versa. It serves a similar purpose but may have different API details or performance characteristics.
The line-numbers package is used to prepend line numbers to a block of text. While it deals with lines in text, it does not provide the bidirectional mapping between line/column and character offset that lines-and-columns offers.
Readme
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.
$ npm install [--save] lines-and-columns
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
MIT
FAQs
Maps lines and columns to character offsets and back.
The npm package lines-and-columns receives a total of 30,492,463 weekly downloads. As such, lines-and-columns popularity was classified as popular.
We found that lines-and-columns demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
GitHub is susceptible to a CDN flaw that allows attackers to host malware on any public repository.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.