UNPKG

2.15 kBTypeScriptView Raw
1// Type definitions for non-npm package Unist 2.0
2// Project: https://github.com/syntax-tree/unist
3// Definitions by: bizen241 <https://github.com/bizen241>
4// Jun Lu <https://github.com/lujun2>
5// Hernan Rajchert <https://github.com/hrajchert>
6// Titus Wormer <https://github.com/wooorm>
7// Junyoung Choi <https://github.com/rokt33r>
8// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9// TypeScript Version: 3.0
10
11/**
12 * Syntactic units in unist syntax trees are called nodes.
13 */
14export interface Node {
15 /**
16 * The variant of a node.
17 */
18 type: string;
19
20 /**
21 * Information from the ecosystem.
22 */
23 data?: Data;
24
25 /**
26 * Location of a node in a source document.
27 * Must not be present if a node is generated.
28 */
29 position?: Position;
30
31 [key: string]: unknown;
32}
33
34/**
35 * Information associated by the ecosystem with the node.
36 * Space is guaranteed to never be specified by unist or specifications
37 * implementing unist.
38 */
39export interface Data {
40 [key: string]: unknown;
41}
42
43/**
44 * Location of a node in a source file.
45 */
46export interface Position {
47 /**
48 * Place of the first character of the parsed source region.
49 */
50 start: Point;
51
52 /**
53 * Place of the first character after the parsed source region.
54 */
55 end: Point;
56
57 /**
58 * Start column at each index (plus start line) in the source region,
59 * for elements that span multiple lines.
60 */
61 indent?: number[];
62}
63
64/**
65 * One place in a source file.
66 */
67export interface Point {
68 /**
69 * Line in a source file (1-indexed integer).
70 */
71 line: number;
72
73 /**
74 * Column in a source file (1-indexed integer).
75 */
76 column: number;
77 /**
78 * Character in a source file (0-indexed integer).
79 */
80 offset?: number;
81}
82
83/**
84 * Nodes containing other nodes.
85 */
86export interface Parent extends Node {
87 /**
88 * List representing the children of a node.
89 */
90 children: Node[];
91}
92
93/**
94 * Nodes containing a value.
95 */
96export interface Literal extends Node {
97 value: unknown;
98}