Skip to content

Commit cce7bcc

Browse files
committed
Refactor code-style
1 parent c9b0466 commit cce7bcc

File tree

3 files changed

+205
-209
lines changed

3 files changed

+205
-209
lines changed

lib/index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* @typedef {import('mdast').Nodes} MdastNodes
33
* @typedef {import('mdast').Parents} MdastParents
44
*
5+
* @typedef {import('nlcst').Paragraph} NlcstParagraph
6+
* @typedef {import('nlcst').Parents} NlcstParents
57
* @typedef {import('nlcst').Root} NlcstRoot
68
* @typedef {import('nlcst').RootContent} NlcstRootContent
7-
* @typedef {import('nlcst').Parents} NlcstParents
9+
* @typedef {import('nlcst').Sentence} NlcstSentence
810
* @typedef {import('nlcst').SentenceContent} NlcstSentenceContent
911
* @typedef {import('nlcst').WhiteSpace} NlcstWhiteSpace
10-
* @typedef {import('nlcst').Sentence} NlcstSentence
11-
* @typedef {import('nlcst').Paragraph} NlcstParagraph
1212
*
1313
* @typedef {import('unist').Point} Point
1414
*
@@ -19,9 +19,9 @@
1919

2020
/**
2121
* @typedef {{
22-
* tokenizeSentencePlugins: Array<(node: NlcstSentence) => void>,
23-
* tokenizeParagraphPlugins: Array<(node: NlcstParagraph) => void>,
24-
* tokenizeRootPlugins: Array<(node: NlcstRoot) => void>,
22+
* tokenizeSentencePlugins: Array<(node: NlcstSentence) => undefined | void>,
23+
* tokenizeParagraphPlugins: Array<(node: NlcstParagraph) => undefined | void>,
24+
* tokenizeRootPlugins: Array<(node: NlcstRoot) => undefined | void>,
2525
* parse(value: string | null | undefined): NlcstRoot
2626
* tokenize(value: string | null | undefined): Array<NlcstSentenceContent>
2727
* }} ParserInstance
@@ -46,18 +46,18 @@
4646
* Info passed around.
4747
* @property {string} doc
4848
* Whole document.
49+
* @property {Array<string>} ignore
50+
* List of mdast node types to ignore.
4951
* @property {Location} place
5052
* Location info.
5153
* @property {ParserInstance} parser
5254
* Parser.
53-
* @property {Array<string>} ignore
54-
* List of mdast node types to ignore.
5555
* @property {Array<string>} source
5656
* List of mdast node types to mark as source.
5757
*/
5858

5959
import {toString} from 'nlcst-to-string'
60-
import {pointStart, pointEnd} from 'unist-util-position'
60+
import {pointEnd, pointStart} from 'unist-util-position'
6161
import {location} from 'vfile-location'
6262

6363
const defaultIgnore = ['table', 'tableRow', 'tableCell']
@@ -78,10 +78,10 @@ const terminalMarker = /^([!.?\u2026\u203D]+)$/
7878
* mdast tree to transform.
7979
* @param {VFile} file
8080
* Virtual file.
81-
* @param {ParserInstance | ParserConstructor} Parser
81+
* @param {ParserConstructor | ParserInstance} Parser
8282
* Parser to use.
8383
* @param {Options | null | undefined} [options]
84-
* Configuration.
84+
* Configuration (optional).
8585
* @returns {NlcstRoot}
8686
* nlcst tree.
8787
*/
@@ -293,7 +293,7 @@ function all(state, parent) {
293293
* nlcst sentence content.
294294
* @param {number | undefined} offset
295295
* Offset.
296-
* @returns {void}
296+
* @returns {undefined}
297297
* Nothing.
298298
*/
299299
function patch(state, nodes, offset) {
@@ -310,11 +310,11 @@ function patch(state, nodes, offset) {
310310
const end =
311311
typeof start === 'number' ? start + toString(node).length : undefined
312312

313-
// @ts-expect-error: to do: fix this.
313+
const startPoint = state.place.toPoint(start)
314+
const endPoint = state.place.toPoint(end)
315+
314316
node.position =
315-
start !== undefined && end !== undefined
316-
? {start: state.place.toPoint(start), end: state.place.toPoint(end)}
317-
: undefined
317+
startPoint && endPoint ? {start: startPoint, end: endPoint} : undefined
318318

319319
start = end
320320
}

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ For example, [`parse-dutch`][parse-dutch], [`parse-english`][parse-english], or
233233
234234
```ts
235235
type ParserInstance = {
236-
tokenizeSentencePlugins: ((node: NlcstSentence) => void)[]
237-
tokenizeParagraphPlugins: ((node: NlcstParagraph) => void)[]
238-
tokenizeRootPlugins: ((node: NlcstRoot) => void)[]
236+
tokenizeSentencePlugins: ((node: NlcstSentence) => undefined)[]
237+
tokenizeParagraphPlugins: ((node: NlcstParagraph) => undefined)[]
238+
tokenizeRootPlugins: ((node: NlcstRoot) => undefined)[]
239239
parse(value: string | null | undefined): NlcstRoot
240240
tokenize(value: string | null | undefined): Array<NlcstSentenceContent>
241241
}

0 commit comments

Comments
 (0)