Skip to content

Commit

Permalink
Add JSDoc based types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 27, 2021
1 parent 0637355 commit 82bf759
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
*.d.ts
*.log
coverage/
node_modules/
Expand Down
18 changes: 0 additions & 18 deletions hastscript-tests.ts

This file was deleted.

74 changes: 45 additions & 29 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
// TypeScript Version: 3.5

import {Element, Properties, Node} from 'hast'

/**
* DSL to create virtual hast trees for HTML or SVG
*
* @param selector Simple CSS selector
* @param children (Lists of) child nodes
*/
declare function hastscript(
selector?: string,
children?: string | Node | Array<string | Node>
): Element

/**
* DSL to create virtual hast trees for HTML or SVG
*
* @param selector Simple CSS selector
* @param properties Map of properties
* @param children (Lists of) child nodes
*/
declare function hastscript(
selector?: string,
properties?: Properties,
children?: string | Node | Array<string | Node>
): Element

export = hastscript
export function h(): HastRoot
export function h(selector: null | undefined, ...children: HChild[]): HastRoot
export function h(
selector: string,
properties: HProperties,
...children: HChild[]
): HastElement
export function h(selector: string, ...children: HChild[]): HastElement
export function s(): HastRoot
export function s(selector: null | undefined, ...children: HChild[]): HastRoot
export function s(
selector: string,
properties: HProperties,
...children: HChild[]
): HastElement
export function s(selector: string, ...children: HChild[]): HastElement
export type HastRoot = import('hast').Root
export type HastElement = import('hast').Element
export type Properties = import('hast').Properties
export type HastChild = HastRoot['children'][number]
export type Info = import('property-information/lib/util/schema').Schema['property'][string]
export type Schema =
| import('property-information/lib/util/schema').Schema
| import('property-information/lib/util/schema').Schema
export type HStyleValue = string | number
export type HStyle = {
[x: string]: HStyleValue
}
export type HPrimitiveValue = string | number | boolean | null | undefined
export type HArrayValue = Array<string | number>
export type HPropertyValue = HPrimitiveValue | (string | number)[]
export type HProperties = {
[property: string]:
| {
[x: string]: HStyleValue
}
| HPropertyValue
}
export type HPrimitiveChild = string | number | null | undefined
export type HNodeChild = HastChild | HastRoot
export type HArrayChild = Array<HPrimitiveChild | HNodeChild>
export type HChild =
| HPrimitiveChild
| HNodeChild
| (HPrimitiveChild | HNodeChild)[]
Loading

0 comments on commit 82bf759

Please sign in to comment.