lines-and-columns
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The npm package "lines-and-columns" is designed to map lines and columns to character offsets and vice versa. This is incredibly useful for parsers and other text processes, particularly those that deal in character ranges but need to process text with meaningful lines and columns.
To utilize "lines-and-columns", first, install it with npm install command as such: npm install --save lines-and-columns
. Once installed, you can import the package with import { LinesAndColumns } from 'lines-and-columns'
. Hereafter, instantiate the class with a string, creating a new instance. To convert character offset to line and column, use lines.locationForIndex()
, and to convert line and column to character offset, use lines.indexForLocation()
.
A usage example could be:
import { LinesAndColumns } from 'lines-and-columns';
const lines = new LinesAndColumns(
`table {
border: 0
}`
);
console.log(lines.locationForIndex(9)); // { line: 1, column: 1 }
console.log(lines.indexForLocation({ line: 1, column: 2 })); // 10
The documentation for "lines-and-columns" can be found on GitHub at git+https://github.com/eventualbuddha/lines-and-columns.git. Details related to installation, usage, and licensing can be found within the README file right here.