Skip to content

Commit 1407d30

Browse files
committed
Use ESM
1 parent 7afedb3 commit 1407d30

File tree

6 files changed

+61
-56
lines changed

6 files changed

+61
-56
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
.DS_Store
22
*.log
3-
.nyc_output/
43
coverage/
54
node_modules/
6-
unist-util-stringify-position.js
7-
unist-util-stringify-position.min.js
85
yarn.lock

.prettierignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
coverage/
2-
unist-util-stringify-position.js
3-
unist-util-stringify-position.min.js
4-
*.json
52
*.md

index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
'use strict'
2-
31
var own = {}.hasOwnProperty
42

5-
module.exports = stringify
6-
7-
function stringify(value) {
3+
export function stringifyPosition(value) {
84
// Nothing.
95
if (!value || typeof value !== 'object') {
106
return ''

package.json

+12-17
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,20 @@
2525
"contributors": [
2626
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
2727
],
28+
"sideEffects": false,
29+
"type": "module",
30+
"main": "index.js",
2831
"types": "types/index.d.ts",
2932
"files": [
3033
"types/index.d.ts",
3134
"index.js"
3235
],
3336
"dependencies": {
34-
"@types/unist": "^2.0.2"
37+
"@types/unist": "^2.0.0"
3538
},
3639
"devDependencies": {
3740
"browserify": "^17.0.0",
41+
"c8": "^7.0.0",
3842
"dtslint": "^4.0.0",
3943
"nyc": "^15.0.0",
4044
"prettier": "^2.0.0",
@@ -47,19 +51,10 @@
4751
},
4852
"scripts": {
4953
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
50-
"build-bundle": "browserify . -s unistUtilStringifyPosition -o unist-util-stringify-position.js",
51-
"build-mangle": "browserify . -s unistUtilStringifyPosition -o unist-util-stringify-position.min.js -p tinyify",
52-
"build": "npm run build-bundle && npm run build-mangle",
53-
"test-api": "node test",
54-
"test-coverage": "nyc --reporter lcov tape test.js",
54+
"test-api": "node test.js",
55+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
5556
"test-types": "dtslint types",
56-
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
57-
},
58-
"nyc": {
59-
"check-coverage": true,
60-
"lines": 100,
61-
"functions": 100,
62-
"branches": 100
57+
"test": "npm run format && npm run test-coverage && npm run test-types"
6358
},
6459
"prettier": {
6560
"tabWidth": 2,
@@ -71,10 +66,10 @@
7166
},
7267
"xo": {
7368
"prettier": true,
74-
"esnext": false,
75-
"ignores": [
76-
"unist-util-stringify-position.js"
77-
]
69+
"rules": {
70+
"no-var": "off",
71+
"prefer-arrow-callback": "off"
72+
}
7873
},
7974
"remarkConfig": {
8075
"plugins": [

readme.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
## Install
1414

15+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
16+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
17+
1518
[npm][]:
1619

1720
```sh
@@ -21,16 +24,16 @@ npm install unist-util-stringify-position
2124
## Use
2225

2326
```js
24-
var stringify = require('unist-util-stringify-position')
27+
import {stringifyPosition} from 'unist-util-stringify-position'
2528

2629
// Point
27-
stringify({line: 2, column: 3}) // => '2:3'
30+
stringifyPosition({line: 2, column: 3}) // => '2:3'
2831

2932
// Position
30-
stringify({start: {line: 2}, end: {line: 3}}) // => '2:1-3:1'
33+
stringifyPosition({start: {line: 2}, end: {line: 3}}) // => '2:1-3:1'
3134

3235
// Node
33-
stringify({
36+
stringifyPosition({
3437
type: 'text',
3538
value: '!',
3639
position: {
@@ -42,6 +45,9 @@ stringify({
4245

4346
## API
4447

48+
This package exports the following identifiers: `stringifyPosition`.
49+
There is no default export.
50+
4551
### `stringifyPosition(node|position|point)`
4652

4753
Stringify one [point][], a [position][] (start and end [point][]s), or a node’s

test.js

+38-24
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var stringify = require('.')
1+
import test from 'tape'
2+
import {stringifyPosition} from './index.js'
53

64
test('stringifyPosition', function (t) {
7-
t.equal(stringify(), '', 'should return empty `string` with `undefined`')
8-
t.equal(stringify(null), '', 'should return empty `string` with `null`')
9-
t.equal(stringify('foo'), '', 'should return empty `string` with `string`')
10-
t.equal(stringify(5), '', 'should return empty `string` with `number`')
11-
t.equal(stringify({}), '', 'should return empty `string` with `{}`')
5+
t.equal(
6+
stringifyPosition(),
7+
'',
8+
'should return empty `string` with `undefined`'
9+
)
10+
t.equal(
11+
stringifyPosition(null),
12+
'',
13+
'should return empty `string` with `null`'
14+
)
15+
t.equal(
16+
stringifyPosition('foo'),
17+
'',
18+
'should return empty `string` with `string`'
19+
)
20+
t.equal(
21+
stringifyPosition(5),
22+
'',
23+
'should return empty `string` with `number`'
24+
)
25+
t.equal(stringifyPosition({}), '', 'should return empty `string` with `{}`')
1226

1327
t.equal(
14-
stringify({type: 'text'}),
28+
stringifyPosition({type: 'text'}),
1529
'1:1-1:1',
1630
'should return a range for a `node` without `position`'
1731
)
1832

1933
t.equal(
20-
stringify({type: 'text', position: 3}),
34+
stringifyPosition({type: 'text', position: 3}),
2135
'1:1-1:1',
2236
'should return a range for `node` with invalid `position` #1'
2337
)
2438

2539
t.equal(
26-
stringify({
40+
stringifyPosition({
2741
type: 'text',
2842
position: {start: {}, end: {}}
2943
}),
@@ -32,7 +46,7 @@ test('stringifyPosition', function (t) {
3246
)
3347

3448
t.equal(
35-
stringify({
49+
stringifyPosition({
3650
type: 'text',
3751
position: {
3852
start: {line: null, column: null},
@@ -44,7 +58,7 @@ test('stringifyPosition', function (t) {
4458
)
4559

4660
t.equal(
47-
stringify({
61+
stringifyPosition({
4862
type: 'text',
4963
position: {
5064
start: {line: 2, column: 5},
@@ -56,25 +70,25 @@ test('stringifyPosition', function (t) {
5670
)
5771

5872
t.equal(
59-
stringify({start: null, end: null}),
73+
stringifyPosition({start: null, end: null}),
6074
'1:1-1:1',
6175
'should return a range for a `position` without `point`s'
6276
)
6377

6478
t.equal(
65-
stringify({start: 3, end: 6}),
79+
stringifyPosition({start: 3, end: 6}),
6680
'1:1-1:1',
6781
'should return a range for `position` with invalid `point`s #1'
6882
)
6983

7084
t.equal(
71-
stringify({start: {}, end: {}}),
85+
stringifyPosition({start: {}, end: {}}),
7286
'1:1-1:1',
7387
'should return range for `position` with invalid `point`s #1'
7488
)
7589

7690
t.equal(
77-
stringify({
91+
stringifyPosition({
7892
start: {line: null, column: null},
7993
end: {line: null, column: null}
8094
}),
@@ -83,7 +97,7 @@ test('stringifyPosition', function (t) {
8397
)
8498

8599
t.equal(
86-
stringify({
100+
stringifyPosition({
87101
start: {line: 2, column: 5},
88102
end: {line: 2, column: 6}
89103
}),
@@ -92,31 +106,31 @@ test('stringifyPosition', function (t) {
92106
)
93107

94108
t.equal(
95-
stringify({line: null, column: null}),
109+
stringifyPosition({line: null, column: null}),
96110
'1:1',
97111
'should return a point for a `point` without indices'
98112
)
99113

100114
t.equal(
101-
stringify({line: 'foo', column: 'bar'}),
115+
stringifyPosition({line: 'foo', column: 'bar'}),
102116
'1:1',
103117
'should return a point for a `point` with invalid indices #1'
104118
)
105119

106120
t.equal(
107-
stringify({line: 4}),
121+
stringifyPosition({line: 4}),
108122
'4:1',
109123
'should return a point for a partially valid `point` #1'
110124
)
111125

112126
t.equal(
113-
stringify({column: 12}),
127+
stringifyPosition({column: 12}),
114128
'1:12',
115129
'should return a point for a partially valid `point` #1'
116130
)
117131

118132
t.equal(
119-
stringify({line: 5, column: 2}),
133+
stringifyPosition({line: 5, column: 2}),
120134
'5:2',
121135
'should return a point for a valid `point`'
122136
)

0 commit comments

Comments
 (0)