Skip to content

Commit

Permalink
chore: add types declaration (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmjuanes authored Jan 15, 2025
1 parent 948d946 commit a08f65c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
48 changes: 48 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
declare type HelperFunction = (params: {
args: any[];
opt: Record<string, any>;
context: Record<string, any>;
fn: (context?: Record<string, any>, vars?: Record<string, any>, output?: string[]) => string;
}) => string;

declare interface Helpers {
[key: string]: HelperFunction;
}

declare interface Partials {
[key: string]: string;
}

declare interface Functions {
[key: string]: (params: {
args: any[];
opt: Record<string, any>;
context: Record<string, any>;
}) => string | void;
}

declare interface MikelOptions {
helpers?: Helpers;
partials?: Partials;
functions?: Functions;
}

declare interface MikelTemplate {
(data?: any): string;
addHelper(name: string, fn: HelperFunction): void;
removeHelper(name: string): void;
addFunction(name: string, fn: (params: any) => string | void): void;
removeFunction(name: string): void;
addPartial(name: string, partial: string): void;
removePartial(name: string): void;
}

declare const mikel: {
(template: string, data?: any, options?: Partial<MikelOptions>): string;
create(template: string, options?: Partial<MikelOptions>): MikelTemplate;
escape(str: string): string;
get(context: any, path: string): any;
parse(value: string, context?: any, vars?: any): any;
};

export default mikel;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"bugs": "https://github.com/jmjuanes/mikel/issues",
"main": "index.js",
"module": "index.js",
"types": "index.d.ts",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
Expand All @@ -26,6 +27,7 @@
"files": [
"README.md",
"LICENSE",
"index.js"
"index.js",
"index.d.ts"
]
}

0 comments on commit a08f65c

Please sign in to comment.