mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
lodash: changed _.template() method
This commit is contained in:
+21
-15
@@ -1721,21 +1721,6 @@ result = <number[]>_(10).range().value();
|
||||
result = <number[]>_(1).range(11).value();
|
||||
result = <number[]>_(0).range(30, 5).value();
|
||||
|
||||
result = <_.TemplateExecutor>_.template('hello <%= name %>');
|
||||
result = <string>_.template('<b><%- value %></b>', { 'value': '<script>' });
|
||||
|
||||
var listTemplate = '<% _.forEach(people, function(name) { %><li><%- name %></li><% }); %>';
|
||||
result = <string>_.template(listTemplate, { 'people': ['moe', 'larry'] });
|
||||
result = <string>_.template('hello ${ name }', { 'name': 'curly' });
|
||||
result = <string>_.template('<% print("hello " + name); %>!', { 'name': 'larry' });
|
||||
|
||||
var listTemplate = '<% $.each(people, function(name) { %><li><%- name %></li><% }); %>';
|
||||
result = <string>_.template(listTemplate, { 'people': ['moe', 'larry'] }, { 'imports': { '$': jQuery } });
|
||||
result = <_.TemplateExecutor>_.template('hello <%= name %>', null, /*sourceURL:*/ '/basic/greeting.jst');
|
||||
|
||||
result = <_.TemplateExecutor>_.template('hi <%= data.name %>!', null, { 'variable': 'data' });
|
||||
result = <string>(<_.TemplateExecutor>result).source;
|
||||
|
||||
class Mage {
|
||||
public castSpell(n: number) {
|
||||
return n;
|
||||
@@ -1836,6 +1821,27 @@ result = <boolean>_.startsWith('abc', 'a', 1);
|
||||
result = <boolean>_('abc').startsWith('a');
|
||||
result = <boolean>_('abc').startsWith('a', 1);
|
||||
|
||||
// _.template
|
||||
interface TestTemplateOptions {
|
||||
escape?: RegExp;
|
||||
evaluate?: RegExp;
|
||||
imports?: _.Dictionary<any>;
|
||||
interpolate?: RegExp;
|
||||
variable?: string;
|
||||
}
|
||||
interface TestTemplateExecutor {
|
||||
(obj?: Object): string;
|
||||
source: string;
|
||||
}
|
||||
{
|
||||
let testTemplateOptions: TestTemplateOptions
|
||||
let result: TestTemplateExecutor;
|
||||
result = _.template('');
|
||||
result = _.template('', testTemplateOptions);
|
||||
result = _('').template();
|
||||
result = _('').template(testTemplateOptions);
|
||||
}
|
||||
|
||||
// _.trim
|
||||
result = <string>_.trim();
|
||||
result = <string>_.trim(' abc ');
|
||||
|
||||
Vendored
+44
-44
@@ -7850,6 +7850,50 @@ declare module _ {
|
||||
startsWith(target?: string, position?: number): boolean;
|
||||
}
|
||||
|
||||
//_.template
|
||||
interface TemplateExecutor {
|
||||
(data?: Object): string;
|
||||
source: string;
|
||||
}
|
||||
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a compiled template function that can interpolate data properties in "interpolate" delimiters,
|
||||
* HTML-escape interpolated data properties in "escape" delimiters, and execute JavaScript in "evaluate"
|
||||
* delimiters. Data properties may be accessed as free variables in the template. If a setting object is
|
||||
* provided it takes precedence over _.templateSettings values.
|
||||
*
|
||||
* Note: In the development build _.template utilizes
|
||||
* [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) for easier
|
||||
* debugging.
|
||||
*
|
||||
* For more information on precompiling templates see
|
||||
* [lodash's custom builds documentation](https://lodash.com/custom-builds).
|
||||
*
|
||||
* For more information on Chrome extension sandboxes see
|
||||
* [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
|
||||
*
|
||||
* @param string The template string.
|
||||
* @param options The options object.
|
||||
* @param options.escape The HTML "escape" delimiter.
|
||||
* @param options.evaluate The "evaluate" delimiter.
|
||||
* @param options.imports An object to import into the template as free variables.
|
||||
* @param options.interpolate The "interpolate" delimiter.
|
||||
* @param options.variable The data object variable name.
|
||||
* @return Returns the compiled template function.
|
||||
*/
|
||||
template(
|
||||
string: string,
|
||||
options?: TemplateSettings): TemplateExecutor;
|
||||
}
|
||||
|
||||
interface LoDashWrapper<T> {
|
||||
/**
|
||||
* @see _.template
|
||||
*/
|
||||
template(options?: TemplateSettings): TemplateExecutor;
|
||||
}
|
||||
|
||||
//_.trim
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
@@ -8214,50 +8258,6 @@ declare module _ {
|
||||
runInContext(context: any): typeof _;
|
||||
}
|
||||
|
||||
//_.template
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* A micro-templating method that handles arbitrary delimiters, preserves whitespace, and
|
||||
* correctly escapes quotes within interpolated code.
|
||||
*
|
||||
* Note: In the development build, _.template utilizes sourceURLs for easier debugging. See
|
||||
* http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
|
||||
*
|
||||
* For more information on precompiling templates see:
|
||||
* http://lodash.com/#custom-builds
|
||||
*
|
||||
* For more information on Chrome extension sandboxes see:
|
||||
* http://developer.chrome.com/stable/extensions/sandboxingEval.html
|
||||
* @param text The template text.
|
||||
* @param data The data object used to populate the text.
|
||||
* @param options The options object.
|
||||
* @param options.escape The "escape" delimiter.
|
||||
* @param options.evaluate The "evaluate" delimiter.
|
||||
* @param options.import An object to import into the template as local variables.
|
||||
* @param options.interpolate The "interpolate" delimiter.
|
||||
* @param sourceURL The sourceURL of the template's compiled source.
|
||||
* @param variable The data object variable name.
|
||||
* @return Returns the compiled Lo-Dash HTML template or a TemplateExecutor if no data is passed.
|
||||
**/
|
||||
template(
|
||||
text: string): TemplateExecutor;
|
||||
|
||||
/**
|
||||
* @see _.template
|
||||
**/
|
||||
template(
|
||||
text: string,
|
||||
data: any,
|
||||
options?: TemplateSettings,
|
||||
sourceURL?: string,
|
||||
variable?: string): any /* string or TemplateExecutor*/;
|
||||
}
|
||||
|
||||
interface TemplateExecutor {
|
||||
(...data: any[]): string;
|
||||
source: string;
|
||||
}
|
||||
|
||||
//_.times
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user