Skip to content

Commit 5924d1a

Browse files
committed
Update wording relating to positional info
Related to syntax-tree/unist@f2b8587.
1 parent c8fc762 commit 5924d1a

File tree

4 files changed

+44
-40
lines changed

4 files changed

+44
-40
lines changed

Diff for: index.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,37 @@ function stringify(value) {
1212

1313
/* Node. */
1414
if (own.call(value, 'position') || own.call(value, 'type')) {
15-
return location(value.position);
15+
return position(value.position);
1616
}
1717

18-
/* Location. */
18+
/* Position. */
1919
if (own.call(value, 'start') || own.call(value, 'end')) {
20-
return location(value);
20+
return position(value);
2121
}
2222

23-
/* Position. */
23+
/* Point. */
2424
if (own.call(value, 'line') || own.call(value, 'column')) {
25-
return position(value);
25+
return point(value);
2626
}
2727

2828
/* ? */
2929
return null;
3030
}
3131

32-
function position(pos) {
33-
if (!pos || typeof pos !== 'object') {
34-
pos = {};
32+
function point(point) {
33+
if (!point || typeof point !== 'object') {
34+
point = {};
3535
}
3636

37-
return index(pos.line) + ':' + index(pos.column);
37+
return index(point.line) + ':' + index(point.column);
3838
}
3939

40-
function location(loc) {
41-
if (!loc || typeof loc !== 'object') {
42-
loc = {};
40+
function position(pos) {
41+
if (!pos || typeof pos !== 'object') {
42+
pos = {};
4343
}
4444

45-
return position(loc.start) + '-' + position(loc.end);
45+
return point(pos.start) + '-' + point(pos.end);
4646
}
4747

4848
function index(value) {

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "unist-util-stringify-position",
33
"version": "1.1.1",
4-
"description": "Stringify a Unist node, location, or position",
4+
"description": "Stringify a Unist node, position, or point",
55
"license": "MIT",
66
"keywords": [
77
"unist",
88
"position",
99
"location",
10+
"point",
1011
"node",
1112
"stringify",
1213
"tostring",

Diff for: readme.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# unist-util-stringify-position [![Build Status][build-badge]][build-page] [![Coverage Status][coverage-badge]][coverage-page]
22

3-
Stringify a [**Unist**][unist] [position][] or [location][].
3+
Stringify a [**Unist**][unist] [`Position`][position] or [`Point`][point].
44

55
## Installation
66

@@ -15,13 +15,16 @@ npm install unist-util-stringify-position
1515
```javascript
1616
var stringify = require('unist-util-stringify-position');
1717

18-
stringify({line: 2, column: 3 }); //=> '2:3'
18+
// Point
19+
stringify({line: 2, column: 3}); //=> '2:3'
1920

21+
// Position
2022
stringify({
2123
start: {line: 2},
2224
end: {line: 3}
2325
}); //=> '2:1-3:1'
2426

27+
// Node
2528
stringify({
2629
type: 'text',
2730
value: '!',
@@ -34,27 +37,27 @@ stringify({
3437

3538
## API
3639

37-
### `stringifyPosition(node|location|position)`
40+
### `stringifyPosition(node|position|point)`
3841

39-
Stringify one position, a location (start and end positions), or
40-
a node’s location.
42+
Stringify one point, a position (start and end points), or
43+
a node’s position.
4144

4245
###### Parameters
4346

4447
* `node` ([`Node`][node])
4548
— Node whose `'position'` property to stringify
46-
* `location` ([`Location`][location])
47-
— Location whose `'start'` and `'end'` positions to stringify
4849
* `position` ([`Position`][position])
49-
— Location whose `'line'` and `'column'` to stringify
50+
— Position whose `'start'` and `'end'` points to stringify
51+
* `point` ([`Point`][point])
52+
— Point whose `'line'` and `'column'` to stringify
5053

5154
###### Returns
5255

5356
`string?` — A range `ls:cs-le:ce` (when given `node` or
54-
`location`) or a point `l:c` (when given `position`), where `l` stands
57+
`position`) or a point `l:c` (when given `point`), where `l` stands
5558
for line, `c` for column, `s` for `start`, and `e` for
5659
end. `null` is returned if the given value is neither `node`,
57-
`location`, nor `position`.
60+
`position`, nor `point`.
5861

5962
## License
6063

@@ -80,6 +83,6 @@ end. `null` is returned if the given value is neither `node`,
8083

8184
[node]: https://github.com/syntax-tree/unist#node
8285

83-
[location]: https://github.com/syntax-tree/unist#location
84-
8586
[position]: https://github.com/syntax-tree/unist#position
87+
88+
[point]: https://github.com/syntax-tree/unist#point

Diff for: test.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('stringifyPosition', function (t) {
1919
t.equal(
2020
stringify({type: 'text', position: 3}),
2121
'1:1-1:1',
22-
'should return range for `node` with invalid `position` #1'
22+
'should return a range for `node` with invalid `position` #1'
2323
);
2424

2525
t.equal(
@@ -28,7 +28,7 @@ test('stringifyPosition', function (t) {
2828
position: {start: {}, end: {}}
2929
}),
3030
'1:1-1:1',
31-
'should return range for `node` with invalid `position` #2'
31+
'should return a range for `node` with invalid `position` #2'
3232
);
3333

3434
t.equal(
@@ -40,7 +40,7 @@ test('stringifyPosition', function (t) {
4040
}
4141
}),
4242
'1:1-1:1',
43-
'should return range for `node` with invalid `position` #3'
43+
'should return a range for `node` with invalid `position` #3'
4444
);
4545

4646
t.equal(
@@ -52,25 +52,25 @@ test('stringifyPosition', function (t) {
5252
}
5353
}),
5454
'2:5-2:6',
55-
'should return range for `node` with valid `position`'
55+
'should return a range for `node` with valid `position`'
5656
);
5757

5858
t.equal(
5959
stringify({start: null, end: null}),
6060
'1:1-1:1',
61-
'should return a range for a `location` without `position`s'
61+
'should return a range for a `position` without `point`s'
6262
);
6363

6464
t.equal(
6565
stringify({start: 3, end: 6}),
6666
'1:1-1:1',
67-
'should return range for `location` with invalid `position`s #1'
67+
'should return a range for `position` with invalid `point`s #1'
6868
);
6969

7070
t.equal(
7171
stringify({start: {}, end: {}}),
7272
'1:1-1:1',
73-
'should return range for `location` with invalid `position`s #1'
73+
'should return range for `position` with invalid `point`s #1'
7474
);
7575

7676
t.equal(
@@ -79,7 +79,7 @@ test('stringifyPosition', function (t) {
7979
end: {line: null, column: null}
8080
}),
8181
'1:1-1:1',
82-
'should return range for `location` with invalid `position`s #3'
82+
'should return range for `position` with invalid `point`s #3'
8383
);
8484

8585
t.equal(
@@ -88,37 +88,37 @@ test('stringifyPosition', function (t) {
8888
end: {line: 2, column: 6}
8989
}),
9090
'2:5-2:6',
91-
'should return range for `location` with valid `position`s'
91+
'should return range for `position` with valid `point`s'
9292
);
9393

9494
t.equal(
9595
stringify({line: null, column: null}),
9696
'1:1',
97-
'should return a point for a `position` without indices'
97+
'should return a point for a `point` without indices'
9898
);
9999

100100
t.equal(
101101
stringify({line: 'foo', column: 'bar'}),
102102
'1:1',
103-
'should return a point for a `position` with invalid indices #1'
103+
'should return a point for a `point` with invalid indices #1'
104104
);
105105

106106
t.equal(
107107
stringify({line: 4}),
108108
'4:1',
109-
'should return a point for a partially valid `position` #1'
109+
'should return a point for a partially valid `point` #1'
110110
);
111111

112112
t.equal(
113113
stringify({column: 12}),
114114
'1:12',
115-
'should return a point for a partially valid `position` #1'
115+
'should return a point for a partially valid `point` #1'
116116
);
117117

118118
t.equal(
119119
stringify({line: 5, column: 2}),
120120
'5:2',
121-
'should return a point for a valid `position`'
121+
'should return a point for a valid `point`'
122122
);
123123

124124
t.end();

0 commit comments

Comments
 (0)