Skip to content

Commit 57dad20

Browse files
committed
Refactor code-style
1 parent 3c8b138 commit 57dad20

File tree

5 files changed

+59
-48
lines changed

5 files changed

+59
-48
lines changed

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
unist-util-stringify-position.js
3+
unist-util-stringify-position.min.js

index.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
'use strict';
1+
'use strict'
22

3-
var own = {}.hasOwnProperty;
3+
var own = {}.hasOwnProperty
44

5-
module.exports = stringify;
5+
module.exports = stringify
66

77
function stringify(value) {
88
/* Nothing. */
99
if (!value || typeof value !== 'object') {
10-
return null;
10+
return null
1111
}
1212

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

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

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

2828
/* ? */
29-
return null;
29+
return null
3030
}
3131

3232
function point(point) {
3333
if (!point || typeof point !== 'object') {
34-
point = {};
34+
point = {}
3535
}
3636

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

4040
function position(pos) {
4141
if (!pos || typeof pos !== 'object') {
42-
pos = {};
42+
pos = {}
4343
}
4444

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

4848
function index(value) {
49-
return value && typeof value === 'number' ? value : 1;
49+
return value && typeof value === 'number' ? value : 1
5050
}

package.json

+13-5
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,37 @@
2828
"browserify": "^16.0.0",
2929
"esmangle": "^1.0.0",
3030
"nyc": "^11.0.0",
31+
"prettier": "^1.12.1",
3132
"remark-cli": "^5.0.0",
3233
"remark-preset-wooorm": "^4.0.0",
3334
"tape": "^4.5.1",
3435
"xo": "^0.20.0"
3536
},
3637
"scripts": {
37-
"build-md": "remark . --quiet --frail --output",
38+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3839
"build-bundle": "browserify index.js --no-builtins -s unistUtilStringifyPosition > unist-util-stringify-position.js",
3940
"build-mangle": "esmangle unist-util-stringify-position.js > unist-util-stringify-position.min.js",
40-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
41-
"lint": "xo",
41+
"build": "npm run build-bundle && npm run build-mangle",
4242
"test-api": "node test",
4343
"test-coverage": "nyc --reporter lcov tape test.js",
44-
"test": "npm run build && npm run lint && npm run test-coverage"
44+
"test": "npm run format && npm run build && npm run test-coverage"
4545
},
4646
"nyc": {
4747
"check-coverage": true,
4848
"lines": 100,
4949
"functions": 100,
5050
"branches": 100
5151
},
52+
"prettier": {
53+
"tabWidth": 2,
54+
"useTabs": false,
55+
"singleQuote": true,
56+
"bracketSpacing": false,
57+
"semi": false,
58+
"trailingComma": "none"
59+
},
5260
"xo": {
53-
"space": true,
61+
"prettier": true,
5462
"esnext": false,
5563
"rules": {
5664
"guard-for-in": "off",

readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ npm install unist-util-stringify-position
1313
## Usage
1414

1515
```javascript
16-
var stringify = require('unist-util-stringify-position');
16+
var stringify = require('unist-util-stringify-position')
1717

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

2121
// Position
2222
stringify({
2323
start: {line: 2},
2424
end: {line: 3}
25-
}); //=> '2:1-3:1'
25+
}) // => '2:1-3:1'
2626

2727
// Node
2828
stringify({
@@ -32,7 +32,7 @@ stringify({
3232
start: {line: 5, column: 11},
3333
end: {line: 5, column: 12}
3434
}
35-
}); //=> '5:11-5:12'
35+
}) // => '5:11-5:12'
3636
```
3737

3838
## API

test.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
'use strict';
1+
'use strict'
22

3-
var test = require('tape');
4-
var stringify = require('.');
3+
var test = require('tape')
4+
var stringify = require('.')
55

6-
test('stringifyPosition', function (t) {
7-
t.equal(stringify(), null, 'should return `null` with `undefined`');
8-
t.equal(stringify(null), null, 'should return `null` with `null`');
9-
t.equal(stringify('foo'), null, 'should return `null` with `string`');
10-
t.equal(stringify(5), null, 'should return `null` with `number`');
11-
t.equal(stringify({}), null, 'should return `null` with `{}`');
6+
test('stringifyPosition', function(t) {
7+
t.equal(stringify(), null, 'should return `null` with `undefined`')
8+
t.equal(stringify(null), null, 'should return `null` with `null`')
9+
t.equal(stringify('foo'), null, 'should return `null` with `string`')
10+
t.equal(stringify(5), null, 'should return `null` with `number`')
11+
t.equal(stringify({}), null, 'should return `null` with `{}`')
1212

1313
t.equal(
1414
stringify({type: 'text'}),
1515
'1:1-1:1',
1616
'should return a range for a `node` without `position`'
17-
);
17+
)
1818

1919
t.equal(
2020
stringify({type: 'text', position: 3}),
2121
'1:1-1:1',
2222
'should return a range for `node` with invalid `position` #1'
23-
);
23+
)
2424

2525
t.equal(
2626
stringify({
@@ -29,7 +29,7 @@ test('stringifyPosition', function (t) {
2929
}),
3030
'1:1-1:1',
3131
'should return a range for `node` with invalid `position` #2'
32-
);
32+
)
3333

3434
t.equal(
3535
stringify({
@@ -41,7 +41,7 @@ test('stringifyPosition', function (t) {
4141
}),
4242
'1:1-1:1',
4343
'should return a range for `node` with invalid `position` #3'
44-
);
44+
)
4545

4646
t.equal(
4747
stringify({
@@ -53,25 +53,25 @@ test('stringifyPosition', function (t) {
5353
}),
5454
'2:5-2:6',
5555
'should return a range for `node` with valid `position`'
56-
);
56+
)
5757

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

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

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

7676
t.equal(
7777
stringify({
@@ -80,7 +80,7 @@ test('stringifyPosition', function (t) {
8080
}),
8181
'1:1-1:1',
8282
'should return range for `position` with invalid `point`s #3'
83-
);
83+
)
8484

8585
t.equal(
8686
stringify({
@@ -89,37 +89,37 @@ test('stringifyPosition', function (t) {
8989
}),
9090
'2:5-2:6',
9191
'should return range for `position` with valid `point`s'
92-
);
92+
)
9393

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

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

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

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

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

124-
t.end();
125-
});
124+
t.end()
125+
})

0 commit comments

Comments
 (0)