Adding Type definitions for Teddy

This commit is contained in:
Benjamin Lannon
2018-08-25 15:22:30 -04:00
parent 00f8143ceb
commit ccdb2edb02
4 changed files with 104 additions and 0 deletions

57
types/teddy/index.d.ts vendored Normal file
View File

@@ -0,0 +1,57 @@
// Type definitions for teddy 0.4
// Project: https://github.com/rooseveltframework/teddy
// Definitions by: Benjamin Lannon <https://github.com/lannonbr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// compiles a template
export function compile(template: string): string;
// parses a template
export function render(template: string, model: object): string;
// mutator method to set template root param; must be a string
export function setTemplateRoot(path: string): void;
// mutator method to set verbosity param. takes human-readable string argument and converts it to an integer for more efficient checks against the setting
export function setVerbosity(n: number | string): void;
// turn on or off the setting to cache template renders
export function cacheRenders(b: boolean): void;
// mutator method to set default caches param: the number of cached versions of each templates to store by default if cacheRenders is enabled
export function setDefaultCaches(n: number): void;
// mutator method to set max caches for a given registered template
export function setMaxCaches(template: string, n: number): void;
// mutator method to set a whitelist of templates to cache, e.g. { "myTemplate.html": maxCaches} where maxCaches is an integer
export function setCacheWhitelist(o: object): void;
// mutator method to set a blacklist of templates not to cache as an array
export function setCacheBlacklist(templateArray: ReadonlyArray<string>): void;
// sets all params to their default values
export function setDefaultParams(): void;
// invalidates cache of a given template and model combination
// if no model is supplied, deletes all caches of the given template
export function flushCache(template: string, model?: object): void;
// mutator method to set max passes param: the number of times the parser can iterate over the template
export function setMaxPasses(n: number): void;
// turn on or off the setting to compile templates at every render
export function compileAtEveryRender(b: boolean): void;
// turn on or off the setting to minify templates using teddy's internal minifier
export function minify(b: boolean): void;
// default values for parameters sent to teddy
export let params: object;
// compiled templates are stored as object collections, e.g. { "myTemplate.html": "<p>some markup</p>"}
export let templates: object;
// cache of fully rendered temmplates, e.g. { "myTemplate.html": "<p>some markup</p>"}
export let renderedTemplates: object;

View File

@@ -0,0 +1,30 @@
import * as teddy from "teddy";
teddy.compile("template.html");
const markup = teddy.render("template.html", {});
teddy.setTemplateRoot("~/");
teddy.setVerbosity(3);
teddy.cacheRenders(true);
teddy.setDefaultCaches(2);
teddy.setMaxCaches("template.html", 2);
teddy.setCacheWhitelist({ "template.html": 5 });
teddy.setCacheBlacklist(["template1.html", "template2.html"]);
teddy.setDefaultParams();
teddy.flushCache("template.html");
teddy.flushCache("template.html", {});
teddy.setMaxPasses(500);
teddy.compileAtEveryRender(true);
teddy.minify(false);

16
types/teddy/tsconfig.json Normal file
View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "teddy-tests.ts"]
}

1
types/teddy/tslint.json Normal file
View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }