diff --git a/lib/index.d.mts b/lib/index.d.mts new file mode 100644 index 0000000..0edde7f --- /dev/null +++ b/lib/index.d.mts @@ -0,0 +1,3 @@ +export * from "./str.mjs"; +export * from "./nodes.mjs"; +export * from "./types.mjs"; diff --git a/lib/index.mjs b/lib/index.mjs new file mode 100644 index 0000000..0edde7f --- /dev/null +++ b/lib/index.mjs @@ -0,0 +1,3 @@ +export * from "./str.mjs"; +export * from "./nodes.mjs"; +export * from "./types.mjs"; diff --git a/lib/lang.d.mts b/lib/lang.d.mts new file mode 100644 index 0000000..1f6e3c3 --- /dev/null +++ b/lib/lang.d.mts @@ -0,0 +1,5 @@ +export declare function isNil(v: Nilable): v is Nil; +export declare type Nullable = T | null; +export declare type Nilable = T | Nil; +export declare type Nil = null | undefined; +export declare function isBool(v: unknown): v is boolean; diff --git a/lib/nodes.d.mts b/lib/nodes.d.mts new file mode 100644 index 0000000..acbac54 --- /dev/null +++ b/lib/nodes.d.mts @@ -0,0 +1,30 @@ +import { Nilable } from "./lang.mjs"; +export declare type AnyNode = AnySyncNode | AnyAsyncNode; +export declare type AnyAsyncNode = Promise; +export declare type AnySyncNode = TextNode | Elem | Frag; +export declare class TextNode extends String { +} +export declare function F(children: AnyNode[]): Frag; +export declare class Frag { + #private; + constructor(); + get children(): Nilable; + withText(text: string): this; + addText(text: string): void; + maybeWithChildren(nodes?: Nilable): this; + withChildren(nodes: AnyNode[]): this; + withChild(node: AnyNode): this; + addChild(node: AnyNode): void; +} +export declare function E(tagName: string, attrs: ElemAttrs, children?: Nilable): Elem; +export declare type ElemAttrs = Record; +export declare class Elem extends Frag { + #private; + constructor(tagName: string); + get tagName(): string; + get attrs(): Record; + withAttrs(attrs: Record): Elem; + withAttr(name: string, value: unknown): Elem; + addAttr(name: string, value: unknown): void; + addChild(node: AnySyncNode): void; +} diff --git a/lib/str.d.mts b/lib/str.d.mts new file mode 100644 index 0000000..c97add4 --- /dev/null +++ b/lib/str.d.mts @@ -0,0 +1,5 @@ +import { Renderer } from "./types.mjs"; +import { Elem } from "./nodes.mjs"; +export declare class StrRenderer implements Renderer { + render(node: Elem | Promise): Promise; +} diff --git a/lib/types.d.mts b/lib/types.d.mts new file mode 100644 index 0000000..fd25db7 --- /dev/null +++ b/lib/types.d.mts @@ -0,0 +1,4 @@ +import { Elem } from "./nodes.mjs"; +export interface Renderer { + render(node: Elem | Promise): Promise; +} diff --git a/makefile b/makefile index 8436e74..f01afd3 100644 --- a/makefile +++ b/makefile @@ -6,4 +6,4 @@ ts-w: npx tsc-watch clean: - rm -rf target + rm -rf lib diff --git a/package.json b/package.json index 1c54e83..4a26304 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,13 @@ { + "name": "ren", + "description": "", + "version": "0.0.1", + "main": "lib/index.mjs", + "types": "lib/index.d.mts", + "directories": { + "lib": "lib", + "src": "src" + }, "devDependencies": { "@types/node": "^17.0.21", "@typescript-eslint/eslint-plugin": "^5.14.0", @@ -9,5 +18,15 @@ "prettier": "^2.5.1", "tsc-watch": "^4.6.0", "typescript": "^4.6.2" - } + }, + "repository": { + "type": "git", + "url": "git+https://github.com/pleshevskiy/ren.git" + }, + "author": "Dmitriy Pleshevskiy ", + "license": "MIT", + "bugs": { + "url": "https://github.com/pleshevskiy/ren/issues" + }, + "homepage": "https://github.com/pleshevskiy/ren#readme" } diff --git a/src/index.mts b/src/index.mts new file mode 100644 index 0000000..0edde7f --- /dev/null +++ b/src/index.mts @@ -0,0 +1,3 @@ +export * from "./str.mjs"; +export * from "./nodes.mjs"; +export * from "./types.mjs"; diff --git a/tsconfig.json b/tsconfig.json index f4674db..33398dc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "module": "ESNext", "lib": ["dom", "esNext"], "moduleResolution": "node", + "declaration": true, "rootDir": "src", "forceConsistentCasingInFileNames": true, "suppressImplicitAnyIndexErrors": true,