Merge pull request #5863 from benliddicott/master

Add typings for static-eval npm and ejs npm
This commit is contained in:
Masahiro Wakame
2015-09-27 12:55:56 +09:00
4 changed files with 128 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
/// <reference path="ejs.d.ts"/>
import ejs = require("ejs");
var people = ['geddy', 'neil', 'alex'];
var html = ejs.render('<%= people.join(", "); %>', { people: people });
+91
View File
@@ -0,0 +1,91 @@
// Type definitions for ejs.js v2.3.3
// Project: http://ejs.co/
// Definitions by: Ben Liddicott <https://github.com/benliddicott/DefinitelyTyped>
// 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<T1>(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;
}
+17
View File
@@ -0,0 +1,17 @@
/// <reference path="../esprima/esprima.d.ts" />
/// <reference path="static-eval.d.ts" />
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 = (<ESTree.ExpressionStatement>(parse(src).body[0])).expression;
console.log(evaluate(ast, {
n: 6,
foo: function (x: number) { return x * 100 },
obj: { x: { y: 555 } }
}));
+16
View File
@@ -0,0 +1,16 @@
// Type definitions for static-eval v0.2.4
// Project: https://github.com/substack/static-eval
// Definitions by: Ben Liddicott <https://github.com/benliddicott/DefinitelyTyped>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../esprima/esprima.d.ts" />
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;
}