docxtemplater
Version:
docx and pptx generator working with templates and data (like Mustache, for Word and Powerpoint documents)
121 lines (106 loc) • 2.94 kB
TypeScript
export namespace DXT {
type integer = number;
interface SimplePart {
type: string;
value: string;
module?: string;
[x: string]: any;
}
interface Part {
type: string;
value: string;
module: string;
raw: string;
offset: integer;
lIndex: integer;
num: integer;
inverted?: boolean;
endLindex?: integer;
expanded?: Part[];
subparsed?: Part[];
}
interface ScopeManager {
scopeList: any[];
scopeLindex: integer[];
scopePath: string[];
scopePathItem: integer[];
scopePathLength: integer[];
resolved: any;
cachedParsers: Record<string, (scope: any, context: ParserContext) => any>;
parser(tag: string): Parser;
}
interface Rendered {
value: string;
errors: any[];
}
type Error = any;
interface Module {
set?(options: any): void;
parse?(placeHolderContent: string): SimplePart | null;
render?(part: Part): Rendered | null;
getTraits?(traitName: string, parsed: any): any;
getFileType?(opts: any): string;
nullGetter?(part: Part, scopeManager: any): any;
optionsTransformer?(options: Options): Options;
postrender?(parts: string[], options: any): string[];
errorsTransformer?(errors: Error[]): Error[];
getRenderedMap?(map: any): any;
preparse?(parsed: any, options: any): any;
postparse?(postparsed: Part[], modules: Module[], options: any): Part[];
on?(event: string): void;
resolve?(part: Part, options: any): null | Promise<any>;
[x: string]: any;
}
interface ParserContext {
meta: {
part: Part;
};
scopeList: any[];
scopePath: string[];
scopePathItem: integer[];
scopePathLength: integer[];
num: integer;
}
interface Parser {
get(scope: any, context: ParserContext): any;
}
interface ConstructorOptions {
modules?: Module[];
delimiters?: { start: string; end: string };
paragraphLoop?: boolean;
parser?(tag: string): Parser;
linebreaks?: boolean;
nullGetter?(part: Part): any;
}
interface Options {
delimiters?: { start: string; end: string };
paragraphLoop?: boolean;
parser?(tag: string): Parser;
linebreaks?: boolean;
nullGetter?(part: Part): any;
}
}
declare class Docxtemplater {
/**
* Create Docxtemplater instance (and compile it on the fly)
*
* @param zip Serialized zip archive
* @param options modules and other other options
*/
constructor(zip: any, options?: DXT.ConstructorOptions);
/**
* Create Docxtemplater instance, without options
*/
constructor();
setData(data: any): this;
resolveData(data: any): Promise<any>;
render(data?: any): this;
renderAsync(data?: any): Promise<any>;
getZip(): any;
loadZip(zip: any): this;
setOptions(options: DXT.Options): this;
attachModule(module: DXT.Module): this;
compile(): this;
getFullText(path?: string): string;
}
export default Docxtemplater;