You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
533 B

3 months ago
  1. # lines-and-columns
  2. Maps lines and columns to character offsets and back. This is useful for parsers
  3. and other text processors that deal in character ranges but process text with
  4. meaningful lines and columns.
  5. ## Install
  6. ```
  7. $ npm install [--save] lines-and-columns
  8. ```
  9. ## Usage
  10. ```js
  11. import { LinesAndColumns } from 'lines-and-columns'
  12. const lines = new LinesAndColumns(
  13. `table {
  14. border: 0
  15. }`
  16. )
  17. lines.locationForIndex(9)
  18. // { line: 1, column: 1 }
  19. lines.indexForLocation({ line: 1, column: 2 })
  20. // 10
  21. ```
  22. ## License
  23. MIT