UNPKG

9.27 kBTypeScriptView Raw
1import { LiquidCache } from './cache';
2import { FS, LookupType } from './fs';
3import { Operators } from './render';
4type OutputEscape = (value: any) => string;
5type OutputEscapeOption = 'escape' | 'json' | OutputEscape;
6export interface LiquidOptions {
7 /** A directory or an array of directories from where to resolve layout and include templates, and the filename passed to `.renderFile()`. If it's an array, the files are looked up in the order they occur in the array. Defaults to `["."]` */
8 root?: string | string[];
9 /** A directory or an array of directories from where to resolve included templates. If it's an array, the files are looked up in the order they occur in the array. Defaults to `root` */
10 partials?: string | string[];
11 /** A directory or an array of directories from where to resolve layout templates. If it's an array, the files are looked up in the order they occur in the array. Defaults to `root` */
12 layouts?: string | string[];
13 /** Allow refer to layouts/partials by relative pathname. To avoid arbitrary filesystem read, paths been referenced also need to be within corresponding root, partials, layouts. Defaults to `true`. */
14 relativeReference?: boolean;
15 /** Use jekyll style include, pass parameters to `include` variable of current scope. Defaults to `false`. */
16 jekyllInclude?: boolean;
17 /** Use jekyll style where filter, enables array item match. Defaults to `false`. */
18 jekyllWhere?: boolean;
19 /** Add a extname (if filepath doesn't include one) before template file lookup. Eg: setting to `".html"` will allow including file by basename. Defaults to `""`. */
20 extname?: string;
21 /** Whether or not to cache resolved templates. Defaults to `false`. */
22 cache?: boolean | number | LiquidCache;
23 /** Use JavaScript Truthiness. Defaults to `false`. */
24 jsTruthy?: boolean;
25 /** If set, treat the `filepath` parameter in `{%include filepath %}` and `{%layout filepath%}` as a variable, otherwise as a literal value. Defaults to `true`. */
26 dynamicPartials?: boolean;
27 /** Whether or not to assert filter existence. If set to `false`, undefined filters will be skipped. Otherwise, undefined filters will cause an exception. Defaults to `false`. */
28 strictFilters?: boolean;
29 /** Whether or not to assert variable existence. If set to `false`, undefined variables will be rendered as empty string. Otherwise, undefined variables will cause an exception. Defaults to `false`. */
30 strictVariables?: boolean;
31 /** Catch all errors instead of exit upon one. Please note that render errors won't be reached when parse fails. */
32 catchAllErrors?: boolean;
33 /** Hide scope variables from prototypes, useful when you're passing a not sanitized object into LiquidJS or need to hide prototypes from templates. */
34 ownPropertyOnly?: boolean;
35 /** Modifies the behavior of `strictVariables`. If set, a single undefined variable will *not* cause an exception in the context of the `if`/`elsif`/`unless` tag and the `default` filter. Instead, it will evaluate to `false` and `null`, respectively. Irrelevant if `strictVariables` is not set. Defaults to `false`. **/
36 lenientIf?: boolean;
37 /** JavaScript timezone name or timezoneOffset for `date` filter, default to local time. That means if you're in Australia (UTC+10), it'll default to `-600` or `Australia/Lindeman` */
38 timezoneOffset?: number | string;
39 /** Default date format to use if the date filter doesn't include a format. Defaults to `%A, %B %-e, %Y at %-l:%M %P %z`. */
40 dateFormat?: string;
41 /** Default locale, will be used by date filter. Defaults to system locale. */
42 locale?: string;
43 /** Strip blank characters (including ` `, `\t`, and `\r`) from the right of tags (`{% %}`) until `\n` (inclusive). Defaults to `false`. */
44 trimTagRight?: boolean;
45 /** Similar to `trimTagRight`, whereas the `\n` is exclusive. Defaults to `false`. See Whitespace Control for details. */
46 trimTagLeft?: boolean;
47 /** Strip blank characters (including ` `, `\t`, and `\r`) from the right of values (`{{ }}`) until `\n` (inclusive). Defaults to `false`. */
48 trimOutputRight?: boolean;
49 /** Similar to `trimOutputRight`, whereas the `\n` is exclusive. Defaults to `false`. See Whitespace Control for details. */
50 trimOutputLeft?: boolean;
51 /** The left delimiter for liquid tags. **/
52 tagDelimiterLeft?: string;
53 /** The right delimiter for liquid tags. **/
54 tagDelimiterRight?: string;
55 /** The left delimiter for liquid outputs. **/
56 outputDelimiterLeft?: string;
57 /** The right delimiter for liquid outputs. **/
58 outputDelimiterRight?: string;
59 /** Whether input strings to date filter preserve the given timezone **/
60 preserveTimezones?: boolean;
61 /** Whether `trim*Left`/`trim*Right` is greedy. When set to `true`, all consecutive blank characters including `\n` will be trimmed regardless of line breaks. Defaults to `true`. */
62 greedy?: boolean;
63 /** `fs` is used to override the default file-system module with a custom implementation. */
64 fs?: FS;
65 /** keyValue separator */
66 keyValueSeparator?: string;
67 /** Render from in-memory `templates` mapping instead of file system. File system related options like `fs`, 'root', and `relativeReference` will be ignored when `templates` is specified. */
68 templates?: {
69 [key: string]: string;
70 };
71 /** the global scope passed down to all partial and layout templates, i.e. templates included by `include`, `layout` and `render` tags. */
72 globals?: object;
73 /** Whether or not to keep value type when writing the Output, not working for streamed rendering. Defaults to `false`. */
74 keepOutputType?: boolean;
75 /** Default escape filter applied to output values, when set, you'll have to add `| raw` for values don't need to be escaped. Defaults to `undefined`. */
76 outputEscape?: OutputEscapeOption;
77 /** An object of operators for conditional statements. Defaults to the regular Liquid operators. */
78 operators?: Operators;
79 /** Respect parameter order when using filters like "for ... reversed limit", Defaults to `false`. */
80 orderedFilterParameters?: boolean;
81 /** For DoS handling, limit total length of templates parsed in one `parse()` call. A typical PC can handle 1e8 (100M) characters without issues. */
82 parseLimit?: number;
83 /** For DoS handling, limit total time (in ms) for each `render()` call. */
84 renderLimit?: number;
85 /** For DoS handling, limit new objects creation, including array concat/join/strftime, etc. A typical PC can handle 1e9 (1G) memory without issue. */
86 memoryLimit?: number;
87}
88export interface RenderOptions {
89 /**
90 * This call is sync or async? It's used by Liquid internal methods, you'll not need this.
91 */
92 sync?: boolean;
93 /**
94 * Same as `globals` on LiquidOptions, but only for current render() call
95 */
96 globals?: object;
97 /**
98 * Same as `strictVariables` on LiquidOptions, but only for current render() call
99 */
100 strictVariables?: boolean;
101 /**
102 * Same as `ownPropertyOnly` on LiquidOptions, but only for current render() call
103 */
104 ownPropertyOnly?: boolean;
105 /** For DoS handling, limit total renders of tag/HTML/output in one `render()` call. A typical PC can handle 1e5 renders of typical templates per second. */
106 templateLimit?: number;
107 /** For DoS handling, limit total time (in ms) for each `render()` call. */
108 renderLimit?: number;
109 /** For DoS handling, limit new objects creation, including array concat/join/strftime, etc. A typical PC can handle 1e9 (1G) memory without issue.. */
110 memoryLimit?: number;
111}
112export interface RenderFileOptions extends RenderOptions {
113 lookupType?: LookupType;
114}
115interface NormalizedOptions extends LiquidOptions {
116 root?: string[];
117 partials?: string[];
118 layouts?: string[];
119 cache?: LiquidCache;
120 outputEscape?: OutputEscape;
121}
122export interface NormalizedFullOptions extends NormalizedOptions {
123 root: string[];
124 partials: string[];
125 layouts: string[];
126 relativeReference: boolean;
127 jekyllInclude: boolean;
128 extname: string;
129 cache?: LiquidCache;
130 jsTruthy: boolean;
131 dynamicPartials: boolean;
132 fs: FS;
133 strictFilters: boolean;
134 strictVariables: boolean;
135 ownPropertyOnly: boolean;
136 lenientIf: boolean;
137 dateFormat: string;
138 locale: string;
139 trimTagRight: boolean;
140 trimTagLeft: boolean;
141 trimOutputRight: boolean;
142 trimOutputLeft: boolean;
143 tagDelimiterLeft: string;
144 tagDelimiterRight: string;
145 outputDelimiterLeft: string;
146 outputDelimiterRight: string;
147 preserveTimezones: boolean;
148 greedy: boolean;
149 globals: object;
150 keepOutputType: boolean;
151 operators: Operators;
152 parseLimit: number;
153 renderLimit: number;
154 memoryLimit: number;
155}
156export declare const defaultOptions: NormalizedFullOptions;
157export declare function normalize(options: LiquidOptions): NormalizedFullOptions;
158export declare function normalizeDirectoryList(value: any): string[];
159export {};