Skip to content

Commit dcd9c4d

Browse files
committed
docs: api
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 04a8636 commit dcd9c4d

5 files changed

Lines changed: 35 additions & 58 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
"todo-tree.tree.buttons.viewStyle": true,
240240
"todo-tree.tree.expanded": true,
241241
"todo-tree.tree.filterCaseSensitive": true,
242-
"todo-tree.tree.scanMode": "workspace",
242+
"todo-tree.tree.scanMode": "workspace only",
243243
"todo-tree.tree.showBadges": true,
244244
"todo-tree.tree.showCountsInTree": true,
245245
"todo-tree.tree.showCurrentScanMode": true,

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [Install](#install)
2020
- [Use](#use)
2121
- [API](#api)
22+
- [`unified().use(docastParse)`](#unifiedusedocastparse)
2223
- [Syntax](#syntax)
2324
- [Docblock](#docblock)
2425
- [Markdown](#markdown)
@@ -78,7 +79,19 @@ In browsers with [`esm.sh`][esmsh]:
7879

7980
## API
8081

81-
**TODO**: api
82+
This package exports no identifiers. The default export is [`docastParse`](#unifiedusedocastparse).
83+
84+
### `unified().use(docastParse)`
85+
86+
Add support for docblock parsing.
87+
88+
#### Parameters
89+
90+
There are no parameters.
91+
92+
#### Returns
93+
94+
Nothing (`undefined`).
8295

8396
## Syntax
8497

@@ -94,7 +107,7 @@ in extending markdown, more information is available in the [`mdast-util-from-ma
94107

95108
## Syntax tree
96109

97-
The syntax tree format is [docast][docast].
110+
The syntax tree is [docast][docast].
98111

99112
## Types
100113

src/__tests__/plugin.integration.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* @module docast-parse/tests/integration/plugin
44
*/
55

6-
import type { Options } from '@flex-development/docast-util-from-docs'
7-
import { constant, type Nilable } from '@flex-development/tutils'
6+
import { constant } from '@flex-development/tutils'
87
import remarkDirective from 'remark-directive'
98
import { read } from 'to-vfile'
109
import { unified } from 'unified'
@@ -21,10 +20,10 @@ describe('integration:plugin', () => {
2120
})
2221
})
2322

24-
describe.each<['empty' | 'non-empty', Nilable<Options>?]>([
25-
['empty'],
26-
['non-empty', { transforms: [vi.fn()] }]
27-
])('%s document', (type, options) => {
23+
describe.each<'empty' | 'non-empty'>([
24+
'empty',
25+
'non-empty'
26+
])('%s document', type => {
2827
let file: VFile
2928
let value: string
3029

@@ -36,7 +35,7 @@ describe('integration:plugin', () => {
3635
it('should configure parser', () => {
3736
// Act
3837
const result = unified()
39-
.use(testSubject, options)
38+
.use(testSubject)
4039
.use(remarkDirective)
4140
.parse(file)
4241

src/__tests__/plugin.spec-d.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,13 @@
44
*/
55

66
import type { Root } from '@flex-development/docast'
7-
import type { Options } from '@flex-development/docast-util-from-docs'
8-
import type { Nilable } from '@flex-development/tutils'
7+
import type { EmptyArray } from '@flex-development/tutils'
98
import type * as unified from 'unified'
109
import type TestSubject from '../plugin'
1110

1211
describe('unit-d:plugin', () => {
13-
it('should match unified.Plugin<[Nilable<Options>?], string, Root>', () => {
12+
it('should equal unified.Plugin<EmptyArray, string, Root>', () => {
1413
expectTypeOf<typeof TestSubject>()
15-
.toMatchTypeOf<unified.Plugin<[Nilable<Options>?], string, Root>>()
16-
})
17-
18-
describe('parameters', () => {
19-
it('should be callable with [Nilable<Options>?]', () => {
20-
expectTypeOf<typeof TestSubject>()
21-
.parameters.toEqualTypeOf<[Nilable<Options>?]>()
22-
})
23-
})
24-
25-
describe('returns', () => {
26-
it('should return void', () => {
27-
expectTypeOf<typeof TestSubject>().returns.toBeVoid()
28-
})
14+
.toEqualTypeOf<unified.Plugin<EmptyArray, string, Root>>()
2915
})
3016
})

src/plugin.ts

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import type { Root } from '@flex-development/docast'
77
import { fromDocs, type Options } from '@flex-development/docast-util-from-docs'
8-
import type { Nilable, Optional } from '@flex-development/tutils'
8+
import type { EmptyArray, Optional } from '@flex-development/tutils'
99
import type { Extension as MdastExtension } from 'mdast-util-from-markdown'
1010
import type { Extension as MicromarkExtension } from 'micromark-util-types'
11-
import type { Data, Plugin, Processor } from 'unified'
11+
import type { Plugin, Processor } from 'unified'
1212
import type { VFile } from 'vfile'
1313

1414
declare module 'unified' {
@@ -31,7 +31,8 @@ declare module 'unified' {
3131
micromarkExtensions?: Optional<MicromarkExtension[]>
3232
}
3333

34-
interface Settings extends Options {}
34+
interface Settings
35+
extends Omit<Options, 'mdastExtensions' | 'micromarkExtensions'> {}
3536
}
3637

3738
/**
@@ -42,30 +43,9 @@ declare module 'unified' {
4243
*
4344
* @this {Processor}
4445
*
45-
* @param {Nilable<Options>?} [options] - Configuration options
4646
* @return {void} Nothing
4747
*/
48-
function plugin(this: Processor, options?: Nilable<Options>): void {
49-
/**
50-
* Processor data.
51-
*
52-
* @const {Data} data
53-
*/
54-
const data: Data = this.data()
55-
56-
// initialize extensions
57-
data.fromMarkdownExtensions ??= []
58-
data.micromarkExtensions ??= []
59-
60-
// initialize options
61-
options ??= {}
62-
options.mdastExtensions ??= []
63-
options.micromarkExtensions ??= []
64-
65-
// configure extensions
66-
data.fromMarkdownExtensions.push(...options.mdastExtensions)
67-
data.micromarkExtensions.push(...options.micromarkExtensions)
68-
48+
function plugin(this: Processor): void {
6949
/**
7050
* Docblock parser.
7151
*
@@ -75,10 +55,11 @@ function plugin(this: Processor, options?: Nilable<Options>): void {
7555
*/
7656
const parser = (document: string, file: VFile): Root => {
7757
return fromDocs(String(file), {
58+
// options are not documented in the readme.
59+
// options should be set by plugins on `data` instead of passed by users.
7860
...this.data('settings'),
79-
...options,
80-
mdastExtensions: data.fromMarkdownExtensions,
81-
micromarkExtensions: data.micromarkExtensions
61+
mdastExtensions: this.data('fromMarkdownExtensions'),
62+
micromarkExtensions: this.data('micromarkExtensions')
8263
})
8364
}
8465

@@ -88,15 +69,13 @@ function plugin(this: Processor, options?: Nilable<Options>): void {
8869
/**
8970
* Add support for docblock parsing.
9071
*
91-
* @see {@linkcode Options}
9272
* @see {@linkcode Plugin}
9373
* @see {@linkcode Root}
9474
*
9575
* @this {Processor}
9676
*
97-
* @param {Nilable<Options>?} [options] - Configuration options
9877
* @return {void} Nothing
9978
*/
100-
const docastParse: Plugin<[Nilable<Options>?], string, Root> = plugin
79+
const docastParse: Plugin<EmptyArray, string, Root> = plugin
10180

10281
export default docastParse

0 commit comments

Comments
 (0)