toPosition
is considered deprecated
Closes GH-5.
4 | 4 | ||
5 | 5 | function factory(file) { |
|
6 | 6 | var contents = indices(String(file)) |
|
7 | + | var toPoint = offsetToPointFactory(contents) |
|
7 | 8 | ||
8 | 9 | return { |
|
9 | - | toPosition: offsetToPositionFactory(contents), |
|
10 | - | toOffset: positionToOffsetFactory(contents) |
|
10 | + | toPoint: toPoint, |
|
11 | + | toPosition: toPoint, |
|
12 | + | toOffset: pointToOffsetFactory(contents) |
|
11 | 13 | } |
|
12 | 14 | } |
|
13 | 15 | ||
14 | - | // Factory to get the line and column-based `position` for `offset` in the bound |
|
16 | + | // Factory to get the line and column-based `point` for `offset` in the bound |
|
15 | 17 | // indices. |
|
16 | - | function offsetToPositionFactory(indices) { |
|
17 | - | return offsetToPosition |
|
18 | + | function offsetToPointFactory(indices) { |
|
19 | + | return offsetToPoint |
|
18 | 20 | ||
19 | - | // Get the line and column-based `position` for `offset` in the bound indices. |
|
20 | - | function offsetToPosition(offset) { |
|
21 | + | // Get the line and column-based `point` for `offset` in the bound indices. |
|
22 | + | function offsetToPoint(offset) { |
|
21 | 23 | var index = -1 |
|
22 | 24 | var length = indices.length |
|
23 | 25 |
39 | 41 | } |
|
40 | 42 | } |
|
41 | 43 | ||
42 | - | // Factory to get the `offset` for a line and column-based `position` in the |
|
44 | + | // Factory to get the `offset` for a line and column-based `point` in the |
|
43 | 45 | // bound indices. |
|
44 | - | function positionToOffsetFactory(indices) { |
|
45 | - | return positionToOffset |
|
46 | + | function pointToOffsetFactory(indices) { |
|
47 | + | return pointToOffset |
|
46 | 48 | ||
47 | - | // Get the `offset` for a line and column-based `position` in the bound |
|
49 | + | // Get the `offset` for a line and column-based `point` in the bound |
|
48 | 50 | // indices. |
|
49 | - | function positionToOffset(position) { |
|
50 | - | var line = position && position.line |
|
51 | - | var column = position && position.column |
|
51 | + | function pointToOffset(point) { |
|
52 | + | var line = point && point.line |
|
53 | + | var column = point && point.column |
|
52 | 54 | ||
53 | 55 | if (!isNaN(line) && !isNaN(column) && line - 1 in indices) { |
|
54 | 56 | return (indices[line - 2] || 0) + column - 1 || 0 |
Files | Coverage |
---|---|
index.js | 100.00% |
Project Totals (1 files) | 100.00% |
lts/dubnium=/dubnium TRAVIS_OS_NAME=windows
node= TRAVIS_OS_NAME=linux
lts/dubnium=/dubnium TRAVIS_OS_NAME=windows
node= TRAVIS_OS_NAME=windows
node= TRAVIS_OS_NAME=linux
lts/dubnium=/dubnium TRAVIS_OS_NAME=linux
node= TRAVIS_OS_NAME=windows