UNPKG

@cloudpss/template

Version:

String and object template engine for Node.js and the browser.

34 lines 1.25 kB
/** 公式模板 */ export type FormulaTemplate = { type: 'formula'; value: string; }; /** 字符串插值模板 */ export type InterpolationTemplate = { type: 'interpolation'; templates: string[]; values: string[]; }; /** 字符串模板 */ export type Template = string | FormulaTemplate | InterpolationTemplate; /** 字符串模板类型 */ export type TemplateType = (Template & object)['type']; /** * 解析字符串插值模板 * @example parseInterpolation("hello $name! I am $age years old. I'll be ${age+1} next year. And $(2*age) after $<age> years.") * // { * // type: 'interpolation', * // templates: ['hello ', '! I am ', ' years old. I\'ll be ', ' next year. And ', ' after ', ' years.'], * // values: ['name', 'age', 'age+1', '2*age', 'age'] * // } */ export declare function parseInterpolation(template: string, start?: number, length?: number): InterpolationTemplate; /** * 解析字符串模板 * - 长度大于 1 * - 如果模板以 `=` 开头,则表示是一个公式 * - 如果模板以 `$` 开头,则表示是一个插值模板 * - 否则表示是一个普通字符串 */ export declare function parseTemplate(template: string): Template; //# sourceMappingURL=parser.d.ts.map