diff --git a/types/index.d.ts b/types/index.d.ts index f4ead217..a8f35f70 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -5,8 +5,15 @@ import {VFile, VFileContents, VFileOptions} from 'vfile' import vfile = require('vfile') declare namespace unified { + /** + * Processor allows plugins, parsers, and compilers to be chained together to transform content. + * + * @typeParam P Processor settings. Useful when packaging unified with a preset parser and compiler. + */ interface Processor
{ /** + * Clone current processor + * * @returns New unfrozen processor which is configured to function the same as its ancestor. But when the descendant processor is configured in the future it does not affect the ancestral processor. */ (): Processor
@@ -17,6 +24,8 @@ declare namespace unified {
* @param plugin unified plugin
* @param settings Configuration for plugin
* @param extraSettings Additional configuration for plugin
+ * @typeParam S Plugin settings
+ * @typeParam S2 Extra plugin settings
* @returns The processor on which use is invoked
*/
use(
@@ -26,28 +35,33 @@ declare namespace unified {
): Processor
/** + * Configure the processor with a preset to use + * * @param preset `Object` with an plugins (set to list), and/or an optional settings object */ use(preset: Preset
): Processor
/**
+ * Configure using a tuple of plugin and setting(s)
+ *
* @param pluginTuple pairs, plugin and settings in an array
+ * @typeParam S Plugin settings
+ * @typeParam S2 Extra plugin settings
*/
- use(pluginTuple: PluginTuple): Processor
-
- /**
- * @param pluginTriple plugin, setting, and extraSettings in an array
- */
- use(
- pluginTriple: PluginTriple
+ use(
+ pluginTuple: PluginTuple
): Processor
/** + * A list of plugins and presets to be applied to processor + * * @param list List of plugins, presets, and pairs */ use(list: PluggableList
): Processor
/** + * Configuration passed to a frozen processor + * * @param processorSettings Settings passed to processor */ use(processorSettings: ProcessorSettings
): Processor
@@ -93,15 +107,35 @@ declare namespace unified {
/**
* Transform a syntax tree by applying plugins to it.
*
- * @param node
- * @param file `VFile` or anything which can be given to `vfile()`
- * @param done Invoked when transformation is complete.
- * Either invoked with an error or a syntax tree and a file.
+ * @param node Node to transform
* @returns `Promise` if `done` is not given. Rejected with an error, or resolved with the resulting syntax tree.
*/
run(node: Node): Promise
}
+ /**
+ * A Plugin (Attacher) is the thing passed to `use`.
+ * It configures the processor and in turn can receive options.
+ *
+ * Attachers can configure processors, such as by interacting with parsers and compilers, linking them to other processors, or by specifying how the syntax tree is handled.
+ *
+ * @this Processor context object is set to the invoked on processor.
+ * @param settings Configuration
+ * @param extraSettings Secondary configuration
+ * @typeParam S Plugin settings
+ * @typeParam S2 Extra plugin settings
+ * @typeParam P Processor settings
+ * @returns Optional Transformer.
+ */
type Plugin {
plugins: PluggableList
- settings?: S
+ settings?: Settings
}
/**
* Settings can be passed directly to the processor
+ *
+ * @typeParam P Settings applied to a processor. Useful when packaging unified with a preset parser and compiler.
*/
- interface ProcessorSettings {
+ settings: P
}
- type PluginTuple
+ | PluginTuple = Array , settings?: S, extraSettings?: S2): Transformer | void
@@ -219,8 +303,8 @@ declare namespace unified {
*
* The transformation process in unified is handled by `trough`, see it’s documentation for the exact semantics of transformers.
*
- * @param node
- * @param file
+ * @param node Node or tree to be transformed
+ * @param file File associated with node or tree
* @param next If the signature of a transformer includes `next` (third argument), the function may finish asynchronous, and must invoke `next()`.
* @returns
* - `Error` — Can be returned to stop the process
@@ -235,26 +319,74 @@ declare namespace unified {
): Error | Node | Promise (): unified.Processor
export = unified
= Attacher
+
+ /**
+ * Configuration passed to a Plugin or Processor
+ */
type Settings = {
[key: string]: unknown
}
+
/**
* Presets provide a potentially sharable way to configure processors.
* They can contain multiple plugins and optionally settings as well.
+ *
+ * @typeParam P Processor settings
*/
- interface Preset {
+ interface Preset {
- settings: S
+ interface ProcessorSettings = [Plugin, S]
- type PluginTriple = [
- Plugin,
- S,
- S2
- ]
+ /**
+ * A pairing of a plugin with its settings
+ *
+ * @typeParam S Plugin settings
+ * @typeParam S2 Extra plugin settings
+ * @typeParam P Processor settings
+ */
+ type PluginTuple =
+ | [Plugin, S]
+ | [Plugin, S, S2]
+
+ /**
+ * A union of the different ways to add plugins to unified
+ *
+ * @typeParam S Plugin settings
+ * @typeParam S2 Extra plugin settings
+ * @typeParam P Processor settings
+ */
type Pluggable =
| Plugin
- | Preset
- | PluginTuple
- | PluginTriple
+ | Preset
+
+ /**
+ * A list of plugins and presets
+ *
+ * @typeParam P Processor settings
+ */
type PluggableList {
(this: Processor