Skip to content

Commit 14d43b1

Browse files
authored
🤖 Merge PR DefinitelyTyped#74808 Add types for textile-js by @phothinmg
1 parent 533d244 commit 14d43b1

5 files changed

Lines changed: 115 additions & 0 deletions

File tree

types/textile-js/.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts

types/textile-js/index.d.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export = textile;
2+
declare function textile(txt: string, opts?: textile.Options): string;
3+
declare namespace textile {
4+
type Tag = string;
5+
type JMLAttributes = Record<string, string | number | boolean | null | undefined>;
6+
type JMLElement = [Tag, ...(JMLAttributes | JMLElement | string)[]];
7+
type JMLNode = Array<JMLElement | string> & { sourceLength?: number };
8+
type JMLDocument = ["html", ...(JMLElement | string)[]];
9+
type TokenType = "OPEN" | "CLOSE" | "TEXT" | "SINGLE" | "WS" | "COMMENT";
10+
type Token =
11+
| {
12+
type: "OPEN" | "CLOSE" | "SINGLE";
13+
tag: Tag;
14+
attr?: JMLAttributes;
15+
pos: number;
16+
src: string;
17+
}
18+
| {
19+
type: "TEXT" | "WS" | "COMMENT";
20+
data: string;
21+
pos: number;
22+
src: string;
23+
};
24+
interface Options {
25+
breaks?: boolean;
26+
}
27+
const defaults: Options;
28+
function setOptions(opt: Options): typeof textile;
29+
function setoptions(opt: Options): typeof textile;
30+
function parse(txt: string, opts?: Options): string;
31+
function convert(txt: string, opts?: Options): string;
32+
function jsonml(txt: string, opts?: Options): JMLDocument;
33+
function serialize(jsonml: JMLElement | string): string;
34+
function html_parser(tokens: Token[], lazy?: boolean): JMLNode;
35+
}

types/textile-js/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"private": true,
3+
"name": "@types/textile-js",
4+
"version": "2.1.9999",
5+
"projects": [
6+
"https://github.com/borgar/textile-js"
7+
],
8+
"devDependencies": {
9+
"@types/textile-js": "workspace:."
10+
},
11+
"owners": [
12+
{
13+
"name": "phothinmg",
14+
"githubUsername": "phothinmg"
15+
}
16+
]
17+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import textile = require("textile-js");
2+
3+
const txt = "h1. Hello World";
4+
const opt: textile.Options = { breaks: true };
5+
6+
const rendered: string = textile(txt, opt);
7+
8+
const parsed: string = textile.parse(txt, opt);
9+
const converted: string = textile.convert(txt, opt);
10+
11+
const doc: textile.JMLDocument = textile.jsonml(txt, opt);
12+
const serializedDoc: string = textile.serialize(doc);
13+
14+
const node: textile.JMLElement = ["p", { class: "intro", "data-id": 1 }, "Hello"];
15+
const serializedNode: string = textile.serialize(node);
16+
17+
const textOnlySerialized: string = textile.serialize("plain text");
18+
19+
const defaults: textile.Options = textile.defaults;
20+
const chained: typeof textile = textile.setOptions(defaults).setoptions({ breaks: false });
21+
22+
const tokens: textile.Token[] = [
23+
{ type: "OPEN", tag: "p", pos: 0, src: "<p>" },
24+
{ type: "TEXT", data: "Hello", pos: 3, src: "Hello" },
25+
{ type: "CLOSE", tag: "p", pos: 8, src: "</p>" },
26+
];
27+
28+
const parsedNode: textile.JMLNode = textile.html_parser(tokens);
29+
const parsedNodeLazy: textile.JMLNode = textile.html_parser(tokens, true);
30+
31+
void rendered;
32+
void parsed;
33+
void converted;
34+
void serializedDoc;
35+
void serializedNode;
36+
void textOnlySerialized;
37+
void chained;
38+
void parsedNode;
39+
void parsedNodeLazy;

types/textile-js/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictFunctionTypes": true,
10+
"strictNullChecks": true,
11+
"types": [],
12+
"noEmit": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.d.ts",
17+
"textile-js-tests.ts"
18+
]
19+
}

0 commit comments

Comments
 (0)