@types/unist
Advanced tools
Comparing version 2.0.6 to 3.0.0
@@ -1,2 +0,2 @@ | ||
// Type definitions for non-npm package Unist 2.0 | ||
// Type definitions for non-npm package unist 3.0 | ||
// Project: https://github.com/syntax-tree/unist | ||
@@ -10,40 +10,52 @@ // Definitions by: bizen241 <https://github.com/bizen241> | ||
// JounQin <https://github.com/JounQin> | ||
// Remco Haszing <https://github.com/remcohaszing> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 3.0 | ||
// ## Interfaces | ||
/** | ||
* Syntactic units in unist syntax trees are called nodes. | ||
* Info associated with nodes by the ecosystem. | ||
* | ||
* @typeParam TData Information from the ecosystem. Useful for more specific {@link Node.data}. | ||
* This space is guaranteed to never be specified by unist or specifications | ||
* implementing unist. | ||
* But you can use it in utilities and plugins to store data. | ||
* | ||
* This type can be augmented to register custom data. | ||
* For example: | ||
* | ||
* ```ts | ||
* declare module 'unist' { | ||
* interface Data { | ||
* // `someNode.data.myId` is typed as `number | undefined` | ||
* myId?: number | undefined | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
export interface Node<TData extends object = Data> { | ||
export interface Data {} | ||
/** | ||
* One place in a source file. | ||
*/ | ||
export interface Point { | ||
/** | ||
* The variant of a node. | ||
* Line in a source file (1-indexed integer). | ||
*/ | ||
type: string; | ||
line: number; | ||
/** | ||
* Information from the ecosystem. | ||
* Column in a source file (1-indexed integer). | ||
*/ | ||
data?: TData | undefined; | ||
column: number; | ||
/** | ||
* Location of a node in a source document. | ||
* Must not be present if a node is generated. | ||
* Character in a source file (0-indexed integer). | ||
*/ | ||
position?: Position | undefined; | ||
offset?: number | undefined; | ||
} | ||
/** | ||
* Information associated by the ecosystem with the node. | ||
* Space is guaranteed to never be specified by unist or specifications | ||
* implementing unist. | ||
* Position of a node in a source document. | ||
* | ||
* A position is a range between two points. | ||
*/ | ||
export interface Data { | ||
[key: string]: unknown; | ||
} | ||
/** | ||
* Location of a node in a source file. | ||
*/ | ||
export interface Position { | ||
@@ -59,58 +71,63 @@ /** | ||
end: Point; | ||
} | ||
// ## Abstract nodes | ||
/** | ||
* Abstract unist node that contains the smallest possible value. | ||
* | ||
* This interface is supposed to be extended. | ||
* | ||
* For example, in HTML, a `text` node is a leaf that contains text. | ||
*/ | ||
export interface Literal extends Node { | ||
/** | ||
* Start column at each index (plus start line) in the source region, | ||
* for elements that span multiple lines. | ||
* Plain value. | ||
*/ | ||
indent?: number[] | undefined; | ||
value: unknown; | ||
} | ||
/** | ||
* One place in a source file. | ||
* Abstract unist node. | ||
* | ||
* The syntactic unit in unist syntax trees are called nodes. | ||
* | ||
* This interface is supposed to be extended. | ||
* If you can use {@link Literal} or {@link Parent}, you should. | ||
* But for example in markdown, a `thematicBreak` (`***`), is neither literal | ||
* nor parent, but still a node. | ||
*/ | ||
export interface Point { | ||
export interface Node { | ||
/** | ||
* Line in a source file (1-indexed integer). | ||
* Node type. | ||
*/ | ||
line: number; | ||
type: string; | ||
/** | ||
* Column in a source file (1-indexed integer). | ||
* Info from the ecosystem. | ||
*/ | ||
column: number; | ||
data?: Data | undefined; | ||
/** | ||
* Character in a source file (0-indexed integer). | ||
* Position of a node in a source document. | ||
* | ||
* Nodes that are generated (not in the original source document) must not | ||
* have a position. | ||
*/ | ||
offset?: number | undefined; | ||
position?: Position | undefined; | ||
} | ||
/** | ||
* Util for extracting type of {@link Node.data} | ||
* Abstract unist node that contains other nodes (*children*). | ||
* | ||
* @typeParam TNode Specific node type such as {@link Node} with {@link Data}, {@link Literal}, etc. | ||
* This interface is supposed to be extended. | ||
* | ||
* @example `NodeData<Node<{ key: string }>>` -> `{ key: string }` | ||
* For example, in XML, an element is a parent of different things, such as | ||
* comments, text, and further elements. | ||
*/ | ||
export type NodeData<TNode extends Node<object>> = TNode extends Node<infer TData> ? TData : never; | ||
/** | ||
* Nodes containing other nodes. | ||
* | ||
* @typeParam ChildNode Node item of {@link Parent.children} | ||
*/ | ||
export interface Parent<ChildNode extends Node<object> = Node, TData extends object = NodeData<ChildNode>> | ||
extends Node<TData> { | ||
export interface Parent extends Node { | ||
/** | ||
* List representing the children of a node. | ||
* List of children. | ||
*/ | ||
children: ChildNode[]; | ||
children: Node[]; | ||
} | ||
/** | ||
* Nodes containing a value. | ||
* | ||
* @typeParam Value Specific value type of {@link Literal.value} such as `string` for `Text` node | ||
*/ | ||
export interface Literal<Value = unknown, TData extends object = Data> extends Node<TData> { | ||
value: Value; | ||
} |
{ | ||
"name": "@types/unist", | ||
"version": "2.0.6", | ||
"description": "TypeScript definitions for Unist", | ||
"version": "3.0.0", | ||
"description": "TypeScript definitions for unist", | ||
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/unist", | ||
@@ -42,2 +42,7 @@ "license": "MIT", | ||
"githubUsername": "JounQin" | ||
}, | ||
{ | ||
"name": "Remco Haszing", | ||
"url": "https://github.com/remcohaszing", | ||
"githubUsername": "remcohaszing" | ||
} | ||
@@ -54,4 +59,4 @@ ], | ||
"dependencies": {}, | ||
"typesPublisherContentHash": "da5f2c3f967fa07869161991244bb7f9a237ac20494b902ffcb9108deb9b4e12", | ||
"typeScriptVersion": "3.6" | ||
"typesPublisherContentHash": "d01bbf21d54cdad6cb77aba467390915cba5c7bef4f2a1f7a3a02afab3b5873d", | ||
"typeScriptVersion": "4.3" | ||
} |
@@ -5,3 +5,3 @@ # Installation | ||
# Summary | ||
This package contains type definitions for Unist (https://github.com/syntax-tree/unist). | ||
This package contains type definitions for unist (https://github.com/syntax-tree/unist). | ||
@@ -12,3 +12,3 @@ # Details | ||
### Additional Details | ||
* Last updated: Thu, 15 Jul 2021 00:31:23 GMT | ||
* Last updated: Thu, 06 Jul 2023 20:32:45 GMT | ||
* Dependencies: none | ||
@@ -18,2 +18,2 @@ * Global values: none | ||
# Credits | ||
These definitions were written by [bizen241](https://github.com/bizen241), [Jun Lu](https://github.com/lujun2), [Hernan Rajchert](https://github.com/hrajchert), [Titus Wormer](https://github.com/wooorm), [Junyoung Choi](https://github.com/rokt33r), [Ben Moon](https://github.com/GuiltyDolphin), and [JounQin](https://github.com/JounQin). | ||
These definitions were written by [bizen241](https://github.com/bizen241), [Jun Lu](https://github.com/lujun2), [Hernan Rajchert](https://github.com/hrajchert), [Titus Wormer](https://github.com/wooorm), [Junyoung Choi](https://github.com/rokt33r), [Ben Moon](https://github.com/GuiltyDolphin), [JounQin](https://github.com/JounQin), and [Remco Haszing](https://github.com/remcohaszing). |
6939
119