Skip to content

Commit bdb240d

Browse files
committed
Refactor code-style
1 parent fe9064f commit bdb240d

File tree

10 files changed

+166
-379
lines changed

10 files changed

+166
-379
lines changed

.editorconfig

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ root = true
22

33
[*]
44
indent_style = space
5-
indent_size = 4
5+
indent_size = 2
66
end_of_line = lf
77
charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
10-
11-
[*.{json,html,svg,css,remarkrc,eslintrc}]
12-
indent_size = 2
13-
14-
[*.md]
15-
trim_trailing_whitespace = false

.eslintignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

.jscs.json

Lines changed: 0 additions & 39 deletions
This file was deleted.

.remarkrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

example.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

history.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

index.js

Lines changed: 34 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,50 @@
1-
/**
2-
* @author Titus Wormer
3-
* @copyright 2016 Titus Wormer
4-
* @license MIT
5-
* @module unist:util:stringify-position
6-
* @fileoverview Stringify a Unist node, location, or position.
7-
*/
8-
91
'use strict';
102

11-
/* eslint-env commonjs */
3+
var has = require('has');
124

13-
/*
14-
* Methods.
15-
*/
5+
module.exports = stringify;
166

17-
var has = Object.prototype.hasOwnProperty;
7+
function stringify(value) {
8+
/* Nothing. */
9+
if (!value || typeof value !== 'object') {
10+
return null;
11+
}
1812

19-
/**
20-
* Stringify a single index.
21-
*
22-
* @param {*} value - Index?
23-
* @return {string?} - Stringified index?
24-
*/
25-
function index(value) {
26-
return value && typeof value === 'number' ? value : 1;
13+
/* Node. */
14+
if (has(value, 'position') || has(value, 'type')) {
15+
return location(value.position);
16+
}
17+
18+
/* Location. */
19+
if (has(value, 'start') || has(value, 'end')) {
20+
return location(value);
21+
}
22+
23+
/* Position. */
24+
if (has(value, 'line') || has(value, 'column')) {
25+
return position(value);
26+
}
27+
28+
/* ? */
29+
return null;
2730
}
2831

29-
/**
30-
* Stringify a single position.
31-
*
32-
* @param {*} pos - Position?
33-
* @return {string?} - Stringified position?
34-
*/
3532
function position(pos) {
36-
if (!pos || typeof pos !== 'object') {
37-
pos = {};
38-
}
33+
if (!pos || typeof pos !== 'object') {
34+
pos = {};
35+
}
3936

40-
return index(pos.line) + ':' + index(pos.column);
37+
return index(pos.line) + ':' + index(pos.column);
4138
}
4239

43-
/**
44-
* Stringify a single location.
45-
*
46-
* @param {*} loc - Location?
47-
* @return {string?} - Stringified location?
48-
*/
4940
function location(loc) {
50-
if (!loc || typeof loc !== 'object') {
51-
loc = {};
52-
}
41+
if (!loc || typeof loc !== 'object') {
42+
loc = {};
43+
}
5344

54-
return position(loc.start) + '-' + position(loc.end);
45+
return position(loc.start) + '-' + position(loc.end);
5546
}
5647

57-
/**
58-
* Stringify a node, location, or position into a range or
59-
* a point.
60-
*
61-
* @param {Node|Position|Location} value - Thing to stringify.
62-
* @return {string?} - Stringified positional information?
63-
*/
64-
function stringify(value) {
65-
/* Nothing. */
66-
if (!value || typeof value !== 'object') {
67-
return null;
68-
}
69-
70-
/* Node. */
71-
if (has.call(value, 'position') || has.call(value, 'type')) {
72-
return location(value.position);
73-
}
74-
75-
/* Location. */
76-
if (has.call(value, 'start') || has.call(value, 'end')) {
77-
return location(value);
78-
}
79-
80-
/* Position. */
81-
if (has.call(value, 'line') || has.call(value, 'column')) {
82-
return position(value);
83-
}
84-
85-
/* ? */
86-
return null;
48+
function index(value) {
49+
return value && typeof value === 'number' ? value : 1;
8750
}
88-
89-
/*
90-
* Expose.
91-
*/
92-
93-
module.exports = stringify;

package.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,33 @@
2727
],
2828
"devDependencies": {
2929
"browserify": "^13.0.0",
30-
"eslint": "^2.0.0",
3130
"esmangle": "^1.0.0",
3231
"istanbul": "^0.4.0",
33-
"jscs": "^3.0.0",
34-
"jscs-jsdoc": "^2.0.0",
3532
"remark": "^4.0.0",
3633
"remark-comment-config": "^3.0.0",
3734
"remark-github": "^4.0.0",
3835
"remark-lint": "^3.0.0",
3936
"remark-usage": "^3.0.0",
40-
"tape": "^4.5.1"
37+
"tape": "^4.5.1",
38+
"xo": "^0.17.1"
4139
},
4240
"scripts": {
4341
"build-md": "remark . --quiet --frail",
4442
"build-bundle": "browserify index.js --no-builtins -s unistUtilStringifyPosition > unist-util-stringify-position.js",
4543
"build-mangle": "esmangle unist-util-stringify-position.js > unist-util-stringify-position.min.js",
4644
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
47-
"lint-api": "eslint .",
48-
"lint-style": "jscs --reporter inline .",
49-
"lint": "npm run lint-api && npm run lint-style",
45+
"lint": "xo",
5046
"test-api": "node test.js",
5147
"test-coverage": "istanbul cover test.js",
5248
"test": "npm run build && npm run lint && npm run test-coverage"
49+
},
50+
"xo": {
51+
"space": true,
52+
"ignores": [
53+
"unist-util-stringify-position.js"
54+
]
55+
},
56+
"dependencies": {
57+
"has": "^1.0.1"
5358
}
5459
}

0 commit comments

Comments
 (0)