Skip to content

Commit ba8f680

Browse files
committedMay 21, 2022
Refactor code-style
1 parent 4ee3d76 commit ba8f680

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed
 

‎lib/contents.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77
* @typedef {import('./search.js').SearchEntry} SearchEntry
88
*
99
* @typedef ContentsOptions
10-
* @property {boolean} [tight=false] Whether to compile list-items tightly.
11-
* @property {boolean} [ordered=false] Whether to compile list-items as an ordered list, otherwise they are unordered.
12-
* @property {string|null} [prefix=null] Add a prefix to links to headings in the table of contents. Useful for example when later going from mdast to hast and sanitizing with `hast-util-sanitize`.
10+
* @property {boolean} [tight=false]
11+
* Whether to compile list-items tightly.
12+
* @property {boolean} [ordered=false]
13+
* Whether to compile list-items as an ordered list, otherwise they are
14+
* unordered.
15+
* @property {string|null} [prefix=null]
16+
* Add a prefix to links to headings in the table of contents.
17+
* Useful for example when later going from mdast to hast and sanitizing with
18+
* `hast-util-sanitize`.
1319
*/
1420

1521
import extend from 'extend'
1622

1723
/**
1824
* Transform a list of heading objects to a markdown list.
1925
*
20-
* @param {Array.<SearchEntry>} map
26+
* @param {Array<SearchEntry>} map
2127
* @param {ContentsOptions} settings
2228
*/
2329
export function contents(map, settings) {
@@ -129,11 +135,11 @@ function insert(entry, parent, settings) {
129135
}
130136

131137
/**
132-
* @param {Array.<PhrasingContent>} [nodes]
133-
* @returns {Array.<StaticPhrasingContent>}
138+
* @param {Array<PhrasingContent>} [nodes]
139+
* @returns {Array<StaticPhrasingContent>}
134140
*/
135141
function all(nodes) {
136-
/** @type {Array.<StaticPhrasingContent>} */
142+
/** @type {Array<StaticPhrasingContent>} */
137143
let result = []
138144
let index = -1
139145

@@ -148,7 +154,7 @@ function all(nodes) {
148154

149155
/**
150156
* @param {PhrasingContent} node
151-
* @returns {StaticPhrasingContent|Array.<StaticPhrasingContent>}
157+
* @returns {StaticPhrasingContent|Array<StaticPhrasingContent>}
152158
*/
153159
function one(node) {
154160
if (

‎lib/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* @typedef {SearchOptions & ContentsOptions & ExtraOptions} Options
77
*
88
* @typedef ExtraOptions
9-
* @property {string} [heading] Heading to look for, wrapped in `new RegExp('^(' + value + ')$', 'i')`.
9+
* @property {string} [heading]
10+
* Heading to look for, wrapped in `new RegExp('^(' + value + ')$', 'i')`.
1011
*
1112
* @typedef Result
1213
* @property {number|null} index

‎lib/search.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,29 @@
77
* @typedef {import('unist-util-is').TestFunctionAnything} IsTestFunctionAnything
88
*
99
* @typedef SearchOptions
10-
* @property {string} [skip] Headings to skip, wrapped in `new RegExp('^(' + value + ')$', 'i')`. Any heading matching this expression will not be present in the table of contents.
11-
* @property {IsType|IsProps|IsTestFunctionAnything|Array.<IsType|IsProps|IsTestFunctionAnything>} [parents]
12-
* @property {Heading['depth']} [maxDepth=6] Maximum heading depth to include in the table of contents. This is inclusive: when set to `3`, level three headings are included (those with three hashes, `###`).
10+
* @property {string} [skip]
11+
* Headings to skip, wrapped in `new RegExp('^(' + value + ')$', 'i')`.
12+
* Any heading matching this expression will not be present in the table of
13+
* contents.
14+
* @property {IsType|IsProps|IsTestFunctionAnything|Array<IsType|IsProps|IsTestFunctionAnything>} [parents]
15+
* Allow headings to be children of certain node types (default: the to `toc`
16+
* given `tree`, to only allow top-level headings).
17+
* Internally, uses `unist-util-is` to check, so `parents` can be any
18+
* `is`-compatible test.
19+
* @property {Heading['depth']} [maxDepth=6]
20+
* Maximum heading depth to include in the table of contents.
21+
* This is inclusive: when set to `3`, level three headings are included
22+
* (those with three hashes, `###`).
1323
*
1424
* @typedef SearchEntry
1525
* @property {Heading['depth']} depth
16-
* @property {Array.<PhrasingContent>} children
26+
* @property {Array<PhrasingContent>} children
1727
* @property {string} id
1828
*
1929
* @typedef SearchResult
2030
* @property {number} index
2131
* @property {number} endIndex
22-
* @property {Array.<SearchEntry>} map
32+
* @property {Array<SearchEntry>} map
2333
*/
2434

2535
import Slugger from 'github-slugger'
@@ -41,7 +51,7 @@ const slugs = new Slugger()
4151
export function search(root, expression, settings) {
4252
const skip = settings.skip && toExpression(settings.skip)
4353
const parents = convert(settings.parents || ((d) => d === root))
44-
/** @type {Array.<SearchEntry>} */
54+
/** @type {Array<SearchEntry>} */
4555
const map = []
4656
/** @type {number|undefined} */
4757
let index

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
6969
"test-api": "node test/index.js",
7070
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
71-
"test": "npm run format && npm run test-coverage"
71+
"test": "npm run build && npm run format && npm run test-coverage"
7272
},
7373
"prettier": {
7474
"tabWidth": 2,

0 commit comments

Comments
 (0)
Please sign in to comment.