line-column-mini
TypeScript icon, indicating that this package has built-in type declarations

3.1.1 • Public • Published

line-column-mini

Convert string index to line-column position

page on codsen.com page on npm page on github Downloads per month changelog MIT Licence

Install

This package is pure ESM. If you're not ready yet, install an older version of this program, 1.2.0 (npm i line-column-mini@1.2.0).

npm i line-column-mini

Quick Take

import { strict as assert } from "assert";

import { lineCol, getLineStartIndexes } from "line-column-mini";

// index 14 is letter "k" on the fourth line:
assert.deepEqual(lineCol("abc\ndef\r\nghi\njkl", 14), {
  line: 4,
  col: 2,
});

// ---------------------------------------------------------

// if you know you might query multiple times, use caching
const lineIndexes = getLineStartIndexes("abc\ndef\r\nghi\njkl");
assert.deepEqual(lineCol(lineIndexes, 14), {
  line: 4,
  col: 2,
});
// other queries will be by magnitude faster:
assert.deepEqual(lineCol(lineIndexes, 15), {
  line: 4,
  col: 3,
});

// by the way...
assert.deepEqual(lineCol(lineIndexes, 99), null);

Documentation

Please visit codsen.com for a full description of the API.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License.

Copyright © 2010-2024 Roy Revelt and other contributors.

ok codsen star

Package Sidebar

Install

npm i line-column-mini

Weekly Downloads

4

Version

3.1.1

License

MIT

Unpacked Size

10.8 kB

Total Files

7

Last publish

Collaborators

  • royston