UNPKG

6.08 kBTypeScriptView Raw
1// API Documentation : http://paularmstrong.github.io/swig/docs/api/
2
3export declare class Swig {
4 constructor(options?: SwigOptions);
5
6 setFilter(
7 name: string,
8 method: (input: any, ...args: any[]) => string,
9 ): void;
10 setTag(
11 name: string,
12 parse: (
13 str?: string,
14 line?: string,
15 parser?: Object,
16 types?: lexer.TYPES,
17 stack?: any,
18 opts?: Object,
19 swig?: Swig,
20 ) => boolean,
21 compile: (
22 compiler?: (content?: string, parents?: any, options?: any, blockName?: string) => string,
23 args?: any[],
24 content?: string,
25 parents?: any,
26 options?: any,
27 blockName?: string,
28 ) => string,
29 ends?: boolean,
30 blockLevel?: boolean,
31 ): void;
32 setExtension(name: string, object: any): void;
33 parseFile(pathName: string, options?: any): parser.ParseReturn;
34 precompile(source: string, options?: SwigOptions): any;
35 compile(source: string, options?: SwigOptions): (locals?: any) => string;
36 compileFile(
37 pathname: string,
38 options: SwigOptions,
39 cb: (err: Error, compiledRender: (locals?: any) => string) => void,
40 ): void;
41 compileFile(pathname: string, options?: SwigOptions): (locals?: any) => string;
42 render(source: string, options?: SwigOptions): string;
43 renderFile(pathName: string, locals: any, cb: (err: Error, output: string) => void): void;
44 renderFile(pathName: string, locals?: any): string;
45 run(templateFn: Function, locals?: any, filePath?: string): string;
46 invalidateCache(): void;
47
48 loaders: typeof loaders;
49}
50
51export declare namespace lexer {
52 export enum TYPES {
53 /** Whitespace */
54 WHITESPACE = 0,
55 /** Plain string */
56 STRING = 1,
57 /** Variable filter */
58 FILTER = 2,
59 /** Empty variable filter */
60 FILTEREMPTY = 3,
61 /** Function */
62 FUNCTION = 4,
63 /** Function with no arguments */
64 FUNCTIONEMPTY = 5,
65 /** Open parenthesis */
66 PARENOPEN = 6,
67 /** Close parenthesis */
68 PARENCLOSE = 7,
69 /** Comma */
70 COMMA = 8,
71 /** Variable */
72 VAR = 9,
73 /** Number */
74 NUMBER = 10,
75 /** Math operator */
76 OPERATOR = 11,
77 /** Open square bracket */
78 BRACKETOPEN = 12,
79 /** Close square bracket */
80 BRACKETCLOSE = 13,
81 /** Key on an object using dot-notation */
82 DOTKEY = 14,
83 /** Start of an array */
84 ARRAYOPEN = 15,
85 /** End of an array
86 * Currently unused
87 ARRAYCLOSE = 16, */
88 /** Open curly brace */
89 CURLYOPEN = 17,
90 /** Close curly brace */
91 CURLYCLOSE = 18,
92 /** Colon (:) */
93 COLON = 19,
94 /** JavaScript-valid comparator */
95 COMPARATOR = 20,
96 /** Boolean logic */
97 LOGIC = 21,
98 /** Boolean logic "not" */
99 NOT = 22,
100 /** true or false */
101 BOOL = 23,
102 /** Variable assignment */
103 ASSIGNMENT = 24,
104 /** Start of a method */
105 METHODOPEN = 25,
106 /** End of a method
107 * Currently unused
108 METHODEND = 26, */
109 /** Unknown type */
110 UNKNOWN = 100,
111 }
112
113 export function read(str: string): string[];
114}
115
116export declare namespace parser {
117 interface ParseReturn {
118 name: string;
119 parent: any;
120 tokens: any[];
121 blocks: any;
122 }
123}
124
125export interface SwigOptions {
126 autoescape?: boolean | undefined;
127 cache?: any;
128 cmtControls?: string[] | undefined;
129 loader?: TemplateLoader | undefined;
130 locals?: any;
131 tagControls?: string[] | undefined;
132 varControls?: string[] | undefined;
133}
134
135export interface TemplateLoader {
136 resolve(to: string, from: string): string;
137 load(identifier: string, callback?: (err: Error, data: any) => void): void;
138 load(identifier: string): any;
139}
140
141export declare namespace loaders {
142 export function fs(basepath?: string, encoding?: string): TemplateLoader;
143 export function memory(mapping: any, basepath?: string): TemplateLoader;
144}
145
146export declare var version: string;
147export declare function setDefaults(options: SwigOptions): void;
148export declare function setDefaultTZOffset(offset: number): void;
149export declare function setFilter(
150 name: string,
151 method: (input: any, ...args: any[]) => string,
152): void;
153export declare function setTag(
154 name: string,
155 parse: (
156 str?: string,
157 line?: string,
158 parser?: Object,
159 types?: lexer.TYPES,
160 stack?: any,
161 opts?: Object,
162 swig?: Swig,
163 ) => boolean,
164 compile: (
165 compiler?: (content?: string, parents?: any, options?: any, blockName?: string) => string,
166 args?: any[],
167 content?: string,
168 parents?: any,
169 options?: any,
170 blockName?: string,
171 ) => string,
172 ends?: boolean,
173 blockLevel?: boolean,
174): void;
175export declare function setExtension(name: string, object: any): void;
176export declare function parseFile(pathName: string, options?: any): parser.ParseReturn;
177export declare function precompile(source: string, options?: SwigOptions): any;
178export declare function compile(source: string, options?: SwigOptions): (locals?: any) => string;
179export declare function compileFile(
180 pathname: string,
181 options: SwigOptions,
182 cb: (err: Error, compiledRender: (locals?: any) => string) => void,
183): void;
184export declare function compileFile(pathname: string, options?: SwigOptions): (locals?: any) => string;
185export declare function render(source: string, options?: SwigOptions): string;
186export declare function renderFile(pathName: string, locals: any, cb: (err: Error, output: string) => void): void;
187export declare function renderFile(pathName: string, locals?: any): string;
188export declare function run(templateFn: Function, locals?: any, filePath?: string): string;
189export declare function invalidateCache(): void;