mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-02 00:00:04 +00:00
[idyll-compiler] add types definition for idyll-compiler (#25397)
* add types for idyll-compiler * remove unnecessary tslint rule for new typedefs
This commit is contained in:
13
types/idyll-compiler/idyll-compiler-tests.ts
Normal file
13
types/idyll-compiler/idyll-compiler-tests.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import compile from "idyll-compiler";
|
||||
|
||||
// Dummy log
|
||||
const log = (msg: string) => {};
|
||||
|
||||
// $ExpectType Node[] | Promise<Node[]>
|
||||
compile("*italics*", { async: false }, () => log("window"));
|
||||
|
||||
// $ExpectType Node[] | Promise<Node[]>
|
||||
compile("Simple **idyll**", { async: false });
|
||||
|
||||
// $ExpectType Node[] | Promise<Node[]>
|
||||
compile(`# Test`);
|
||||
55
types/idyll-compiler/index.d.ts
vendored
Normal file
55
types/idyll-compiler/index.d.ts
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
// Type definitions for idyll-compiler 3.1
|
||||
// Project: https://github.com/idyll-lang/idyll/tree/master/packages/idyll-compiler
|
||||
// Definitions by: Thanh Ngo <https://github.com/iocat>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
export type PropType = "variable" | "value" | "expression";
|
||||
export type PropData = string | number | boolean;
|
||||
export type PropKey = string;
|
||||
export type PropValue = [PropType, PropData];
|
||||
export type Property = [PropKey, PropValue];
|
||||
type __RecursiveNode<T> = [string, Property[], T[]];
|
||||
export interface TreeNode extends __RecursiveNode<Node> {}
|
||||
export type Node = TreeNode | string;
|
||||
export type AST = Node[];
|
||||
|
||||
export type PostProcessor =
|
||||
| ((ast: AST) => AST)
|
||||
| ((ast: AST, callback: (err: any, value: AST) => void) => void);
|
||||
|
||||
export interface Options {
|
||||
spellcheck?: boolean;
|
||||
|
||||
smartquotes?: boolean;
|
||||
|
||||
/**
|
||||
* If false and there is no postprocessors, compiler returns the AST synchronously
|
||||
* Otherwise, a promise is returned
|
||||
*
|
||||
*/
|
||||
async?: boolean;
|
||||
|
||||
/**
|
||||
* compiler plugins
|
||||
* If provided, compiler always compiles asynchronously
|
||||
*/
|
||||
postProcessors?: PostProcessor[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the given idyllMarkup and returns an AST either synchronously
|
||||
* or asynchronously.
|
||||
*
|
||||
* If postProcessors are provided or options.async is set to true:
|
||||
* compiler returns a promise
|
||||
* Otherwise, compile returns the AST synchronously
|
||||
*
|
||||
*/
|
||||
declare function compiler(
|
||||
input: string,
|
||||
options?: Options,
|
||||
callback?: () => void
|
||||
): Promise<AST> | AST;
|
||||
|
||||
export default compiler;
|
||||
16
types/idyll-compiler/tsconfig.json
Normal file
16
types/idyll-compiler/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictFunctionTypes": true
|
||||
},
|
||||
"files": ["index.d.ts", "idyll-compiler-tests.ts"]
|
||||
}
|
||||
3
types/idyll-compiler/tslint.json
Normal file
3
types/idyll-compiler/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user