Skip to content

Commit ef0f7a0

Browse files
committed
Add TypeScript support and update package metadata
Add index.d.ts for TypeScript definitions, update files list to include TypeScript and documentation files, enhance keywords for better discoverability, and add TypeScript dev dependency.
1 parent f1b68c1 commit ef0f7a0

File tree

3 files changed

+186
-2
lines changed

3 files changed

+186
-2
lines changed

.npmignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# 测试相关文件
2+
test/
3+
coverage/
4+
*.test.js
5+
jest.config.js
6+
7+
# 开发工具和配置
8+
.eslintrc*
9+
.eslintignore
10+
.editorconfig
11+
.vscode/
12+
.idea/
13+
14+
# 开发文档
15+
CLAUDE.md
16+
.github/
17+
18+
# 依赖和构建产物
19+
node_modules/
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*
23+
24+
# 锁文件
25+
package-lock.json
26+
yarn.lock
27+
28+
# 临时文件
29+
.DS_Store
30+
Thumbs.db
31+
.tmp
32+
.temp
33+
34+
# 源码管理
35+
.git/
36+
.gitignore
37+
38+
# TypeScript 构建产物(如果有的话)
39+
*.tsbuildinfo
40+
tsconfig.json
41+
42+
# 其他开发用文件
43+
*.log
44+
.nyc_output

index.d.ts

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/**
2+
* Template compilation options
3+
*/
4+
export interface CompileOptions {
5+
/** Block name to compile specific block */
6+
block?: string;
7+
/** Enable/disable caching */
8+
cache?: boolean;
9+
/** Cache directory name */
10+
cacheName?: string;
11+
}
12+
13+
/**
14+
* Template data object - can be any object type
15+
*/
16+
export type TemplateData = Record<string, any>;
17+
18+
/**
19+
* Compiled template function
20+
*/
21+
export interface CompiledTemplate {
22+
(data?: TemplateData, subTemplate?: string): string;
23+
}
24+
25+
/**
26+
* Template rendering callback
27+
*/
28+
export interface RenderCallback {
29+
(error: Error | null, result?: string): void;
30+
}
31+
32+
/**
33+
* Template compilation callback
34+
*/
35+
export interface CompileCallback {
36+
(error: Error | null, templateFunction?: CompiledTemplate): void;
37+
}
38+
39+
/**
40+
* Main template engine interface
41+
*/
42+
export interface CBTemplate {
43+
/** Template engine version */
44+
version: string;
45+
46+
/** Left delimiter for template syntax */
47+
leftDelimiter: string;
48+
49+
/** Right delimiter for template syntax */
50+
rightDelimiter: string;
51+
52+
/** Default HTML escaping setting */
53+
escape: boolean;
54+
55+
/** Base path for template files */
56+
basePath: string;
57+
58+
/** Cache path for compiled templates */
59+
cachePath: string;
60+
61+
/** Default file extension */
62+
defaultExtName: string;
63+
64+
/**
65+
* Compile template string to function
66+
* @param str Template string
67+
* @returns Compiled template function
68+
*/
69+
compile(str: string): CompiledTemplate;
70+
71+
/**
72+
* Render template string with data
73+
* @param str Template string
74+
* @param data Template data
75+
* @param subTemplate Sub template name
76+
* @returns Rendered string
77+
*/
78+
render(str: string, data?: TemplateData, subTemplate?: string): string;
79+
80+
/**
81+
* Compile template file with inheritance support
82+
* @param filename Template file path
83+
* @param options Compilation options
84+
* @param callback Compilation callback
85+
*/
86+
compileFile(filename: string, options: CompileOptions, callback: CompileCallback): void;
87+
compileFile(filename: string, callback: CompileCallback): void;
88+
89+
/**
90+
* Render template file with data and inheritance support
91+
* @param filename Template file path
92+
* @param data Template data
93+
* @param options Render options
94+
* @param callback Render callback
95+
*/
96+
renderFile(filename: string, data: TemplateData, options: CompileOptions, callback: RenderCallback): void;
97+
renderFile(filename: string, data: TemplateData, callback: RenderCallback): void;
98+
99+
/**
100+
* Get new instance of template engine
101+
* @returns New template engine instance
102+
*/
103+
getInstance(): CBTemplate;
104+
105+
/** Internal parse method */
106+
_parse(str: string): string;
107+
108+
/** Internal build template function method */
109+
_buildTemplateFunction(str: string): CompiledTemplate;
110+
}
111+
112+
/**
113+
* Template engine instance with static methods
114+
*/
115+
export interface CBTemplateStatic extends CBTemplate {
116+
/**
117+
* Get new instance of template engine
118+
* @returns New template engine instance
119+
*/
120+
getInstance(): CBTemplate;
121+
}
122+
123+
declare const cbTemplate: CBTemplateStatic;
124+
export default cbTemplate;

package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
"version": "1.3.9",
44
"description": "唱吧模板引擎",
55
"main": "index.js",
6+
"types": "index.d.ts",
7+
"files": [
8+
"index.js",
9+
"index.d.ts",
10+
"lib/",
11+
"README.md",
12+
"LICENSE"
13+
],
614
"scripts": {
715
"eslint": "eslint *.js",
816
"test": "jest",
@@ -14,7 +22,14 @@
1422
"url": "git+https://github.com/ChangbaFE/cbT.git"
1523
},
1624
"keywords": [
17-
"template"
25+
"template",
26+
"template-engine",
27+
"changba",
28+
"cbT",
29+
"server-side-template",
30+
"template-inheritance",
31+
"html-template",
32+
"node-template"
1833
],
1934
"author": "Hex",
2035
"license": "MIT",
@@ -24,6 +39,7 @@
2439
"homepage": "https://github.com/ChangbaFE/cbT#readme",
2540
"devDependencies": {
2641
"eslint": "^6.8.0",
27-
"jest": "^30.0.4"
42+
"jest": "^30.0.4",
43+
"typescript": "^5.8.3"
2844
}
2945
}

0 commit comments

Comments
 (0)