UNPKG

7.67 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 /** 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 `""`. */
18 extname?: string;
19 /** Whether or not to cache resolved templates. Defaults to `false`. */
20 cache?: boolean | number | LiquidCache;
21 /** Use JavaScript Truthiness. Defaults to `false`. */
22 jsTruthy?: boolean;
23 /** If set, treat the `filepath` parameter in `{%include filepath %}` and `{%layout filepath%}` as a variable, otherwise as a literal value. Defaults to `true`. */
24 dynamicPartials?: boolean;
25 /** 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`. */
26 strictFilters?: boolean;
27 /** 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`. */
28 strictVariables?: boolean;
29 /** Catch all errors instead of exit upon one. Please note that render errors won't be reached when parse fails. */
30 catchAllErrors?: boolean;
31 /** Hide scope variables from prototypes, useful when you're passing a not sanitized object into LiquidJS or need to hide prototypes from templates. */
32 ownPropertyOnly?: boolean;
33 /** 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`. **/
34 lenientIf?: boolean;
35 /** 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` */
36 timezoneOffset?: number | string;
37 /** 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`. */
38 dateFormat?: string;
39 /** Strip blank characters (including ` `, `\t`, and `\r`) from the right of tags (`{% %}`) until `\n` (inclusive). Defaults to `false`. */
40 trimTagRight?: boolean;
41 /** Similar to `trimTagRight`, whereas the `\n` is exclusive. Defaults to `false`. See Whitespace Control for details. */
42 trimTagLeft?: boolean;
43 /** Strip blank characters (including ` `, `\t`, and `\r`) from the right of values (`{{ }}`) until `\n` (inclusive). Defaults to `false`. */
44 trimOutputRight?: boolean;
45 /** Similar to `trimOutputRight`, whereas the `\n` is exclusive. Defaults to `false`. See Whitespace Control for details. */
46 trimOutputLeft?: boolean;
47 /** The left delimiter for liquid tags. **/
48 tagDelimiterLeft?: string;
49 /** The right delimiter for liquid tags. **/
50 tagDelimiterRight?: string;
51 /** The left delimiter for liquid outputs. **/
52 outputDelimiterLeft?: string;
53 /** The right delimiter for liquid outputs. **/
54 outputDelimiterRight?: string;
55 /** Whether input strings to date filter preserve the given timezone **/
56 preserveTimezones?: boolean;
57 /** 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`. */
58 greedy?: boolean;
59 /** `fs` is used to override the default file-system module with a custom implementation. */
60 fs?: FS;
61 /** the global scope passed down to all partial and layout templates, i.e. templates included by `include`, `layout` and `render` tags. */
62 globals?: object;
63 /** Whether or not to keep value type when writing the Output, not working for streamed rendering. Defaults to `false`. */
64 keepOutputType?: boolean;
65 /** 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`. */
66 outputEscape?: OutputEscapeOption;
67 /** An object of operators for conditional statements. Defaults to the regular Liquid operators. */
68 operators?: Operators;
69 /** Respect parameter order when using filters like "for ... reversed limit", Defaults to `false`. */
70 orderedFilterParameters?: boolean;
71}
72export interface RenderOptions {
73 /**
74 * This call is sync or async? It's used by Liquid internal methods, you'll not need this.
75 */
76 sync?: boolean;
77 /**
78 * Same as `globals` on LiquidOptions, but only for current render() call
79 */
80 globals?: object;
81 /**
82 * Same as `strictVariables` on LiquidOptions, but only for current render() call
83 */
84 strictVariables?: boolean;
85 /**
86 * Same as `ownPropertyOnly` on LiquidOptions, but only for current render() call
87 */
88 ownPropertyOnly?: boolean;
89}
90export interface RenderFileOptions extends RenderOptions {
91 lookupType?: LookupType;
92}
93interface NormalizedOptions extends LiquidOptions {
94 root?: string[];
95 partials?: string[];
96 layouts?: string[];
97 cache?: LiquidCache;
98 outputEscape?: OutputEscape;
99}
100export interface NormalizedFullOptions extends NormalizedOptions {
101 root: string[];
102 partials: string[];
103 layouts: string[];
104 relativeReference: boolean;
105 jekyllInclude: boolean;
106 extname: string;
107 cache?: LiquidCache;
108 jsTruthy: boolean;
109 dynamicPartials: boolean;
110 fs: FS;
111 strictFilters: boolean;
112 strictVariables: boolean;
113 ownPropertyOnly: boolean;
114 lenientIf: boolean;
115 dateFormat: string;
116 trimTagRight: boolean;
117 trimTagLeft: boolean;
118 trimOutputRight: boolean;
119 trimOutputLeft: boolean;
120 tagDelimiterLeft: string;
121 tagDelimiterRight: string;
122 outputDelimiterLeft: string;
123 outputDelimiterRight: string;
124 preserveTimezones: boolean;
125 greedy: boolean;
126 globals: object;
127 keepOutputType: boolean;
128 operators: Operators;
129}
130export declare const defaultOptions: NormalizedFullOptions;
131export declare function normalize(options: LiquidOptions): NormalizedFullOptions;
132export declare function normalizeDirectoryList(value: any): string[];
133export {};