diff --git a/ejs/ejs-tests.ts b/ejs/ejs-tests.ts new file mode 100644 index 0000000000..fd03dd1e09 --- /dev/null +++ b/ejs/ejs-tests.ts @@ -0,0 +1,4 @@ +/// +import ejs = require("ejs"); +var people = ['geddy', 'neil', 'alex']; +var html = ejs.render('<%= people.join(", "); %>', { people: people }); diff --git a/ejs/ejs.d.ts b/ejs/ejs.d.ts new file mode 100644 index 0000000000..56e755a460 --- /dev/null +++ b/ejs/ejs.d.ts @@ -0,0 +1,91 @@ +// Type definitions for ejs.js v2.3.3 +// Project: http://ejs.co/ +// Definitions by: Ben Liddicott +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +declare module "ejs" { + namespace Ejs { + type Data = { [name: string]: any }; + type Dependencies = string[]; + var cache: Cache; + var localsName: string; + function resolveInclude(name: string, filename: string): string; + function compile(template: string, opts?: Options): (TemplateFunction); + function render(template: string, data?: Data, opts?: Options): string; + function renderFile(path: string, data?: Data, opts?: Options, cb?: Function): any;// TODO RenderFileCallback return type + function clearCache(): any; + + function TemplateFunction(data: Data): any; + interface TemplateFunction { + dependencies: Dependencies; + } + interface Options { + cache?: any; + filename?: string; + context?: any; + compileDebug?: boolean; + client?: boolean; + delimiter?: string; + debug?: any; + _with?: boolean; + } + class Template { + constructor(text: string, opts: Options); + opts: Options; + templateText: string; + mode: string; + truncate: boolean; + currentLine: number; + source: string; + dependencies: Dependencies; + createRegex(): RegExp; + compile(): TemplateFunction; + generateSource(): any; + parseTemplateText(): string[]; + scanLine(line: string): any; + + } + module Template { + interface MODES { + EVAL: string; + ESCAPED: string; + RAW: string; + COMMENT: string; + LITERAL: string; + } + } + function escapeRegexChars(s: string): string; + function escapeXML(markup: string): string; + function shallowCopy(to: T1, fro: any): T1; + interface Cache { + _data: { [name: string]: any }; + set(key: string, val: any): any; + get(key: string): any; + } + var cache: Cache; + function resolve(from1: string, to: string): string; + function resolve(from1: string, from2: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, from8: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, from8: string, from9: string, to: string): string; + function resolve(...args: string[]): string; + function normalize(path: string): string; + function isAbsolute(path: string): boolean; + function join(...args: string[]): string; + function relative(from: string, to: string): string; + var sep: string; + var delimiter: string; + function dirname(path: string): string; + function basename(path: string): string; + function extname(path: string): string; + function filter(xs: any, f: any): any; // TODO WHUT? + + + } + export = Ejs; +} \ No newline at end of file diff --git a/static-eval/static-eval-tests.ts b/static-eval/static-eval-tests.ts new file mode 100644 index 0000000000..fe42c3d4d2 --- /dev/null +++ b/static-eval/static-eval-tests.ts @@ -0,0 +1,17 @@ +/// +/// + +import evaluate = require('static-eval'); +import esprima = require('esprima'); +var parse = esprima.parse; + + +var src = '[1,2,3+4*10+n,foo(3+5),obj[""+"x"].y]'; + +var ast = ((parse(src).body[0])).expression; + +console.log(evaluate(ast, { + n: 6, + foo: function (x: number) { return x * 100 }, + obj: { x: { y: 555 } } +})); \ No newline at end of file diff --git a/static-eval/static-eval.d.ts b/static-eval/static-eval.d.ts new file mode 100644 index 0000000000..e44294c27e --- /dev/null +++ b/static-eval/static-eval.d.ts @@ -0,0 +1,16 @@ +// Type definitions for static-eval v0.2.4 +// Project: https://github.com/substack/static-eval +// Definitions by: Ben Liddicott +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module 'static-eval' { + /** + * Evaluates the given ESTree.Expression, with the given named variables in place. + * @param ast [ESTree.Expression] An esprima expression derived from parse.body[].expression + * @param vars Named variables, objects or functions which may be referenced in the expression. + */ + function evaluate(ast : ESTree.Expression, vars: { [name: string]: any }): any; + export =evaluate; +}