Skip to content

Commit

Permalink
Refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 19, 2024
1 parent 19e59f5 commit f401100
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
37 changes: 35 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
import type {Position} from 'unist'

export type {Options, Space} from './lib/index.js'
import type {VFile} from 'vfile'

export {fromParse5} from './lib/index.js'

/**
* Configuration.
*/
export interface Options {
/**
* File used to add positional info to nodes (optional).
*
* If given, the file should represent the original HTML source.
*/
file?: VFile | null | undefined

/**
* Which space the document is in (default: `'html'`).
*
* When an `<svg>` element is found in the HTML space, this package already
* automatically switches to and from the SVG space when entering and exiting
* it.
*/
space?: Space | null | undefined

/**
* Whether to add extra positional info about starting tags, closing tags,
* and attributes to elements (default: `false`).
*
* > 👉 **Note**: only used when `file` is given.
*/
verbose?: boolean | null | undefined
}

/**
* Namespace.
*/
export type Space = 'html' | 'svg'

// Register data on hast.
declare module 'hast' {
interface ElementData {
Expand Down
22 changes: 1 addition & 21 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,10 @@
* @import {Schema} from 'property-information'
* @import {Point, Position} from 'unist'
* @import {VFile} from 'vfile'
* @import {Options} from 'hast-util-from-parse5'
*/

/**
* @typedef Options
* Configuration.
* @property {Space | null | undefined} [space='html']
* Which space the document is in (default: `'html'`).
*
* When an `<svg>` element is found in the HTML space, this package already
* automatically switches to and from the SVG space when entering and exiting
* it.
* @property {VFile | null | undefined} [file]
* File used to add positional info to nodes (optional).
*
* If given, the file should represent the original HTML source.
* @property {boolean | null | undefined} [verbose=false]
* Whether to add extra positional info about starting tags, closing tags,
* and attributes to elements (default: `false`).
*
* > 👉 **Note**: only used when `file` is given.
*
* @typedef {'html' | 'svg'} Space
* Namespace.
*
* @typedef State
* Info passed around about the current state.
* @property {VFile | undefined} file
Expand Down

0 comments on commit f401100

Please sign in to comment.