janja 2.4.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -40
- package/dist/index.cjs +5536 -0
- package/dist/index.d.ts +705 -20
- package/dist/index.esm.js +4032 -1481
- package/dist/index.js +4085 -1490
- package/dist/index.min.js +1 -0
- package/package.json +52 -33
- package/dist/index.cjs.js +0 -2941
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
declare class LRUCache<T> {
|
|
2
|
+
private cache;
|
|
3
|
+
private maxSize;
|
|
4
|
+
private ttl;
|
|
5
|
+
private stats;
|
|
6
|
+
constructor(options?: CacheOptions);
|
|
7
|
+
get(key: string): T | null;
|
|
8
|
+
/**
|
|
9
|
+
* Look at an entry without counting it as a hit or changing its position.
|
|
10
|
+
*/
|
|
11
|
+
peek(key: string): T | null;
|
|
12
|
+
set(key: string, value: T): void;
|
|
13
|
+
has(key: string): boolean;
|
|
14
|
+
delete(key: string): boolean;
|
|
15
|
+
clear(): void;
|
|
16
|
+
invalidate(predicate?: (key: string) => boolean): void;
|
|
17
|
+
getStats(): {
|
|
18
|
+
size: number;
|
|
19
|
+
hitRate: number;
|
|
20
|
+
hits: number;
|
|
21
|
+
misses: number;
|
|
22
|
+
evictions: number;
|
|
23
|
+
};
|
|
24
|
+
resetStats(): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
1
27
|
interface Mapping {
|
|
2
28
|
source: Loc;
|
|
3
29
|
target: Loc;
|
|
@@ -42,12 +68,23 @@ declare class SourceMap {
|
|
|
42
68
|
}
|
|
43
69
|
|
|
44
70
|
declare class OutScript extends SourceMap {
|
|
45
|
-
|
|
71
|
+
private codeParts;
|
|
72
|
+
private codeLength;
|
|
73
|
+
get code(): string;
|
|
74
|
+
set code(value: string);
|
|
46
75
|
get script(): Script;
|
|
47
|
-
|
|
76
|
+
checkpoint(): unknown;
|
|
77
|
+
rollback(checkpoint: unknown): void;
|
|
78
|
+
start(root?: boolean): void;
|
|
48
79
|
end(): void;
|
|
49
80
|
pushRaw(loc: Loc | null, ...lines: string[]): void;
|
|
50
81
|
pushStr(loc: Loc | null, s: string): Pos | void;
|
|
82
|
+
/**
|
|
83
|
+
* In stream mode, hand the output collected so far to the writer once
|
|
84
|
+
* there is enough of it. Only valid where `s` is the template's own output,
|
|
85
|
+
* i.e. not inside captures, macros, blocks or partials.
|
|
86
|
+
*/
|
|
87
|
+
pushFlush(): void;
|
|
51
88
|
pushVar(loc: Loc | null, v: string): void;
|
|
52
89
|
}
|
|
53
90
|
|
|
@@ -55,6 +92,8 @@ declare class Context extends OutScript {
|
|
|
55
92
|
context: string;
|
|
56
93
|
private stack;
|
|
57
94
|
private index;
|
|
95
|
+
checkpoint(): unknown;
|
|
96
|
+
rollback(checkpoint: unknown): void;
|
|
58
97
|
in(): string;
|
|
59
98
|
out(): void;
|
|
60
99
|
}
|
|
@@ -100,6 +139,8 @@ interface SyntaxNode {
|
|
|
100
139
|
type: string;
|
|
101
140
|
loc: Loc;
|
|
102
141
|
body?: SyntaxNode[];
|
|
142
|
+
val?: Exp | string;
|
|
143
|
+
strip?: Strip;
|
|
103
144
|
traverse: (cb: (node: SyntaxNode) => void) => void;
|
|
104
145
|
}
|
|
105
146
|
declare class Traversal implements SyntaxNode {
|
|
@@ -124,16 +165,40 @@ declare class BlockNode extends Traversal {
|
|
|
124
165
|
constructor(val: IdExp, body: SyntaxNode[], loc: Loc, strip: Strip);
|
|
125
166
|
}
|
|
126
167
|
|
|
168
|
+
interface CompiledTemplate {
|
|
169
|
+
code: string;
|
|
170
|
+
mappings: Mapping[];
|
|
171
|
+
script?: Script;
|
|
172
|
+
sources: Map<string, string>;
|
|
173
|
+
fingerprint: string;
|
|
174
|
+
}
|
|
175
|
+
declare const MAX_INCLUDE_DEPTH = 100;
|
|
176
|
+
declare function templateCacheKey(template: string, stream?: boolean): string;
|
|
177
|
+
declare function optionsFingerprint(options: Required<CompilerOptions>): string;
|
|
127
178
|
declare class Compiler extends Context {
|
|
128
179
|
options: Required<CompilerOptions>;
|
|
180
|
+
private revalidate;
|
|
181
|
+
private stream;
|
|
129
182
|
template: string;
|
|
130
183
|
state: Record<string, any>;
|
|
131
184
|
private isRoot;
|
|
132
185
|
private rootNode;
|
|
133
186
|
private partials;
|
|
134
187
|
private blocks;
|
|
135
|
-
|
|
136
|
-
|
|
188
|
+
private sources;
|
|
189
|
+
private cache?;
|
|
190
|
+
private compiled?;
|
|
191
|
+
/**
|
|
192
|
+
* Whether the code being generated may write output to the stream. True
|
|
193
|
+
* only in stream mode, for the template's own top-level output.
|
|
194
|
+
*/
|
|
195
|
+
flushable: boolean;
|
|
196
|
+
constructor(options: Required<CompilerOptions>, cache?: LRUCache<CompiledTemplate>, revalidate?: boolean, stream?: boolean);
|
|
197
|
+
compile(template: string, root?: boolean, partials?: Map<string, string>, blocks?: Map<string, BlockNode[]>, sources?: Map<string, string>): Promise<this>;
|
|
198
|
+
get script(): Script;
|
|
199
|
+
private generateCacheKey;
|
|
200
|
+
private fingerprint;
|
|
201
|
+
private isFresh;
|
|
137
202
|
private parseTemplates;
|
|
138
203
|
private collectPartialsAndBlocks;
|
|
139
204
|
private compileNode;
|
|
@@ -148,9 +213,10 @@ declare class Tokenizer implements Pos {
|
|
|
148
213
|
protected index: number;
|
|
149
214
|
protected tokens: Token[];
|
|
150
215
|
private tokenPatterns;
|
|
216
|
+
private markerIndices;
|
|
151
217
|
line: number;
|
|
152
218
|
column: number;
|
|
153
|
-
constructor(options
|
|
219
|
+
constructor(options: Required<ParserOptions>);
|
|
154
220
|
tokenize(template: string): Token[];
|
|
155
221
|
private consumeSpecialTokens;
|
|
156
222
|
private consumeTextToken;
|
|
@@ -161,8 +227,8 @@ declare class Tokenizer implements Pos {
|
|
|
161
227
|
declare class Parser extends Tokenizer {
|
|
162
228
|
private expParser;
|
|
163
229
|
protected cursor: number;
|
|
164
|
-
parse(template: string):
|
|
165
|
-
parseUntil(names?: string[]):
|
|
230
|
+
parse(template: string): RootNode;
|
|
231
|
+
parseUntil(names?: string[]): SyntaxNode[];
|
|
166
232
|
parseExp<T extends Exp = Exp>({ val, loc }: DirectiveExpression): T | undefined;
|
|
167
233
|
peek(): Token | null;
|
|
168
234
|
private advance;
|
|
@@ -170,6 +236,24 @@ declare class Parser extends Tokenizer {
|
|
|
170
236
|
emitExpErr({ name, loc }: DirectiveToken, required?: boolean): void;
|
|
171
237
|
}
|
|
172
238
|
|
|
239
|
+
interface SecurityOptions {
|
|
240
|
+
sandbox?: boolean;
|
|
241
|
+
allowedGlobals?: string[];
|
|
242
|
+
deepEscape?: boolean;
|
|
243
|
+
cspNonce?: string;
|
|
244
|
+
cspHeaders?: Record<string, string>;
|
|
245
|
+
}
|
|
246
|
+
interface SecurityAuditResult {
|
|
247
|
+
issues: SecurityIssue[];
|
|
248
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
249
|
+
}
|
|
250
|
+
interface SecurityIssue {
|
|
251
|
+
type: string;
|
|
252
|
+
message: string;
|
|
253
|
+
location?: string;
|
|
254
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
255
|
+
}
|
|
256
|
+
|
|
173
257
|
type MaybePromise<T> = T | Promise<T>;
|
|
174
258
|
type ObjectType<T = any> = Record<string, T>;
|
|
175
259
|
type Primitive = string | number | boolean | null | undefined;
|
|
@@ -218,18 +302,28 @@ interface DirectiveExpression {
|
|
|
218
302
|
loc: Loc;
|
|
219
303
|
}
|
|
220
304
|
type Token = CommentToken | DirectiveToken | OutputToken | TextToken;
|
|
221
|
-
|
|
222
|
-
|
|
305
|
+
/**
|
|
306
|
+
* A filter receives the piped value followed by the arguments written in the
|
|
307
|
+
* template. `this` is the context the expression is evaluated in. It may
|
|
308
|
+
* return a promise.
|
|
309
|
+
*/
|
|
310
|
+
type Filter<Value = any, Args extends any[] = any[], Result = unknown> = (this: ObjectType, value: Value, ...args: Args) => Result;
|
|
311
|
+
type Filters = Record<string, Filter>;
|
|
312
|
+
type Script = (globals: ObjectType, escape: (v: any) => any, filters: Filters,
|
|
313
|
+
/** Receives chunks of output when the template was compiled for streaming */
|
|
314
|
+
write?: (chunk: string) => void | Promise<void>) => Promise<string>;
|
|
223
315
|
interface Plugin {
|
|
224
316
|
filters?: Filters;
|
|
225
317
|
parsers?: ParserMap;
|
|
226
318
|
compilers?: CompilerMap;
|
|
319
|
+
formatters?: FormatterMap;
|
|
227
320
|
}
|
|
228
|
-
type ParserFn<T extends Token = any, U extends SyntaxNode = any> = (token: T, parser: Parser) =>
|
|
321
|
+
type ParserFn<T extends Token = any, U extends SyntaxNode = any> = (token: T, parser: Parser) => Generator<U | 'NEXT' | void>;
|
|
229
322
|
type ParserMap = Record<string, string | ParserFn>;
|
|
230
323
|
type CompilerFn<T extends SyntaxNode = any> = (node: T, compiler: Compiler) => MaybePromise<void>;
|
|
231
324
|
type CompilerMap = Record<string, string | CompilerFn>;
|
|
232
|
-
|
|
325
|
+
type FormatterFn<T extends SyntaxNode = any> = (node: T) => string;
|
|
326
|
+
type FormatterMap = Record<string, string | FormatterFn>;
|
|
233
327
|
interface BaseOptions {
|
|
234
328
|
debug?: (error: Error) => any;
|
|
235
329
|
filters?: Filters;
|
|
@@ -250,34 +344,296 @@ interface CompilerOptions extends ParserOptions {
|
|
|
250
344
|
stripComments?: boolean;
|
|
251
345
|
loader?: (path: string) => Promise<string>;
|
|
252
346
|
}
|
|
347
|
+
interface FormatterOptions extends ParserOptions {
|
|
348
|
+
trimWhitespace?: boolean;
|
|
349
|
+
stripComments?: boolean;
|
|
350
|
+
}
|
|
351
|
+
interface CacheOptions {
|
|
352
|
+
enabled?: boolean;
|
|
353
|
+
maxSize?: number;
|
|
354
|
+
ttl?: number;
|
|
355
|
+
/**
|
|
356
|
+
* Re-read included templates through the loader on every cache hit and
|
|
357
|
+
* recompile when one of them changed. Disable when templates are immutable
|
|
358
|
+
* at runtime to skip those loader calls.
|
|
359
|
+
* @default true
|
|
360
|
+
*/
|
|
361
|
+
revalidate?: boolean;
|
|
362
|
+
}
|
|
253
363
|
interface RendererOptions extends CompilerOptions {
|
|
254
364
|
globals?: ObjectType;
|
|
255
365
|
autoEscape?: boolean;
|
|
366
|
+
cache?: CacheOptions;
|
|
367
|
+
security?: SecurityOptions;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Define filters with their value and argument types checked, e.g.
|
|
371
|
+
* `defineFilters({ shout: (value: string, times = 1) => ... })`.
|
|
372
|
+
*/
|
|
373
|
+
declare function defineFilters<T extends Filters>(filters: T): T;
|
|
374
|
+
/**
|
|
375
|
+
* Define a plugin (filters, parsers and compilers) with its shape checked.
|
|
376
|
+
*/
|
|
377
|
+
declare function definePlugin<T extends Plugin>(plugin: T): T;
|
|
378
|
+
|
|
379
|
+
declare class Safe extends String {
|
|
380
|
+
constructor(value: unknown);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
declare function escape(v: unknown): string;
|
|
384
|
+
|
|
385
|
+
declare function abs(this: ObjectType, value?: number): number;
|
|
386
|
+
declare function add(this: ObjectType, value?: number, addend?: number): number;
|
|
387
|
+
declare function capitalize(this: ObjectType, value?: string): string;
|
|
388
|
+
declare function ceil(this: ObjectType, value?: number): number;
|
|
389
|
+
declare function compact(this: ObjectType, value?: unknown[]): {}[];
|
|
390
|
+
declare function div(this: ObjectType, value?: number, divisor?: number): number;
|
|
391
|
+
declare function entries(this: ObjectType, value?: ObjectType): [string, any][];
|
|
392
|
+
declare function even(this: ObjectType, value?: number | string): boolean;
|
|
393
|
+
declare function fallback(this: ObjectType, value: any, defaultValue: any, anyFalsy?: boolean): any;
|
|
394
|
+
declare function first(this: ObjectType, value?: string | any[]): any;
|
|
395
|
+
declare function get(this: ObjectType, value: ObjectType, ...path: string[]): ObjectType;
|
|
396
|
+
declare function groupby(this: ObjectType, value: ObjectType[] | undefined, key: string): Record<string, ObjectType[]>;
|
|
397
|
+
declare function join(this: ObjectType, value?: string | string[], separator?: string): string;
|
|
398
|
+
declare function json(this: ObjectType, value?: unknown, indent?: number): Safe;
|
|
399
|
+
declare function keys(this: ObjectType, value?: ObjectType): string[];
|
|
400
|
+
declare function last(this: ObjectType, value?: string | unknown[]): unknown;
|
|
401
|
+
declare function length(this: ObjectType, value?: string): number;
|
|
402
|
+
declare function lower(this: ObjectType, value?: string): string;
|
|
403
|
+
declare function map(this: ObjectType, value: ObjectType[] | undefined, key: string, defaultValue?: unknown): any[];
|
|
404
|
+
declare function max(this: ObjectType, value?: number, ...rest: number[]): number;
|
|
405
|
+
declare function min(this: ObjectType, value?: number, ...rest: number[]): number;
|
|
406
|
+
declare function mul(this: ObjectType, value?: number, multiplier?: number): number;
|
|
407
|
+
declare function odd(this: ObjectType, value?: number | string): boolean;
|
|
408
|
+
declare function omit(this: ObjectType, value?: ObjectType, ...omitKeys: string[]): {};
|
|
409
|
+
declare function pick(this: ObjectType, value?: ObjectType, ...pickKeys: string[]): {};
|
|
410
|
+
declare function repeat(this: ObjectType, value?: string, count?: number): string;
|
|
411
|
+
declare function replace(this: ObjectType, value: string | undefined, search: string, replacement: string): string;
|
|
412
|
+
declare function reverse(this: ObjectType, value?: string | unknown[]): string | unknown[];
|
|
413
|
+
declare function safe(this: ObjectType, value?: string): Safe;
|
|
414
|
+
declare function slice(this: ObjectType, value?: string, start?: number, end?: number): string;
|
|
415
|
+
declare function sort(this: ObjectType, value?: string | unknown[]): string | unknown[];
|
|
416
|
+
declare function split(this: ObjectType, value?: string, separator?: string): string[];
|
|
417
|
+
declare function sub(this: ObjectType, value?: number, subtrahend?: number): number;
|
|
418
|
+
declare function sum(this: ObjectType, value?: number[]): number;
|
|
419
|
+
declare function trim(this: ObjectType, value?: string): string;
|
|
420
|
+
declare function truncate(this: ObjectType, value?: string, maxLength?: number, truncateStr?: string): string;
|
|
421
|
+
declare function unique(this: ObjectType, value?: string | unknown[]): string | unknown[];
|
|
422
|
+
declare function upper(this: ObjectType, value?: string): string;
|
|
423
|
+
declare function urldecode(this: ObjectType, value?: string): string;
|
|
424
|
+
declare function urlencode(this: ObjectType, value?: string): string;
|
|
425
|
+
declare function values(this: ObjectType, value?: ObjectType): any[];
|
|
426
|
+
declare function date(this: ObjectType, value: Date | string, format?: string): string;
|
|
427
|
+
declare function timeAgo(this: ObjectType, value: Date | string): string;
|
|
428
|
+
declare function round(this: ObjectType, value: number, decimals?: number): number;
|
|
429
|
+
declare function fixed(this: ObjectType, value: number, decimals?: number): string;
|
|
430
|
+
declare function percent(this: ObjectType, value: number, decimals?: number): string;
|
|
431
|
+
declare function currency(this: ObjectType, value: number, currencyCode?: string, locale?: string): string;
|
|
432
|
+
declare function wordCount(this: ObjectType, value: string): number;
|
|
433
|
+
declare function stripTags(this: ObjectType, value: string): string;
|
|
434
|
+
declare function slugify(this: ObjectType, value: string): string;
|
|
435
|
+
declare function shuffle(this: ObjectType, value: unknown[]): unknown[];
|
|
436
|
+
declare function chunk(this: ObjectType, value: unknown[], size: number): unknown[][];
|
|
437
|
+
declare function pluck(this: ObjectType, value: ObjectType[], key: string): any[];
|
|
438
|
+
declare function defaults(this: ObjectType, value: ObjectType, defaultValues: ObjectType): {
|
|
439
|
+
[x: string]: any;
|
|
440
|
+
};
|
|
441
|
+
declare function invert(this: ObjectType, value: ObjectType): {};
|
|
442
|
+
declare function merge(this: ObjectType, value: ObjectType, ...objects: ObjectType[]): any;
|
|
443
|
+
declare function fetchUrl(this: ObjectType, url: string, options?: RequestInit): Promise<string>;
|
|
444
|
+
declare function delay(this: ObjectType, value: unknown, ms: number): Promise<unknown>;
|
|
445
|
+
|
|
446
|
+
declare const filters_abs: typeof abs;
|
|
447
|
+
declare const filters_add: typeof add;
|
|
448
|
+
declare const filters_capitalize: typeof capitalize;
|
|
449
|
+
declare const filters_ceil: typeof ceil;
|
|
450
|
+
declare const filters_chunk: typeof chunk;
|
|
451
|
+
declare const filters_compact: typeof compact;
|
|
452
|
+
declare const filters_currency: typeof currency;
|
|
453
|
+
declare const filters_date: typeof date;
|
|
454
|
+
declare const filters_defaults: typeof defaults;
|
|
455
|
+
declare const filters_delay: typeof delay;
|
|
456
|
+
declare const filters_div: typeof div;
|
|
457
|
+
declare const filters_entries: typeof entries;
|
|
458
|
+
declare const filters_escape: typeof escape;
|
|
459
|
+
declare const filters_even: typeof even;
|
|
460
|
+
declare const filters_fallback: typeof fallback;
|
|
461
|
+
declare const filters_fetchUrl: typeof fetchUrl;
|
|
462
|
+
declare const filters_first: typeof first;
|
|
463
|
+
declare const filters_fixed: typeof fixed;
|
|
464
|
+
declare const filters_get: typeof get;
|
|
465
|
+
declare const filters_groupby: typeof groupby;
|
|
466
|
+
declare const filters_invert: typeof invert;
|
|
467
|
+
declare const filters_join: typeof join;
|
|
468
|
+
declare const filters_json: typeof json;
|
|
469
|
+
declare const filters_keys: typeof keys;
|
|
470
|
+
declare const filters_last: typeof last;
|
|
471
|
+
declare const filters_length: typeof length;
|
|
472
|
+
declare const filters_lower: typeof lower;
|
|
473
|
+
declare const filters_map: typeof map;
|
|
474
|
+
declare const filters_max: typeof max;
|
|
475
|
+
declare const filters_merge: typeof merge;
|
|
476
|
+
declare const filters_min: typeof min;
|
|
477
|
+
declare const filters_mul: typeof mul;
|
|
478
|
+
declare const filters_odd: typeof odd;
|
|
479
|
+
declare const filters_omit: typeof omit;
|
|
480
|
+
declare const filters_percent: typeof percent;
|
|
481
|
+
declare const filters_pick: typeof pick;
|
|
482
|
+
declare const filters_pluck: typeof pluck;
|
|
483
|
+
declare const filters_repeat: typeof repeat;
|
|
484
|
+
declare const filters_replace: typeof replace;
|
|
485
|
+
declare const filters_reverse: typeof reverse;
|
|
486
|
+
declare const filters_round: typeof round;
|
|
487
|
+
declare const filters_safe: typeof safe;
|
|
488
|
+
declare const filters_shuffle: typeof shuffle;
|
|
489
|
+
declare const filters_slice: typeof slice;
|
|
490
|
+
declare const filters_slugify: typeof slugify;
|
|
491
|
+
declare const filters_sort: typeof sort;
|
|
492
|
+
declare const filters_split: typeof split;
|
|
493
|
+
declare const filters_stripTags: typeof stripTags;
|
|
494
|
+
declare const filters_sub: typeof sub;
|
|
495
|
+
declare const filters_sum: typeof sum;
|
|
496
|
+
declare const filters_timeAgo: typeof timeAgo;
|
|
497
|
+
declare const filters_trim: typeof trim;
|
|
498
|
+
declare const filters_truncate: typeof truncate;
|
|
499
|
+
declare const filters_unique: typeof unique;
|
|
500
|
+
declare const filters_upper: typeof upper;
|
|
501
|
+
declare const filters_urldecode: typeof urldecode;
|
|
502
|
+
declare const filters_urlencode: typeof urlencode;
|
|
503
|
+
declare const filters_values: typeof values;
|
|
504
|
+
declare const filters_wordCount: typeof wordCount;
|
|
505
|
+
declare namespace filters {
|
|
506
|
+
export {
|
|
507
|
+
filters_abs as abs,
|
|
508
|
+
filters_add as add,
|
|
509
|
+
filters_capitalize as capitalize,
|
|
510
|
+
filters_ceil as ceil,
|
|
511
|
+
filters_chunk as chunk,
|
|
512
|
+
filters_compact as compact,
|
|
513
|
+
filters_currency as currency,
|
|
514
|
+
filters_date as date,
|
|
515
|
+
filters_defaults as defaults,
|
|
516
|
+
filters_delay as delay,
|
|
517
|
+
filters_div as div,
|
|
518
|
+
filters_entries as entries,
|
|
519
|
+
filters_escape as escape,
|
|
520
|
+
filters_even as even,
|
|
521
|
+
filters_fallback as fallback,
|
|
522
|
+
filters_fetchUrl as fetchUrl,
|
|
523
|
+
filters_first as first,
|
|
524
|
+
filters_fixed as fixed,
|
|
525
|
+
filters_get as get,
|
|
526
|
+
filters_groupby as groupby,
|
|
527
|
+
filters_invert as invert,
|
|
528
|
+
filters_join as join,
|
|
529
|
+
filters_json as json,
|
|
530
|
+
filters_keys as keys,
|
|
531
|
+
filters_last as last,
|
|
532
|
+
filters_length as length,
|
|
533
|
+
filters_lower as lower,
|
|
534
|
+
filters_map as map,
|
|
535
|
+
filters_max as max,
|
|
536
|
+
filters_merge as merge,
|
|
537
|
+
filters_min as min,
|
|
538
|
+
filters_mul as mul,
|
|
539
|
+
filters_odd as odd,
|
|
540
|
+
filters_omit as omit,
|
|
541
|
+
filters_percent as percent,
|
|
542
|
+
filters_pick as pick,
|
|
543
|
+
filters_pluck as pluck,
|
|
544
|
+
filters_repeat as repeat,
|
|
545
|
+
filters_replace as replace,
|
|
546
|
+
filters_reverse as reverse,
|
|
547
|
+
filters_round as round,
|
|
548
|
+
filters_safe as safe,
|
|
549
|
+
filters_shuffle as shuffle,
|
|
550
|
+
filters_slice as slice,
|
|
551
|
+
filters_slugify as slugify,
|
|
552
|
+
filters_sort as sort,
|
|
553
|
+
filters_split as split,
|
|
554
|
+
filters_stripTags as stripTags,
|
|
555
|
+
filters_sub as sub,
|
|
556
|
+
filters_sum as sum,
|
|
557
|
+
filters_timeAgo as timeAgo,
|
|
558
|
+
filters_trim as trim,
|
|
559
|
+
filters_truncate as truncate,
|
|
560
|
+
filters_unique as unique,
|
|
561
|
+
filters_upper as upper,
|
|
562
|
+
filters_urldecode as urldecode,
|
|
563
|
+
filters_urlencode as urlencode,
|
|
564
|
+
filters_values as values,
|
|
565
|
+
filters_wordCount as wordCount,
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
interface ErrorSuggestion {
|
|
570
|
+
message: string;
|
|
571
|
+
fix?: string;
|
|
572
|
+
example?: string;
|
|
256
573
|
}
|
|
257
574
|
|
|
258
575
|
declare class CompileError extends SyntaxError {
|
|
259
576
|
protected src: string;
|
|
260
577
|
protected loc?: Loc | undefined;
|
|
261
|
-
|
|
578
|
+
protected context?: string | undefined;
|
|
579
|
+
constructor(message: string, src: string, loc?: Loc | undefined, context?: string | undefined);
|
|
262
580
|
get details(): string;
|
|
581
|
+
get suggestions(): ErrorSuggestion[];
|
|
263
582
|
}
|
|
264
583
|
|
|
584
|
+
declare const baseOptions: Required<BaseOptions>;
|
|
585
|
+
declare const parserOptions: Required<ParserOptions>;
|
|
586
|
+
declare const compilerOptions: Required<CompilerOptions>;
|
|
587
|
+
declare const renderOptions: Required<RendererOptions>;
|
|
588
|
+
declare const mergeOptions: <T extends Required<BaseOptions>, U extends RendererOptions>(defaultOptions: T, ...optionsArray: U[]) => Required<U>;
|
|
589
|
+
|
|
265
590
|
declare class RenderError extends CompileError {
|
|
266
591
|
protected src: string;
|
|
267
592
|
protected getLoc: () => Loc;
|
|
268
|
-
constructor(message: string, src: string, getLoc: () => Loc);
|
|
593
|
+
constructor(message: string, src: string, getLoc: () => Loc, context?: string);
|
|
269
594
|
get details(): string;
|
|
270
595
|
}
|
|
271
596
|
|
|
272
597
|
declare class Renderer {
|
|
273
598
|
protected options: Required<RendererOptions>;
|
|
599
|
+
private cache?;
|
|
600
|
+
private sandbox?;
|
|
601
|
+
private filters;
|
|
602
|
+
private escape;
|
|
603
|
+
private compiling;
|
|
274
604
|
constructor(options?: RendererOptions);
|
|
275
605
|
render(template: string, globals: ObjectType): Promise<string>;
|
|
606
|
+
/**
|
|
607
|
+
* Bind a template to the type of data it expects:
|
|
608
|
+
* `const page = renderer.template<{ title: string }>(source)`.
|
|
609
|
+
*/
|
|
610
|
+
template<Data extends ObjectType = ObjectType>(template: string): (data: Data) => Promise<string>;
|
|
611
|
+
/**
|
|
612
|
+
* Render a template that was compiled ahead of time by `precompileTemplate`.
|
|
613
|
+
*/
|
|
614
|
+
renderCompiled(script: Script, globals?: ObjectType): Promise<string>;
|
|
615
|
+
/**
|
|
616
|
+
* Render a template as a stream of chunks, so the first bytes can be sent
|
|
617
|
+
* before the whole page is rendered. Output is written between top-level
|
|
618
|
+
* parts of the template and between the iterations of top-level loops.
|
|
619
|
+
*/
|
|
620
|
+
renderStream(template: string, globals?: ObjectType): ReadableStream<string>;
|
|
621
|
+
private compile;
|
|
622
|
+
private wrapError;
|
|
623
|
+
private run;
|
|
276
624
|
renderFile(filepath: string, globals: ObjectType): Promise<string>;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
625
|
+
clearCache(): void;
|
|
626
|
+
invalidateCache(predicate?: (key: string) => boolean): void;
|
|
627
|
+
getCacheStats(): {
|
|
628
|
+
size: number;
|
|
629
|
+
hitRate: number;
|
|
630
|
+
hits: number;
|
|
631
|
+
misses: number;
|
|
632
|
+
evictions: number;
|
|
633
|
+
} | null;
|
|
634
|
+
resetCacheStats(): void;
|
|
635
|
+
auditTemplate(template: string): SecurityAuditResult;
|
|
636
|
+
getCSPHeaders(): Record<string, string>;
|
|
281
637
|
}
|
|
282
638
|
|
|
283
639
|
declare class ExpCompiler {
|
|
@@ -287,6 +643,11 @@ declare class ExpCompiler {
|
|
|
287
643
|
private compileExp;
|
|
288
644
|
private compileNot;
|
|
289
645
|
private compileId;
|
|
646
|
+
/**
|
|
647
|
+
* Positional arguments in the order they are written, followed by one
|
|
648
|
+
* object holding the named ones: `f(1, a=2, b=3)` calls `f(1, {a:2,b:3})`.
|
|
649
|
+
*/
|
|
650
|
+
private compileArgs;
|
|
290
651
|
private compileLit;
|
|
291
652
|
private compileSeq;
|
|
292
653
|
private compilePipe;
|
|
@@ -298,7 +659,10 @@ declare class ExpCompiler {
|
|
|
298
659
|
|
|
299
660
|
declare class ExpError extends SyntaxError {
|
|
300
661
|
loc: Loc;
|
|
301
|
-
|
|
662
|
+
private context?;
|
|
663
|
+
constructor(message: string, loc: Loc, context?: string | undefined);
|
|
664
|
+
get suggestions(): ErrorSuggestion[];
|
|
665
|
+
get details(): string;
|
|
302
666
|
}
|
|
303
667
|
|
|
304
668
|
interface ExpToken<T = ExpTokenType> {
|
|
@@ -308,6 +672,7 @@ interface ExpToken<T = ExpTokenType> {
|
|
|
308
672
|
raw?: string;
|
|
309
673
|
}
|
|
310
674
|
declare const expTokenTypes: Record<string, ExpTokenType>;
|
|
675
|
+
declare function isForbiddenIdentifier(name: unknown): boolean;
|
|
311
676
|
declare class ExpTokenizer implements Pos {
|
|
312
677
|
val: string;
|
|
313
678
|
tokens: ExpToken[];
|
|
@@ -315,6 +680,7 @@ declare class ExpTokenizer implements Pos {
|
|
|
315
680
|
line: number;
|
|
316
681
|
column: number;
|
|
317
682
|
tokenize(val: string, loc: Loc): ExpToken<ExpTokenType>[];
|
|
683
|
+
private afterOperand;
|
|
318
684
|
private readString;
|
|
319
685
|
private readNumber;
|
|
320
686
|
private readIdentifier;
|
|
@@ -340,8 +706,327 @@ declare class ExpParser implements Pos {
|
|
|
340
706
|
private consume;
|
|
341
707
|
}
|
|
342
708
|
|
|
709
|
+
/**
|
|
710
|
+
* A source map as defined by the Source Map Revision 3 specification.
|
|
711
|
+
*/
|
|
712
|
+
interface SourceMapV3 {
|
|
713
|
+
version: 3;
|
|
714
|
+
file?: string;
|
|
715
|
+
sources: string[];
|
|
716
|
+
sourcesContent: string[];
|
|
717
|
+
names: string[];
|
|
718
|
+
mappings: string;
|
|
719
|
+
}
|
|
720
|
+
interface SourceMapOptions {
|
|
721
|
+
/** Name of the generated file */
|
|
722
|
+
file?: string;
|
|
723
|
+
/** Name of the template the code was compiled from */
|
|
724
|
+
source: string;
|
|
725
|
+
/** The template itself, embedded so tools need not find it on disk */
|
|
726
|
+
sourceContent: string;
|
|
727
|
+
/** Zero-based line of the generated file that holds the compiled code */
|
|
728
|
+
line: number;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Turn the compiler's mappings (template location -> offset in the compiled
|
|
732
|
+
* code, which is a single line) into a standard source map.
|
|
733
|
+
*/
|
|
734
|
+
declare function generateSourceMap(mappings: Mapping[], { file, source, sourceContent, line }: SourceMapOptions): SourceMapV3;
|
|
735
|
+
|
|
736
|
+
interface PrecompileOptions extends CompilerOptions {
|
|
737
|
+
/**
|
|
738
|
+
* Also export a ready-to-call `render(globals, options)` function. The
|
|
739
|
+
* generated module then imports the runtime from `janja`.
|
|
740
|
+
*/
|
|
741
|
+
includeRuntime?: boolean;
|
|
742
|
+
/** Also return a source map (`precompile` only) */
|
|
743
|
+
sourceMap?: boolean;
|
|
744
|
+
/** Name of the template, recorded in the source map */
|
|
745
|
+
filename?: string;
|
|
746
|
+
/** Also return TypeScript declarations for the module (`precompile` only) */
|
|
747
|
+
dts?: boolean;
|
|
748
|
+
}
|
|
749
|
+
interface PrecompileResult {
|
|
750
|
+
/** Source of an ES module exporting the compiled template as `script` */
|
|
751
|
+
code: string;
|
|
752
|
+
/** Present when the `sourceMap` option is set */
|
|
753
|
+
map?: SourceMapV3;
|
|
754
|
+
/** Present when the `dts` option is set */
|
|
755
|
+
dts?: string;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Compile a template into the source of an ES module, optionally with a
|
|
759
|
+
* source map pointing back into the template.
|
|
760
|
+
*
|
|
761
|
+
* The module's `script` export is the compiled template; pass it to
|
|
762
|
+
* `renderCompiled` to render it without compiling anything at runtime.
|
|
763
|
+
*/
|
|
764
|
+
declare function precompile(template: string, { includeRuntime, sourceMap, filename, dts, ...options }?: PrecompileOptions): Promise<PrecompileResult>;
|
|
765
|
+
/**
|
|
766
|
+
* Compile a template into the source of an ES module. See `precompile`.
|
|
767
|
+
*/
|
|
768
|
+
declare function precompileTemplate(template: string, options?: PrecompileOptions): Promise<string>;
|
|
769
|
+
|
|
770
|
+
interface TranslationDict {
|
|
771
|
+
[key: string]: string | TranslationDict;
|
|
772
|
+
}
|
|
773
|
+
interface I18nOptions {
|
|
774
|
+
defaultLocale?: string;
|
|
775
|
+
locale?: string;
|
|
776
|
+
translations?: Record<string, TranslationDict>;
|
|
777
|
+
pluralRules?: PluralRules;
|
|
778
|
+
}
|
|
779
|
+
interface PluralRules {
|
|
780
|
+
[locale: string]: (n: number) => 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
|
|
781
|
+
}
|
|
782
|
+
declare class I18n {
|
|
783
|
+
private defaultLocale;
|
|
784
|
+
private currentLocale;
|
|
785
|
+
private translations;
|
|
786
|
+
private pluralRules;
|
|
787
|
+
constructor(options?: I18nOptions);
|
|
788
|
+
setLocale(locale: string): void;
|
|
789
|
+
getLocale(): string;
|
|
790
|
+
addTranslations(locale: string, translations: TranslationDict): void;
|
|
791
|
+
translate(key: string, params?: ObjectType): string;
|
|
792
|
+
t(key: string, params?: ObjectType): string;
|
|
793
|
+
pluralize(key: string, count: number, params?: ObjectType): string;
|
|
794
|
+
formatDate(date: Date | string, options?: Intl.DateTimeFormatOptions): string;
|
|
795
|
+
formatNumber(number: number, options?: Intl.NumberFormatOptions): string;
|
|
796
|
+
formatCurrency(number: number, currency: string, options?: Intl.NumberFormatOptions): string;
|
|
797
|
+
private getTranslation;
|
|
798
|
+
private interpolate;
|
|
799
|
+
private getPluralForm;
|
|
800
|
+
private getDefaultPluralRules;
|
|
801
|
+
private mergeDeep;
|
|
802
|
+
private isObject;
|
|
803
|
+
}
|
|
804
|
+
declare const i18n: I18n;
|
|
805
|
+
|
|
806
|
+
interface CompositionOptions {
|
|
807
|
+
data?: ObjectType;
|
|
808
|
+
options?: RendererOptions;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Compose multiple templates together, passing the output of one as input to the next.
|
|
812
|
+
*/
|
|
813
|
+
declare function composeTemplates(templates: string[], options?: CompositionOptions): Promise<string>;
|
|
814
|
+
/**
|
|
815
|
+
* Compose templates with partial data, allowing each template to access specific data.
|
|
816
|
+
*/
|
|
817
|
+
declare function composeTemplatesWithData(templates: Array<{
|
|
818
|
+
template: string;
|
|
819
|
+
data?: ObjectType;
|
|
820
|
+
}>, options?: CompositionOptions): Promise<string>;
|
|
821
|
+
/**
|
|
822
|
+
* Create a template composition pipeline.
|
|
823
|
+
*/
|
|
824
|
+
declare class TemplatePipeline {
|
|
825
|
+
private templates;
|
|
826
|
+
private data;
|
|
827
|
+
private options?;
|
|
828
|
+
constructor(options?: RendererOptions);
|
|
829
|
+
addTemplate(template: string): TemplatePipeline;
|
|
830
|
+
setData(data: ObjectType): TemplatePipeline;
|
|
831
|
+
setOptions(options: RendererOptions): TemplatePipeline;
|
|
832
|
+
execute(): Promise<string>;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Compose templates in a layout pattern (header, content, footer).
|
|
836
|
+
*/
|
|
837
|
+
declare function composeLayout(layout: string, content: string, options?: CompositionOptions): Promise<string>;
|
|
838
|
+
/**
|
|
839
|
+
* Compose templates with slots for flexible content placement.
|
|
840
|
+
*/
|
|
841
|
+
declare function composeWithSlots(template: string, slots: Record<string, string>, options?: CompositionOptions): Promise<string>;
|
|
842
|
+
|
|
843
|
+
interface WhitespaceOptions {
|
|
844
|
+
trim?: boolean;
|
|
845
|
+
stripComments?: boolean;
|
|
846
|
+
collapseWhitespace?: boolean;
|
|
847
|
+
preserveNewlines?: boolean;
|
|
848
|
+
}
|
|
849
|
+
declare const defaultWhitespaceOptions: Required<WhitespaceOptions>;
|
|
850
|
+
declare function mergeWhitespaceOptions(options?: WhitespaceOptions): Required<WhitespaceOptions>;
|
|
851
|
+
declare function applyWhitespaceControl(content: string, options: Required<WhitespaceOptions>): string;
|
|
852
|
+
declare function getWhitespaceCompilerOptions(options: WhitespaceOptions): Partial<CompilerOptions>;
|
|
853
|
+
declare function getWhitespaceRendererOptions(options: WhitespaceOptions): Partial<RendererOptions>;
|
|
854
|
+
|
|
855
|
+
interface MixinDefinition {
|
|
856
|
+
name: string;
|
|
857
|
+
template: string;
|
|
858
|
+
data?: ObjectType;
|
|
859
|
+
}
|
|
860
|
+
interface MixinOptions {
|
|
861
|
+
data?: ObjectType;
|
|
862
|
+
options?: RendererOptions;
|
|
863
|
+
}
|
|
864
|
+
declare class MixinRegistry {
|
|
865
|
+
private mixins;
|
|
866
|
+
register(mixin: MixinDefinition): void;
|
|
867
|
+
registerMultiple(mixins: MixinDefinition[]): void;
|
|
868
|
+
get(name: string): MixinDefinition | undefined;
|
|
869
|
+
has(name: string): boolean;
|
|
870
|
+
delete(name: string): boolean;
|
|
871
|
+
clear(): void;
|
|
872
|
+
list(): string[];
|
|
873
|
+
}
|
|
874
|
+
declare const globalMixinRegistry: MixinRegistry;
|
|
875
|
+
declare function applyMixin(name: string, options?: MixinOptions, registry?: MixinRegistry): Promise<string>;
|
|
876
|
+
declare function applyMixins(names: string[], options?: MixinOptions, registry?: MixinRegistry): Promise<string[]>;
|
|
877
|
+
declare function extendTemplateWithMixin(baseTemplate: string, mixinName: string, options?: MixinOptions, registry?: MixinRegistry): Promise<string>;
|
|
878
|
+
declare function createMixin(name: string, template: string, data?: ObjectType): MixinDefinition;
|
|
879
|
+
|
|
880
|
+
interface ValidationError {
|
|
881
|
+
type: 'error' | 'warning';
|
|
882
|
+
message: string;
|
|
883
|
+
line?: number;
|
|
884
|
+
column?: number;
|
|
885
|
+
suggestion?: string;
|
|
886
|
+
}
|
|
887
|
+
interface ValidationResult {
|
|
888
|
+
valid: boolean;
|
|
889
|
+
errors: ValidationError[];
|
|
890
|
+
warnings: ValidationError[];
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Validates templates by running them through the real parser, so it reports
|
|
894
|
+
* exactly the syntax errors that rendering would.
|
|
895
|
+
*/
|
|
896
|
+
declare class TemplateValidator {
|
|
897
|
+
private options;
|
|
898
|
+
constructor(options?: CompilerOptions);
|
|
899
|
+
validate(template: string): Promise<ValidationResult>;
|
|
900
|
+
private checkFilters;
|
|
901
|
+
}
|
|
902
|
+
declare function validateTemplate(template: string, options?: CompilerOptions): Promise<ValidationResult>;
|
|
903
|
+
|
|
904
|
+
interface TemplateAnalysis {
|
|
905
|
+
/** Names the template reads from the data it is rendered with */
|
|
906
|
+
variables: string[];
|
|
907
|
+
/** Filters the template applies */
|
|
908
|
+
filters: string[];
|
|
909
|
+
/** Templates it includes, directly or through other includes */
|
|
910
|
+
includes: string[];
|
|
911
|
+
/** Blocks it defines */
|
|
912
|
+
blocks: string[];
|
|
913
|
+
/** Macros it defines */
|
|
914
|
+
macros: string[];
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Statically determine what a template needs: the data it reads, the filters
|
|
918
|
+
* it applies and the templates it includes. Included templates are followed
|
|
919
|
+
* through the `loader` option.
|
|
920
|
+
*/
|
|
921
|
+
declare function analyzeTemplate(template: string, options?: CompilerOptions): Promise<TemplateAnalysis>;
|
|
922
|
+
/**
|
|
923
|
+
* TypeScript declarations for a module produced by `precompile`: the data
|
|
924
|
+
* the template reads becomes the `TemplateData` interface.
|
|
925
|
+
*/
|
|
926
|
+
declare function generateDeclarations({ variables }: Pick<TemplateAnalysis, 'variables'>, { includeRuntime }?: {
|
|
927
|
+
includeRuntime?: boolean | undefined;
|
|
928
|
+
}): string;
|
|
929
|
+
|
|
930
|
+
type FormatOptions = Pick<ParserOptions, 'commentOpen' | 'commentClose' | 'directiveOpen' | 'directiveClose' | 'outputOpen' | 'outputClose'>;
|
|
931
|
+
/**
|
|
932
|
+
* Normalise the tags of a template:
|
|
933
|
+
*
|
|
934
|
+
* {{=name|upper}} -> {{= name | upper }}
|
|
935
|
+
* {{if a eq 1}} -> {{ if a eq 1 }}
|
|
936
|
+
* {{#note#}} -> {{# note #}}
|
|
937
|
+
*
|
|
938
|
+
* Only what is inside tags changes. Text between tags, where whitespace may
|
|
939
|
+
* matter, is kept byte for byte, as are whitespace-control markers. A tag is
|
|
940
|
+
* left exactly as written whenever its expression does not parse or
|
|
941
|
+
* reformatting would not provably keep its meaning. Formatting twice gives
|
|
942
|
+
* the same result as formatting once.
|
|
943
|
+
*
|
|
944
|
+
* Throws a `CompileError` for templates with an unclosed tag.
|
|
945
|
+
*/
|
|
946
|
+
declare function formatTemplate(template: string, options?: FormatOptions): string;
|
|
947
|
+
|
|
948
|
+
interface FileLoaderOptions {
|
|
949
|
+
/**
|
|
950
|
+
* Extensions tried, in order, when a path has none.
|
|
951
|
+
* @default ['.janja', '.html']
|
|
952
|
+
*/
|
|
953
|
+
extensions?: string[];
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* A `loader` that reads templates from a directory (Node.js only).
|
|
957
|
+
*
|
|
958
|
+
* Paths are resolved against `root`, with or without an extension, and may
|
|
959
|
+
* not lead outside of it, so that a template cannot include arbitrary files.
|
|
960
|
+
*/
|
|
961
|
+
declare function createFileLoader(root: string, { extensions }?: FileLoaderOptions): (name: string) => Promise<string>;
|
|
962
|
+
|
|
963
|
+
interface ErrorRecoveryOptions {
|
|
964
|
+
/**
|
|
965
|
+
* Whether to continue rendering when an error occurs
|
|
966
|
+
*/
|
|
967
|
+
continueOnError?: boolean;
|
|
968
|
+
/**
|
|
969
|
+
* Fallback value to use when a variable is undefined
|
|
970
|
+
*/
|
|
971
|
+
undefinedFallback?: any;
|
|
972
|
+
/**
|
|
973
|
+
* Whether to ignore missing filters
|
|
974
|
+
*/
|
|
975
|
+
ignoreMissingFilters?: boolean;
|
|
976
|
+
/**
|
|
977
|
+
* Custom error handler for rendering errors
|
|
978
|
+
*/
|
|
979
|
+
onError?: (error: Error, context: ErrorContext) => any;
|
|
980
|
+
}
|
|
981
|
+
interface ErrorContext {
|
|
982
|
+
template: string;
|
|
983
|
+
data: ObjectType;
|
|
984
|
+
expression?: string;
|
|
985
|
+
filter?: string;
|
|
986
|
+
}
|
|
987
|
+
declare class ErrorRecovery {
|
|
988
|
+
private options;
|
|
989
|
+
constructor(options?: ErrorRecoveryOptions);
|
|
990
|
+
/**
|
|
991
|
+
* Safely evaluate an expression with error recovery
|
|
992
|
+
*/
|
|
993
|
+
safeEvaluate(expression: string, data: ObjectType, context?: Partial<ErrorContext>): any;
|
|
994
|
+
/**
|
|
995
|
+
* Safely apply a filter with error recovery
|
|
996
|
+
*/
|
|
997
|
+
safeApplyFilter(value: any, filterName: string, filterFn: ((value: any, ...args: any[]) => any) | undefined, args?: any[], context?: Partial<ErrorContext>): any;
|
|
998
|
+
/**
|
|
999
|
+
* Wrap a rendering function with error recovery
|
|
1000
|
+
*/
|
|
1001
|
+
wrapRender<T extends (...args: any[]) => any>(fn: T, context?: Partial<ErrorContext>): T;
|
|
1002
|
+
/**
|
|
1003
|
+
* Simple expression evaluation (placeholder for actual expression evaluator)
|
|
1004
|
+
*/
|
|
1005
|
+
private evaluateExpression;
|
|
1006
|
+
/**
|
|
1007
|
+
* Create a safe data accessor that handles undefined paths
|
|
1008
|
+
*/
|
|
1009
|
+
createSafeAccessor(data: ObjectType): (path: string) => any;
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Default error handler that logs to console
|
|
1013
|
+
*/
|
|
1014
|
+
declare function defaultErrorHandler(error: Error, context: ErrorContext): void;
|
|
1015
|
+
/**
|
|
1016
|
+
* Create error recovery options with defaults
|
|
1017
|
+
*/
|
|
1018
|
+
declare function createErrorRecovery(options?: ErrorRecoveryOptions): ErrorRecovery;
|
|
1019
|
+
|
|
343
1020
|
declare function render(template: string, data: ObjectType, options?: RendererOptions): Promise<string>;
|
|
344
1021
|
declare function renderFile(filepath: string, data: ObjectType, options?: RendererOptions): Promise<string>;
|
|
1022
|
+
/**
|
|
1023
|
+
* Render a template that was compiled ahead of time by `precompileTemplate`.
|
|
1024
|
+
*/
|
|
1025
|
+
declare function renderCompiled(script: Script, data?: ObjectType, options?: RendererOptions): Promise<string>;
|
|
1026
|
+
/**
|
|
1027
|
+
* Render a template as a stream of chunks. See `Renderer.renderStream`.
|
|
1028
|
+
*/
|
|
1029
|
+
declare function renderStream(template: string, data?: ObjectType, options?: RendererOptions): ReadableStream<string>;
|
|
345
1030
|
|
|
346
|
-
export { CompileError, Compiler, ExpCompiler, ExpError, ExpParser, ExpTokenizer, Parser, RenderError, Renderer, RootNode, Safe, TokenType, Tokenizer, Traversal, expTokenTypes, render, renderFile };
|
|
347
|
-
export type { BinaryExp, BinaryExpTokenType, BinaryExpType, Checker, CommentToken, CompilerFn, CompilerMap, DirectiveExpression, DirectiveToken, Exp, ExpBase, ExpToken, ExpTokenType, ExpType, Filters, IdExp, IfExp, LitExp, Loc, MaybePromise, NotExp, ObjectType, OutputToken, ParserFn, ParserMap, Plugin, Pos, Primitive, Script, SeqExp, Strip, SyntaxNode, TernaryExpTokenType, TernaryExpType, TextToken, Token, TokenBase, UnaryExpTokenType, UnaryExpType };
|
|
1031
|
+
export { CompileError, Compiler, ErrorRecovery, ExpCompiler, ExpError, ExpParser, ExpTokenizer, I18n, MAX_INCLUDE_DEPTH, MixinRegistry, Parser, RenderError, Renderer, RootNode, Safe, TemplatePipeline, TemplateValidator, TokenType, Tokenizer, Traversal, analyzeTemplate, applyMixin, applyMixins, applyWhitespaceControl, baseOptions, compilerOptions, composeLayout, composeTemplates, composeTemplatesWithData, composeWithSlots, createErrorRecovery, createFileLoader, createMixin, defaultErrorHandler, defaultWhitespaceOptions, defineFilters, definePlugin, expTokenTypes, extendTemplateWithMixin, filters, formatTemplate, generateDeclarations, generateSourceMap, getWhitespaceCompilerOptions, getWhitespaceRendererOptions, globalMixinRegistry, i18n, isForbiddenIdentifier, mergeOptions, mergeWhitespaceOptions, optionsFingerprint, parserOptions, precompile, precompileTemplate, render, renderCompiled, renderFile, renderOptions, renderStream, templateCacheKey, validateTemplate };
|
|
1032
|
+
export type { BaseOptions, BinaryExp, BinaryExpTokenType, BinaryExpType, CacheOptions, Checker, CommentToken, CompiledTemplate, CompilerFn, CompilerMap, CompilerOptions, CompositionOptions, DirectiveExpression, DirectiveToken, ErrorContext, ErrorRecoveryOptions, Exp, ExpBase, ExpToken, ExpTokenType, ExpType, FileLoaderOptions, Filter, Filters, FormatOptions, FormatterFn, FormatterMap, FormatterOptions, I18nOptions, IdExp, IfExp, LitExp, Loc, MaybePromise, MixinDefinition, MixinOptions, NotExp, ObjectType, OutputToken, ParserFn, ParserMap, ParserOptions, Plugin, PluralRules, Pos, PrecompileOptions, PrecompileResult, Primitive, RendererOptions, Script, SeqExp, SourceMapOptions, SourceMapV3, Strip, SyntaxNode, TemplateAnalysis, TernaryExpTokenType, TernaryExpType, TextToken, Token, TokenBase, TranslationDict, UnaryExpTokenType, UnaryExpType, ValidationError, ValidationResult, WhitespaceOptions };
|