|
1 |
| -/* These definitions were imported from https://github.com/DefinitelyTyped/DefinitelyTyped |
2 |
| - * and includes previous contributions from the DefinitelyTyped community by: |
3 |
| - * - Albert Willemsen <https://github.com/AlbertWillemsen-Centric> |
4 |
| - * - Boris Yankov <https://github.com/borisyankov> |
5 |
| - * - Jessica Franco <https://github.com/Kovensky> |
6 |
| - * - Masahiro Wakame <https://github.com/vvakame> |
7 |
| - * - Raanan Weber <https://github.com/RaananW> |
8 |
| - * - Sergei Dorogin <https://github.com/evil-shrike> |
9 |
| - * - webbiesdk <https://github.com/webbiesdk> |
10 |
| - * - Andrew Leedham <https://github.com/AndrewLeedham> |
11 |
| - * - Nils Knappmeier <https://github.com/nknapp> |
12 |
| - * For full history prior to their migration to handlebars.js, please see: |
13 |
| - * https://github.com/DefinitelyTyped/DefinitelyTyped/commits/1ce60bdc07f10e0b076778c6c953271c072bc894/types/handlebars/index.d.ts |
14 |
| - */ |
15 |
| -// TypeScript Version: 2.3 |
16 |
| -import { |
17 |
| - parse, |
18 |
| - parseWithoutProcessing, |
19 |
| - ParseOptions, |
20 |
| - AST |
21 |
| -} from '@handlebars/parser'; |
22 |
| - |
23 |
| -declare namespace Handlebars { |
24 |
| - export interface TemplateDelegate<T = any> { |
25 |
| - (context: T, options?: RuntimeOptions): string; |
26 |
| - } |
27 |
| - |
28 |
| - export type Template<T = any> = TemplateDelegate<T>|string; |
29 |
| - |
30 |
| - export interface RuntimeOptions { |
31 |
| - partial?: boolean; |
32 |
| - depths?: any[]; |
33 |
| - helpers?: { [name: string]: Function }; |
34 |
| - partials?: { [name: string]: HandlebarsTemplateDelegate }; |
35 |
| - decorators?: { [name: string]: Function }; |
36 |
| - data?: any; |
37 |
| - blockParams?: any[]; |
38 |
| - allowCallsToHelperMissing?: boolean; |
39 |
| - allowedProtoProperties?: { [name: string]: boolean }; |
40 |
| - allowedProtoMethods?: { [name: string]: boolean }; |
41 |
| - allowProtoPropertiesByDefault?: boolean; |
42 |
| - allowProtoMethodsByDefault?: boolean; |
43 |
| - } |
44 |
| - |
45 |
| - export interface HelperOptions { |
46 |
| - fn: TemplateDelegate; |
47 |
| - inverse: TemplateDelegate; |
48 |
| - hash: any; |
49 |
| - data?: any; |
50 |
| - } |
51 |
| - |
52 |
| - export interface HelperDelegate { |
53 |
| - (context?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, options?: HelperOptions): any; |
54 |
| - } |
55 |
| - export interface HelperDeclareSpec { |
56 |
| - [key: string]: HelperDelegate; |
57 |
| - } |
58 |
| - |
59 |
| - export { parse, parseWithoutProcessing, ParseOptions }; |
60 |
| - |
61 |
| - export function registerHelper(name: string, fn: HelperDelegate): void; |
62 |
| - export function registerHelper(name: HelperDeclareSpec): void; |
63 |
| - export function unregisterHelper(name: string): void; |
64 |
| - |
65 |
| - export function registerPartial(name: string, fn: Template): void; |
66 |
| - export function registerPartial(spec: { [name: string]: HandlebarsTemplateDelegate }): void; |
67 |
| - export function unregisterPartial(name: string): void; |
68 |
| - |
69 |
| - // TODO: replace Function with actual signature |
70 |
| - export function registerDecorator(name: string, fn: Function): void; |
71 |
| - export function unregisterDecorator(name: string): void; |
72 |
| - |
73 |
| - export function K(): void; |
74 |
| - export function createFrame(object: any): any; |
75 |
| - export function blockParams(obj: any[], ids: any[]): any[]; |
76 |
| - export function log(level: number, obj: any): void; |
77 |
| - |
78 |
| - export function compile<T = any>(input: any, options?: CompileOptions): HandlebarsTemplateDelegate<T>; |
79 |
| - export function precompile(input: any, options?: PrecompileOptions): TemplateSpecification; |
80 |
| - export function template<T = any>(precompilation: TemplateSpecification): HandlebarsTemplateDelegate<T>; |
81 |
| - |
82 |
| - export function create(): typeof Handlebars; |
83 |
| - |
84 |
| - export const escapeExpression: typeof Utils.escapeExpression; |
85 |
| - //export const Utils: typeof hbs.Utils; |
86 |
| - export const logger: Logger; |
87 |
| - export const templates: HandlebarsTemplates; |
88 |
| - export const helpers: { [name: string]: HelperDelegate }; |
89 |
| - export const partials: { [name: string]: any }; |
90 |
| - // TODO: replace Function with actual signature |
91 |
| - export const decorators: { [name: string]: Function }; |
92 |
| - |
93 |
| - export const VERSION: string; |
94 |
| - |
95 |
| - export function noConflict(): typeof Handlebars; |
96 |
| - |
97 |
| - export class Exception { |
98 |
| - constructor(message: string, node?: hbs.AST.Node); |
99 |
| - description: string; |
100 |
| - fileName: string; |
101 |
| - lineNumber?: any; |
102 |
| - endLineNumber?: any; |
103 |
| - message: string; |
104 |
| - name: string; |
105 |
| - number: number; |
106 |
| - stack?: string; |
107 |
| - column?: any; |
108 |
| - endColumn?: any; |
109 |
| - } |
110 |
| - |
111 |
| - export class SafeString { |
112 |
| - constructor(str: string); |
113 |
| - toString(): string; |
114 |
| - toHTML(): string; |
115 |
| - } |
116 |
| - |
117 |
| - export namespace Utils { |
118 |
| - export function escapeExpression(str: string): string; |
119 |
| - export function createFrame(object: any): any; |
120 |
| - export function blockParams(obj: any[], ids: any[]): any[]; |
121 |
| - export function isEmpty(obj: any) : boolean; |
122 |
| - export function extend(obj: any, ...source: any[]): any; |
123 |
| - export function toString(obj: any): string; |
124 |
| - export function isArray(obj: any): boolean; |
125 |
| - export function isFunction(obj: any): boolean; |
126 |
| - } |
127 |
| - |
128 |
| - export namespace AST { |
129 |
| - export const helpers: hbs.AST.helpers; |
130 |
| - } |
131 |
| - |
132 |
| - export interface ICompiler { |
133 |
| - accept(node: hbs.AST.Node): void; |
134 |
| - Program(program: hbs.AST.Program): void; |
135 |
| - BlockStatement(block: hbs.AST.BlockStatement): void; |
136 |
| - PartialStatement(partial: hbs.AST.PartialStatement): void; |
137 |
| - PartialBlockStatement(partial: hbs.AST.PartialBlockStatement): void; |
138 |
| - DecoratorBlock(decorator: hbs.AST.DecoratorBlock): void; |
139 |
| - Decorator(decorator: hbs.AST.Decorator): void; |
140 |
| - MustacheStatement(mustache: hbs.AST.MustacheStatement): void; |
141 |
| - ContentStatement(content: hbs.AST.ContentStatement): void; |
142 |
| - CommentStatement(comment?: hbs.AST.CommentStatement): void; |
143 |
| - SubExpression(sexpr: hbs.AST.SubExpression): void; |
144 |
| - PathExpression(path: hbs.AST.PathExpression): void; |
145 |
| - StringLiteral(str: hbs.AST.StringLiteral): void; |
146 |
| - NumberLiteral(num: hbs.AST.NumberLiteral): void; |
147 |
| - BooleanLiteral(bool: hbs.AST.BooleanLiteral): void; |
148 |
| - UndefinedLiteral(): void; |
149 |
| - NullLiteral(): void; |
150 |
| - Hash(hash: hbs.AST.Hash): void; |
151 |
| - } |
152 |
| - |
153 |
| - export class Visitor implements ICompiler { |
154 |
| - accept(node: hbs.AST.Node): void; |
155 |
| - acceptKey(node: hbs.AST.Node, name: string): void; |
156 |
| - acceptArray(arr: hbs.AST.Expression[]): void; |
157 |
| - Program(program: hbs.AST.Program): void; |
158 |
| - BlockStatement(block: hbs.AST.BlockStatement): void; |
159 |
| - PartialStatement(partial: hbs.AST.PartialStatement): void; |
160 |
| - PartialBlockStatement(partial: hbs.AST.PartialBlockStatement): void; |
161 |
| - DecoratorBlock(decorator: hbs.AST.DecoratorBlock): void; |
162 |
| - Decorator(decorator: hbs.AST.Decorator): void; |
163 |
| - MustacheStatement(mustache: hbs.AST.MustacheStatement): void; |
164 |
| - ContentStatement(content: hbs.AST.ContentStatement): void; |
165 |
| - CommentStatement(comment?: hbs.AST.CommentStatement): void; |
166 |
| - SubExpression(sexpr: hbs.AST.SubExpression): void; |
167 |
| - PathExpression(path: hbs.AST.PathExpression): void; |
168 |
| - StringLiteral(str: hbs.AST.StringLiteral): void; |
169 |
| - NumberLiteral(num: hbs.AST.NumberLiteral): void; |
170 |
| - BooleanLiteral(bool: hbs.AST.BooleanLiteral): void; |
171 |
| - UndefinedLiteral(): void; |
172 |
| - NullLiteral(): void; |
173 |
| - Hash(hash: hbs.AST.Hash): void; |
174 |
| - } |
175 |
| - |
176 |
| - |
177 |
| - export interface ResolvePartialOptions { |
178 |
| - name: string; |
179 |
| - helpers?: { [name: string]: Function }; |
180 |
| - partials?: { [name: string]: HandlebarsTemplateDelegate }; |
181 |
| - decorators?: { [name: string]: Function }; |
182 |
| - data?: any; |
183 |
| - } |
184 |
| - |
185 |
| - export namespace VM { |
186 |
| - /** |
187 |
| - * @deprecated |
188 |
| - */ |
189 |
| - export function resolvePartial<T = any>(partial: HandlebarsTemplateDelegate<T> | undefined, context: any, options: ResolvePartialOptions): HandlebarsTemplateDelegate<T>; |
190 |
| - } |
| 1 | +import { ParseOptions, AST } from '@handlebars/parser'; |
| 2 | +declare type BuiltinHelperName = "helperMissing" | "blockHelperMissing" | "each" | "if" | "unless" | "with" | "log" | "lookup"; |
| 3 | +declare type KnownHelpers = { |
| 4 | + [name in BuiltinHelperName | string]: boolean; |
| 5 | +}; |
| 6 | +declare type Template<T = any> = TemplateDelegate<T> | string; |
| 7 | +interface CompileOptions { |
| 8 | + data?: boolean; |
| 9 | + compat?: boolean; |
| 10 | + knownHelpers?: KnownHelpers; |
| 11 | + knownHelpersOnly?: boolean; |
| 12 | + noEscape?: boolean; |
| 13 | + strict?: boolean; |
| 14 | + assumeObjects?: boolean; |
| 15 | + preventIndent?: boolean; |
| 16 | + ignoreStandalone?: boolean; |
| 17 | + explicitPartialContext?: boolean; |
| 18 | +} |
| 19 | +interface PrecompileOptions extends CompileOptions { |
| 20 | + srcName?: string; |
| 21 | + destName?: string; |
191 | 22 | }
|
192 |
| - |
193 |
| -/** |
194 |
| -* Implement this interface on your MVW/MVVM/MVC views such as Backbone.View |
195 |
| -**/ |
196 |
| -export interface HandlebarsTemplatable { |
197 |
| - template: HandlebarsTemplateDelegate; |
| 23 | +interface RuntimeOptions { |
| 24 | + partial?: boolean; |
| 25 | + depths?: any[]; |
| 26 | + helpers?: { |
| 27 | + [name: string]: Function; |
| 28 | + }; |
| 29 | + partials?: { |
| 30 | + [name: string]: TemplateDelegate; |
| 31 | + }; |
| 32 | + decorators?: { |
| 33 | + [name: string]: Function; |
| 34 | + }; |
| 35 | + data?: any; |
| 36 | + blockParams?: any[]; |
| 37 | + allowCallsToHelperMissing?: boolean; |
| 38 | + allowedProtoProperties?: { |
| 39 | + [name: string]: boolean; |
| 40 | + }; |
| 41 | + allowedProtoMethods?: { |
| 42 | + [name: string]: boolean; |
| 43 | + }; |
| 44 | + allowProtoPropertiesByDefault?: boolean; |
| 45 | + allowProtoMethodsByDefault?: boolean; |
198 | 46 | }
|
199 |
| - |
200 |
| -// NOTE: for backward compatibility of this typing |
201 |
| -export type HandlebarsTemplateDelegate<T = any> = Handlebars.TemplateDelegate<T>; |
202 |
| - |
203 |
| -export interface HandlebarsTemplates { |
204 |
| - [index: string]: HandlebarsTemplateDelegate; |
| 47 | +interface TemplateSpecification { |
205 | 48 | }
|
206 |
| - |
207 |
| -export interface TemplateSpecification { |
208 |
| - |
| 49 | +export interface TemplateDelegate<T = any> { |
| 50 | + (context: T, options?: RuntimeOptions): string; |
209 | 51 | }
|
210 |
| - |
211 |
| -// for backward compatibility of this typing |
212 |
| -export type RuntimeOptions = Handlebars.RuntimeOptions; |
213 |
| - |
214 |
| -export interface CompileOptions { |
215 |
| - data?: boolean; |
216 |
| - compat?: boolean; |
217 |
| - knownHelpers?: KnownHelpers; |
218 |
| - knownHelpersOnly?: boolean; |
219 |
| - noEscape?: boolean; |
220 |
| - strict?: boolean; |
221 |
| - assumeObjects?: boolean; |
222 |
| - preventIndent?: boolean; |
223 |
| - ignoreStandalone?: boolean; |
224 |
| - explicitPartialContext?: boolean; |
| 52 | +interface HelperOptions { |
| 53 | + fn: TemplateDelegate; |
| 54 | + inverse: TemplateDelegate; |
| 55 | + hash: any; |
| 56 | + data?: any; |
225 | 57 | }
|
226 |
| - |
227 |
| -export type KnownHelpers = { |
228 |
| - [name in BuiltinHelperName | CustomHelperName]: boolean; |
229 |
| -}; |
230 |
| - |
231 |
| -export type BuiltinHelperName = |
232 |
| - "helperMissing"| |
233 |
| - "blockHelperMissing"| |
234 |
| - "each"| |
235 |
| - "if"| |
236 |
| - "unless"| |
237 |
| - "with"| |
238 |
| - "log"| |
239 |
| - "lookup"; |
240 |
| - |
241 |
| -export type CustomHelperName = string; |
242 |
| - |
243 |
| -export interface PrecompileOptions extends CompileOptions { |
244 |
| - srcName?: string; |
245 |
| - destName?: string; |
| 58 | +interface HelperDelegate { |
| 59 | + (context?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, options?: HelperOptions): any; |
246 | 60 | }
|
247 |
| - |
248 |
| -export namespace hbs { |
249 |
| - // for backward compatibility of this typing |
250 |
| - export type SafeString = Handlebars.SafeString; |
251 |
| - |
252 |
| - export type Utils = typeof Handlebars.Utils; |
253 |
| - |
254 |
| - export { AST } |
| 61 | +interface HelperDeclareSpec { |
| 62 | + [key: string]: HelperDelegate; |
255 | 63 | }
|
256 |
| - |
257 |
| -export interface Logger { |
258 |
| - DEBUG: number; |
259 |
| - INFO: number; |
260 |
| - WARN: number; |
261 |
| - ERROR: number; |
262 |
| - level: number; |
263 |
| - |
264 |
| - methodMap: { [level: number]: string }; |
265 |
| - |
266 |
| - log(level: number, obj: string): void; |
| 64 | +interface SafeString { |
| 65 | + new (str: string): void; |
| 66 | + toString(): string; |
| 67 | + toHTML(): string; |
267 | 68 | }
|
268 |
| - |
269 |
| -export type CompilerInfo = [number/* revision */, string /* versions */]; |
270 |
| - |
271 |
| -declare module "handlebars/runtime" { |
272 |
| - export = Handlebars; |
| 69 | +declare class Handlebars { |
| 70 | + readonly VERSION: string; |
| 71 | + SafeString: SafeString; |
| 72 | + constructor(); |
| 73 | + compile<T = any>(input: any, options?: CompileOptions): TemplateDelegate; |
| 74 | + precompile(input: any, options?: PrecompileOptions): TemplateSpecification; |
| 75 | + parse(input: string, options?: ParseOptions): AST.Program; |
| 76 | + parseWithoutProcessing(input: string, options?: ParseOptions): AST.Program; |
| 77 | + registerHelper(name: HelperDeclareSpec | string, fn?: HelperDelegate): void; |
| 78 | + unregisterHelper(name: string): void; |
| 79 | + registerPartial(name: string, fn: Template): void; |
| 80 | + registerPartial(spec: { |
| 81 | + [name: string]: TemplateDelegate; |
| 82 | + }): void; |
| 83 | + unregisterPartial(name: string): void; |
273 | 84 | }
|
274 |
| - |
275 |
| -export default Handlebars; |
| 85 | +declare const _default: Handlebars; |
| 86 | +export default _default; |
0 commit comments