-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtemplate.d.ts
89 lines (89 loc) · 2.72 KB
/
template.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Position } from 'source-map';
export interface TemplateOptions {
sourceURL?: string;
sourceMap?: boolean;
module?: boolean | {
exports: {};
};
sourceRoot?: string;
fileName?: string;
}
/**
* A simple AST for templates. There's only one level of AST nodes, but it's still useful
* to have the information you're looking for.
*/
export interface TemplateAst {
fileName: string;
content: string;
children: TemplateAstNode[];
}
/**
* The base, which contains positions.
*/
export interface TemplateAstBase {
start: Position;
end: Position;
}
/**
* A static content node.
*/
export interface TemplateAstContent extends TemplateAstBase {
kind: 'content';
content: string;
}
/**
* A comment node.
*/
export interface TemplateAstComment extends TemplateAstBase {
kind: 'comment';
text: string;
}
/**
* An evaluate node, which is the code between `<% ... %>`.
*/
export interface TemplateAstEvaluate extends TemplateAstBase {
kind: 'evaluate';
expression: string;
}
/**
* An escape node, which is the code between `<%- ... %>`.
*/
export interface TemplateAstEscape extends TemplateAstBase {
kind: 'escape';
expression: string;
}
/**
* An interpolation node, which is the code between `<%= ... %>`.
*/
export interface TemplateAstInterpolate extends TemplateAstBase {
kind: 'interpolate';
expression: string;
}
export type TemplateAstNode = TemplateAstContent | TemplateAstEvaluate | TemplateAstComment | TemplateAstEscape | TemplateAstInterpolate;
/**
* Given a source text (and a fileName), returns a TemplateAst.
*/
export declare function templateParser(sourceText: string, fileName: string): TemplateAst;
/**
* An equivalent of EJS templates, which is based on John Resig's `tmpl` implementation
* (http://ejohn.org/blog/javascript-micro-templating/) and Laura Doktorova's doT.js
* (https://github.com/olado/doT).
*
* This version differs from lodash by removing support from ES6 quasi-literals, and making the
* code slightly simpler to follow. It also does not depend on any third party, which is nice.
*
* Finally, it supports SourceMap, if you ever need to debug, which is super nice.
*
* @param content The template content.
* @param options Optional Options. See TemplateOptions for more description.
* @return {(input: T) => string} A function that accept an input object and returns the content
* of the template with the input applied.
*/
export declare function template<T>(content: string, options?: TemplateOptions): (input: T) => string;