From ac52d79dde40f6c3bfa33aa273262072e4b02adf Mon Sep 17 00:00:00 2001 From: bizen241 Date: Thu, 31 Aug 2017 09:02:59 +0900 Subject: [PATCH] [unist]: add types (#19472) --- types/unist/index.d.ts | 39 ++++++++++++++++++++++++++++++ types/unist/tsconfig.json | 22 +++++++++++++++++ types/unist/tslint.json | 1 + types/unist/unist-tests.ts | 49 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 types/unist/index.d.ts create mode 100644 types/unist/tsconfig.json create mode 100644 types/unist/tslint.json create mode 100644 types/unist/unist-tests.ts diff --git a/types/unist/index.d.ts b/types/unist/index.d.ts new file mode 100644 index 0000000000..5eed577657 --- /dev/null +++ b/types/unist/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for Unist 1.0 +// Project: https://github.com/syntax-tree/unist +// Definitions by: bizen241 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +export interface Node { + type: string; + data?: Data; + position?: Position; +} + +export interface Data { + [key: string]: string | number | object | any[] | boolean | null; +} + +export interface Position { + start: Point; + end: Point; + /** >= 1 */ + indent?: number[]; +} + +export interface Point { + /** >= 1 */ + line: number; + /** >= 1 */ + column: number; + /** >= 0 */ + offset?: number; +} + +export interface Parent extends Node { + children: Node[]; +} + +export interface Text extends Node { + value: string; +} diff --git a/types/unist/tsconfig.json b/types/unist/tsconfig.json new file mode 100644 index 0000000000..0ba86f9b59 --- /dev/null +++ b/types/unist/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "unist-tests.ts" + ] +} diff --git a/types/unist/tslint.json b/types/unist/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/unist/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/unist/unist-tests.ts b/types/unist/unist-tests.ts new file mode 100644 index 0000000000..b49f1002f9 --- /dev/null +++ b/types/unist/unist-tests.ts @@ -0,0 +1,49 @@ +import * as Unist from 'unist'; + +const data: Unist.Data = { + string: 'string', + number: 1, + object: { + key: 'value', + }, + array: [], + boolean: true, + null: null, +}; + +const point: Unist.Point = { + line: 1, + column: 1, + offset: 0, +}; + +const position: Unist.Position = { + start: point, + end: point, + indent: [ + 1, + ], +}; + +const node: Unist.Node = { + type: 'node', + data, + position, +}; + +const text: Unist.Text = { + type: 'text', + data, + position, + value: 'value', +}; + +const parent: Unist.Parent = { + type: 'parent', + data, + position, + children: [ + node, + text, + ], +};