From 85ed772c92df82221ac132a0e9d33c561c31c184 Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 09:44:54 +0900 Subject: [PATCH 01/19] Cleanup unnecessary rule invalidation setting --- types/ejs/tslint.json | 67 +------------------------------------------ 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/types/ejs/tslint.json b/types/ejs/tslint.json index a41bf5d19a..95db3aea31 100644 --- a/types/ejs/tslint.json +++ b/types/ejs/tslint.json @@ -1,79 +1,14 @@ { "extends": "dtslint/dt.json", "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, "callable-types": false, - "comment-format": false, "dt-header": false, - "eofline": false, "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false + "unified-signatures": false } } From 326da556b0920c36bc290bb32bf5cf4acfc0d183 Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 09:49:25 +0900 Subject: [PATCH 02/19] Cleanup lint ignore error: dt-header --- types/ejs/index.d.ts | 4 ++-- types/ejs/tslint.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index a5bfb23ee9..8eae387b06 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for ejs.js v2.3.3 +// Type definitions for ejs.js 2.3 // Project: http://ejs.co/ -// Definitions by: Ben Liddicott +// Definitions by: Ben Liddicott // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace Ejs { diff --git a/types/ejs/tslint.json b/types/ejs/tslint.json index 95db3aea31..6c97118099 100644 --- a/types/ejs/tslint.json +++ b/types/ejs/tslint.json @@ -2,7 +2,6 @@ "extends": "dtslint/dt.json", "rules": { "callable-types": false, - "dt-header": false, "export-just-namespace": false, "interface-over-type-literal": false, "no-padding": false, From d22dd362f4defa0656a364ee416dfdcc473e57cd Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 09:51:00 +0900 Subject: [PATCH 03/19] Cleanup lint error: no-padding --- types/ejs/index.d.ts | 1 - types/ejs/tslint.json | 1 - 2 files changed, 2 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index 8eae387b06..c1c1969be3 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -46,7 +46,6 @@ declare namespace Ejs { generateSource(): any; parseTemplateText(): string[]; scanLine(line: string): any; - } namespace Template { interface MODES { diff --git a/types/ejs/tslint.json b/types/ejs/tslint.json index 6c97118099..d01f83708a 100644 --- a/types/ejs/tslint.json +++ b/types/ejs/tslint.json @@ -4,7 +4,6 @@ "callable-types": false, "export-just-namespace": false, "interface-over-type-literal": false, - "no-padding": false, "no-var-keyword": false, "object-literal-shorthand": false, "prefer-const": false, From 8f627efc6476dd4ef9e7cd3addbc6af436237bff Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 09:52:18 +0900 Subject: [PATCH 04/19] Cleanup lint ignore error: callable-types --- types/ejs/index.d.ts | 4 +--- types/ejs/tslint.json | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index c1c1969be3..5a52399e17 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -19,9 +19,7 @@ declare namespace Ejs { function clearCache(): any; - interface TemplateFunction { - (data: Data): any; - } + type TemplateFunction = (data: Data) => any; interface Options { cache?: any; filename?: string; diff --git a/types/ejs/tslint.json b/types/ejs/tslint.json index d01f83708a..001a94fd06 100644 --- a/types/ejs/tslint.json +++ b/types/ejs/tslint.json @@ -1,7 +1,6 @@ { "extends": "dtslint/dt.json", "rules": { - "callable-types": false, "export-just-namespace": false, "interface-over-type-literal": false, "no-var-keyword": false, From dd60fa13a8f28fdde72de494ae6e42ba10d14bcb Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 09:53:35 +0900 Subject: [PATCH 05/19] Cleanup lint ignore error: prefer-const --- types/ejs/ejs-tests.ts | 4 ++-- types/ejs/tslint.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/types/ejs/ejs-tests.ts b/types/ejs/ejs-tests.ts index b5b46f03b5..f7ad42ab73 100644 --- a/types/ejs/ejs-tests.ts +++ b/types/ejs/ejs-tests.ts @@ -1,3 +1,3 @@ import ejs = require("ejs"); -var people = ['geddy', 'neil', 'alex']; -var html = ejs.render('<%= people.join(", "); %>', { people: people }); +const people = ['geddy', 'neil', 'alex']; +const html = ejs.render('<%= people.join(", "); %>', { people: people }); diff --git a/types/ejs/tslint.json b/types/ejs/tslint.json index 001a94fd06..f697c232f4 100644 --- a/types/ejs/tslint.json +++ b/types/ejs/tslint.json @@ -5,7 +5,6 @@ "interface-over-type-literal": false, "no-var-keyword": false, "object-literal-shorthand": false, - "prefer-const": false, "unified-signatures": false } } From 57f6d33af3bc0d6796eb1199802c5007138e57b2 Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 09:54:56 +0900 Subject: [PATCH 06/19] Cleanup lint ignore error: no-var-keyword --- types/ejs/index.d.ts | 8 ++++---- types/ejs/tslint.json | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index 5a52399e17..7532fbd3cc 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -6,8 +6,8 @@ declare namespace Ejs { type Data = { [name: string]: any }; type Dependencies = string[]; - var cache: Cache; - var localsName: string; + let cache: Cache; + let 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; @@ -76,8 +76,8 @@ declare namespace Ejs { function isAbsolute(path: string): boolean; function join(...args: string[]): string; function relative(from: string, to: string): string; - var sep: string; - var delimiter: string; + let sep: string; + let delimiter: string; function dirname(path: string): string; function basename(path: string): string; function extname(path: string): string; diff --git a/types/ejs/tslint.json b/types/ejs/tslint.json index f697c232f4..06b9038d96 100644 --- a/types/ejs/tslint.json +++ b/types/ejs/tslint.json @@ -3,7 +3,6 @@ "rules": { "export-just-namespace": false, "interface-over-type-literal": false, - "no-var-keyword": false, "object-literal-shorthand": false, "unified-signatures": false } From 33d331a29745e77550f90deef9246691bc9c45b2 Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 09:59:13 +0900 Subject: [PATCH 07/19] cleanup lint ignore error: export-just-namespace --- types/ejs/index.d.ts | 152 ++++++++++++++++++++---------------------- types/ejs/tslint.json | 1 - 2 files changed, 74 insertions(+), 79 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index 7532fbd3cc..0fade248a9 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -3,85 +3,81 @@ // Definitions by: Ben Liddicott // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare namespace Ejs { - type Data = { [name: string]: any }; - type Dependencies = string[]; - let cache: Cache; - let 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; +export type Data = { [name: string]: any }; +export type Dependencies = string[]; +export let cache: Cache; +export let localsName: string; +export function resolveInclude(name: string, filename: string): string; +export function compile(template: string, opts?: Options): (TemplateFunction); +export function render(template: string, data?: Data, opts?: Options): string; - type RenderFileCallback = (err: Error, str?: string) => T; - function renderFile(path: string, cb: RenderFileCallback): T; - function renderFile(path: string, data: Data, cb: RenderFileCallback): T; - function renderFile(path: string, data: Data, opts: Options, cb: RenderFileCallback): T; +export type RenderFileCallback = (err: Error, str?: string) => T; +export function renderFile(path: string, cb: RenderFileCallback): T; +export function renderFile(path: string, data: Data, cb: RenderFileCallback): T; +export function renderFile(path: string, data: Data, opts: Options, cb: RenderFileCallback): T; - function clearCache(): any; +export function clearCache(): any; - type TemplateFunction = (data: Data) => any; - 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; - } - namespace 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; - } - 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; - let sep: string; - let 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 type TemplateFunction = (data: Data) => any; +export interface Options { + cache?: any; + filename?: string; + context?: any; + compileDebug?: boolean; + client?: boolean; + delimiter?: string; + debug?: any; + _with?: boolean; } - -export = Ejs; +export 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; +} +export namespace Template { + interface MODES { + EVAL: string; + ESCAPED: string; + RAW: string; + COMMENT: string; + LITERAL: string; + } +} +export function escapeRegexChars(s: string): string; +export function escapeXML(markup: string): string; +export function shallowCopy(to: T1, fro: any): T1; +export interface Cache { + _data: { [name: string]: any }; + set(key: string, val: any): any; + get(key: string): any; +} +export function resolve(from1: string, to: string): string; +export function resolve(from1: string, from2: string, to: string): string; +export function resolve(from1: string, from2: string, from3: string, to: string): string; +export function resolve(from1: string, from2: string, from3: string, from4: string, to: string): string; +export function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, to: string): string; +export function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, to: string): string; +export function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, to: string): string; +export function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, from8: string, to: string): string; +export function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, from8: string, from9: string, to: string): string; +export function resolve(...args: string[]): string; +export function normalize(path: string): string; +export function isAbsolute(path: string): boolean; +export function join(...args: string[]): string; +export function relative(from: string, to: string): string; +export let sep: string; +export let delimiter: string; +export function dirname(path: string): string; +export function basename(path: string): string; +export function extname(path: string): string; +export function filter(xs: any, f: any): any; // TODO WHUT? diff --git a/types/ejs/tslint.json b/types/ejs/tslint.json index 06b9038d96..a3126dd180 100644 --- a/types/ejs/tslint.json +++ b/types/ejs/tslint.json @@ -1,7 +1,6 @@ { "extends": "dtslint/dt.json", "rules": { - "export-just-namespace": false, "interface-over-type-literal": false, "object-literal-shorthand": false, "unified-signatures": false From a9b2387bce0ff711a7c3543e705e91b9dbad2c1e Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 10:01:17 +0900 Subject: [PATCH 08/19] Cleanup lint ignore error: interface-over-type-literal --- types/ejs/index.d.ts | 4 +++- types/ejs/tslint.json | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index 0fade248a9..b7a8c6a191 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -3,7 +3,9 @@ // Definitions by: Ben Liddicott // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export type Data = { [name: string]: any }; +export interface Data { + [name: string]: any; +} export type Dependencies = string[]; export let cache: Cache; export let localsName: string; diff --git a/types/ejs/tslint.json b/types/ejs/tslint.json index a3126dd180..ffc654f941 100644 --- a/types/ejs/tslint.json +++ b/types/ejs/tslint.json @@ -1,7 +1,6 @@ { "extends": "dtslint/dt.json", "rules": { - "interface-over-type-literal": false, "object-literal-shorthand": false, "unified-signatures": false } From eeb464569d58173070ecd79a0beb6707bc2498c4 Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 12:00:35 +0900 Subject: [PATCH 09/19] There is no resolve(). --- types/ejs/index.d.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index b7a8c6a191..76a47ca94c 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -63,16 +63,6 @@ export interface Cache { set(key: string, val: any): any; get(key: string): any; } -export function resolve(from1: string, to: string): string; -export function resolve(from1: string, from2: string, to: string): string; -export function resolve(from1: string, from2: string, from3: string, to: string): string; -export function resolve(from1: string, from2: string, from3: string, from4: string, to: string): string; -export function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, to: string): string; -export function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, to: string): string; -export function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, to: string): string; -export function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, from8: string, to: string): string; -export function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, from8: string, from9: string, to: string): string; -export function resolve(...args: string[]): string; export function normalize(path: string): string; export function isAbsolute(path: string): boolean; export function join(...args: string[]): string; From 996c9c0db36aba5406bb84e7b7da69cfabca3b51 Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 13:07:06 +0900 Subject: [PATCH 10/19] Add Options. --- types/ejs/index.d.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index 76a47ca94c..7918de773a 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -22,14 +22,19 @@ export function clearCache(): any; export type TemplateFunction = (data: Data) => any; export interface Options { - cache?: any; + cache?: boolean; filename?: string; + root?: string; context?: any; compileDebug?: boolean; client?: boolean; delimiter?: string; - debug?: any; + debug?: boolean; + strict?: boolean; _with?: boolean; + localsName?: string; + rmWhitespace?: boolean; + escape?(str: string): string; } export class Template { constructor(text: string, opts: Options); From 5d9f85b6934b9487354930b0bf646e291f125970 Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 13:07:34 +0900 Subject: [PATCH 11/19] Delete Not API class --- types/ejs/index.d.ts | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index 7918de773a..a64deb7ded 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -36,30 +36,7 @@ export interface Options { rmWhitespace?: boolean; escape?(str: string): string; } -export 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; -} -export namespace Template { - interface MODES { - EVAL: string; - ESCAPED: string; - RAW: string; - COMMENT: string; - LITERAL: string; - } -} + export function escapeRegexChars(s: string): string; export function escapeXML(markup: string): string; export function shallowCopy(to: T1, fro: any): T1; From b6df77415caf3bf4703e85f939483641ee84b75d Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 13:38:46 +0900 Subject: [PATCH 12/19] Delete unexported export --- types/ejs/index.d.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index a64deb7ded..49d1cb368b 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -6,7 +6,6 @@ export interface Data { [name: string]: any; } -export type Dependencies = string[]; export let cache: Cache; export let localsName: string; export function resolveInclude(name: string, filename: string): string; @@ -39,19 +38,9 @@ export interface Options { export function escapeRegexChars(s: string): string; export function escapeXML(markup: string): string; -export function shallowCopy(to: T1, fro: any): T1; export interface Cache { _data: { [name: string]: any }; set(key: string, val: any): any; get(key: string): any; } -export function normalize(path: string): string; -export function isAbsolute(path: string): boolean; -export function join(...args: string[]): string; -export function relative(from: string, to: string): string; -export let sep: string; export let delimiter: string; -export function dirname(path: string): string; -export function basename(path: string): string; -export function extname(path: string): string; -export function filter(xs: any, f: any): any; // TODO WHUT? From cd4e399afff7203e02201a629fe9a833598bca99 Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 13:52:23 +0900 Subject: [PATCH 13/19] ADD JSDoc and add isDir from resolveInclude(). and typed clearCache(). --- types/ejs/index.d.ts | 89 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index 49d1cb368b..771ab220e6 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -2,45 +2,124 @@ // Project: http://ejs.co/ // Definitions by: Ben Liddicott // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 export interface Data { [name: string]: any; } +/** + * EJS template function cache. This can be a LRU object from lru-cache NPM + * module. By default, it is {@link module:utils.cache}, a simple in-process + * cache that grows continuously. + */ export let cache: Cache; +/** + * Name of the object containing the locals. + * + * This variable is overridden by {@link Options}`.localsName` if it is not + * `undefined`. + */ export let localsName: string; -export function resolveInclude(name: string, filename: string): string; +/** + * Get the path to the included file from the parent file path and the + * specified path. + */ +export function resolveInclude(name: string, filename: string, isDir: boolean): string; +/** + * Compile the given `str` of ejs into a template function. + */ export function compile(template: string, opts?: Options): (TemplateFunction); +/** + * Render the given `template` of ejs. + * + * If you would like to include options but not data, you need to explicitly + * call this function with `data` being an empty object or `null`. + */ export function render(template: string, data?: Data, opts?: Options): string; export type RenderFileCallback = (err: Error, str?: string) => T; + +/** + * Render an EJS file at the given `path` and callback `cb(err, str)`. + * + * If you would like to include options but not data, you need to explicitly + * call this function with `data` being an empty object or `null`. + */ export function renderFile(path: string, cb: RenderFileCallback): T; export function renderFile(path: string, data: Data, cb: RenderFileCallback): T; export function renderFile(path: string, data: Data, opts: Options, cb: RenderFileCallback): T; -export function clearCache(): any; +/** + * Clear intermediate JavaScript cache. Calls {@link Cache#reset}. + */ +export function clearCache(): void; export type TemplateFunction = (data: Data) => any; export interface Options { + /** Compiled functions are cached, requires `filename` */ cache?: boolean; + /** + * The name of the file being rendered. Not required if you are using `renderFile()`. + * Used by `cache` to key caches, and for includes. + */ filename?: string; + /** Set project root for includes with an absolute path (/file.ejs). */ root?: string; + /** Function execution context */ context?: any; + /** When `false` no debug instrumentation is compiled */ compileDebug?: boolean; + /** When `true`, compiles a function that can be rendered in the browser without needing to load the EJS Runtime (ejs.min.js). */ client?: boolean; + /** Character to use with angle brackets for open/close */ delimiter?: string; + /** Output generated function body */ debug?: boolean; + /** When set to `true`, generated function is in strict mode */ strict?: boolean; + /** + * Whether or not to use `with() {}` constructs. + * If `false` then the locals will be stored in the `locals` object. Set to `false` in strict mode. + */ _with?: boolean; + /** Name to use for the object storing local variables when not using `with` Defaults to `locals` */ localsName?: string; + /** + * Remove all safe-to-remove whitespace, including leading and trailing whitespace. + * It also enables a safer version of `-%>` line slurping for all scriptlet tags (it does not strip new lines of tags in the middle of a line). + */ rmWhitespace?: boolean; + /** + * The escaping function used with `<%=` construct. + * It is used in rendering and is `.toString()`ed in the generation of client functions. + * (By default escapes XML). + */ escape?(str: string): string; } export function escapeRegexChars(s: string): string; +/** + * Escape characters reserved in XML. + * + * This is simply an export of {@link module:utils.escapeXML}. + * + * If `markup` is `undefined` or `null`, the empty string is returned. + */ export function escapeXML(markup: string): string; export interface Cache { - _data: { [name: string]: any }; - set(key: string, val: any): any; - get(key: string): any; + _data: { [name: string]: TemplateFunction; }; + set(key: string, val: TemplateFunction): TemplateFunction; + get(key: string): TemplateFunction; } export let delimiter: string; + +/** + * Custom file loader. Useful for template preprocessing or restricting access + * to a certain part of the filesystem. + */ +export function fileLoader(filePath: string): string; + +/** + * Name for detection of EJS. + */ +export const name = "ejs"; From b8cabc4f9961690607009150de7e7eca79bbaadc Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 13:55:09 +0900 Subject: [PATCH 14/19] Add Tests and Cleanup ignore lint errors --- types/ejs/ejs-tests.ts | 34 +++++++++++++++++++++++++++++++++- types/ejs/tslint.json | 8 +------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/types/ejs/ejs-tests.ts b/types/ejs/ejs-tests.ts index f7ad42ab73..8c6dae9965 100644 --- a/types/ejs/ejs-tests.ts +++ b/types/ejs/ejs-tests.ts @@ -1,3 +1,35 @@ import ejs = require("ejs"); +import * as fs from 'graceful-fs'; + +const fileName = 'test.ejs'; const people = ['geddy', 'neil', 'alex']; -const html = ejs.render('<%= people.join(", "); %>', { people: people }); +const data = { people }; +const template = '<%= people.join(", "); %>'; +const options = {delimiter: '$'}; +let result: string; +let cacheResult: string; +let ejsFunction: ejs.TemplateFunction; + +const SimpleCallback = (err: any, html?: string) => { + if (err) { + return null; + } + return html; +}; + +result = ejs.render(template); +result = ejs.render(template, data); +result = ejs.render(template, data, options); + +cacheResult = ejs.renderFile(fileName, SimpleCallback); +cacheResult = ejs.renderFile(fileName, data, SimpleCallback); +cacheResult = ejs.renderFile(fileName, data, options, SimpleCallback); + +ejsFunction = ejs.compile(template); +ejsFunction({}); +ejsFunction(data); +ejs.compile(template, options); + +ejs.fileLoader = (str: string) => str; + +ejs.clearCache(); diff --git a/types/ejs/tslint.json b/types/ejs/tslint.json index ffc654f941..3db14f85ea 100644 --- a/types/ejs/tslint.json +++ b/types/ejs/tslint.json @@ -1,7 +1 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "object-literal-shorthand": false, - "unified-signatures": false - } -} +{ "extends": "dtslint/dt.json" } From ae1ea523661007e218fc57e903e58859fafc431d Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 14:03:37 +0900 Subject: [PATCH 15/19] Fixed Cache methods --- types/ejs/ejs-tests.ts | 4 ++++ types/ejs/index.d.ts | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/types/ejs/ejs-tests.ts b/types/ejs/ejs-tests.ts index 8c6dae9965..40c610dd59 100644 --- a/types/ejs/ejs-tests.ts +++ b/types/ejs/ejs-tests.ts @@ -1,5 +1,7 @@ import ejs = require("ejs"); import * as fs from 'graceful-fs'; +import LRU = require("lru-cache"); +import { TemplateFunction } from "ejs"; const fileName = 'test.ejs'; const people = ['geddy', 'neil', 'alex']; @@ -33,3 +35,5 @@ ejs.compile(template, options); ejs.fileLoader = (str: string) => str; ejs.clearCache(); + +ejs.cache = LRU(100); diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index 771ab220e6..9d1294e681 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -107,8 +107,7 @@ export function escapeRegexChars(s: string): string; */ export function escapeXML(markup: string): string; export interface Cache { - _data: { [name: string]: TemplateFunction; }; - set(key: string, val: TemplateFunction): TemplateFunction; + set(key: string, val: TemplateFunction): void; get(key: string): TemplateFunction; } export let delimiter: string; From a8f40e9d04cdd6db77b40eae834f875de91e1caa Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 24 Nov 2017 14:13:23 +0900 Subject: [PATCH 16/19] remove test import graceful-fs --- types/ejs/ejs-tests.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/ejs/ejs-tests.ts b/types/ejs/ejs-tests.ts index 40c610dd59..89b0479529 100644 --- a/types/ejs/ejs-tests.ts +++ b/types/ejs/ejs-tests.ts @@ -1,5 +1,4 @@ import ejs = require("ejs"); -import * as fs from 'graceful-fs'; import LRU = require("lru-cache"); import { TemplateFunction } from "ejs"; From 21390eeb9a0eebdf1cfb4ad7473af3a267b006ad Mon Sep 17 00:00:00 2001 From: segayuu Date: Mon, 27 Nov 2017 11:15:52 +0900 Subject: [PATCH 17/19] data is not absolutely necessary. https://github.com/mde/ejs/blob/v2.5.7/test/ejs.js#L58 --- types/ejs/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index 9d1294e681..c395e54533 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -54,7 +54,7 @@ export function renderFile(path: string, data: Data, opts: Options, cb: Rende */ export function clearCache(): void; -export type TemplateFunction = (data: Data) => any; +export type TemplateFunction = (data?: Data) => string; export interface Options { /** Compiled functions are cached, requires `filename` */ cache?: boolean; From f29db221d658d323b9989638dacb12d8bab32592 Mon Sep 17 00:00:00 2001 From: segayuu Date: Mon, 27 Nov 2017 11:16:29 +0900 Subject: [PATCH 18/19] Add tests --- types/ejs/ejs-tests.ts | 47 +++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/types/ejs/ejs-tests.ts b/types/ejs/ejs-tests.ts index 89b0479529..a7b7b66944 100644 --- a/types/ejs/ejs-tests.ts +++ b/types/ejs/ejs-tests.ts @@ -1,15 +1,17 @@ +/// + import ejs = require("ejs"); +import { readFileSync as read } from 'fs'; import LRU = require("lru-cache"); -import { TemplateFunction } from "ejs"; +import { TemplateFunction, Options } from "ejs"; const fileName = 'test.ejs'; const people = ['geddy', 'neil', 'alex']; const data = { people }; const template = '<%= people.join(", "); %>'; -const options = {delimiter: '$'}; +const options = { filename: fileName }; let result: string; -let cacheResult: string; -let ejsFunction: ejs.TemplateFunction; +let ejsFunction: TemplateFunction; const SimpleCallback = (err: any, html?: string) => { if (err) { @@ -22,17 +24,38 @@ result = ejs.render(template); result = ejs.render(template, data); result = ejs.render(template, data, options); -cacheResult = ejs.renderFile(fileName, SimpleCallback); -cacheResult = ejs.renderFile(fileName, data, SimpleCallback); -cacheResult = ejs.renderFile(fileName, data, options, SimpleCallback); +result = ejs.renderFile(fileName, SimpleCallback); +result = ejs.renderFile(fileName, data, SimpleCallback); +result = ejs.renderFile(fileName, data, options, SimpleCallback); +ejsFunction = ejs.compile(''); +ejsFunction = ejs.compile(read(fileName, "utf8")); ejsFunction = ejs.compile(template); -ejsFunction({}); -ejsFunction(data); -ejs.compile(template, options); +ejsFunction = ejs.compile(template, options); +ejsFunction = ejs.compile(template, { cache: true, filename: fileName }); +ejsFunction = ejs.compile(template, { cache: true, filename: fileName, root: "./" }); +ejsFunction = ejs.compile(template, { context: { foo: 'FOO' } }); +ejsFunction = ejs.compile(template, { compileDebug: false }); +ejsFunction = ejs.compile(template, { client: true }); +ejsFunction = ejs.compile('<$= people.join(", "); $>', { delimiter: '$' }); +ejsFunction = ejs.compile('<%= locals.people.join(", "); %>', { _with: false }); +ejsFunction = ejs.compile('<%= locals.people.join(", "); %>', { strict: true }); +ejsFunction = ejs.compile('<%= it.people.join(", "); %>', { _with: false, localsName: "it" }); +ejsFunction = ejs.compile(template, { rmWhitespace: true }); +const customEscape = (str: string) => !str ? '' : str.toUpperCase(); +ejsFunction = ejs.compile(template, { escape: customEscape }); -ejs.fileLoader = (str: string) => str; +result = ejsFunction(); +result = ejsFunction({}); +result = ejsFunction(data); +/** @see https://github.com/mde/ejs/tree/v2.5.7#custom-fileloader */ +ejs.fileLoader = (path: string) => ""; + +/** @see https://github.com/mde/ejs/tree/v2.5.7#caching */ ejs.clearCache(); - ejs.cache = LRU(100); + +/** @see https://github.com/mde/ejs/tree/v2.5.7#custom-delimiters */ +ejs.delimiter = "%"; +delete ejs.delimiter; From a271488804f91c4eda641f2b6b1a7a2475d7d0dd Mon Sep 17 00:00:00 2001 From: segayuu Date: Mon, 27 Nov 2017 11:22:27 +0900 Subject: [PATCH 19/19] version up --- types/ejs/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index c395e54533..e785f2c6ae 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -1,8 +1,8 @@ -// Type definitions for ejs.js 2.3 +// Type definitions for ejs.js 2.5 // Project: http://ejs.co/ // Definitions by: Ben Liddicott // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 2.4 export interface Data { [name: string]: any;