Allow standalone usage and fix tests.

This commit is contained in:
Marcin Wisnicki
2014-01-05 17:55:03 +01:00
parent 9da84a1ed5
commit 0d2d660e7a
2 changed files with 64 additions and 27 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
/// <reference path='../underscore/underscore.d.ts' />
/// <reference path='underscore.string.d.ts' />
_.mixin(_['string'].exports());
_.mixin(_.string.exports());
interface UnderscoreStatic extends UnderscoreStringStaticExports { }
_.numberFormat(1000, 2);
_.numberFormat(123456789.123, 5, '.', ',');
+62 -26
View File
@@ -4,6 +4,45 @@
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface UnderscoreStatic {
str: UnderscoreStringStatic;
string: UnderscoreStringStatic;
}
interface UnderscoreStringStatic extends UnderscoreStringStaticExports {
/**
* Tests if string contains a substring.
* ('foobar', 'ob') => true
* @param str
* @param needle
*/
include(str: string, needle: string): boolean;
/**
* Tests if string contains a substring.
* ('foobar', 'ob') => true
* @param str
* @param needle
*/
contains(str: string, needle: string): boolean;
/**
* Return reversed string.
* ('foobar') => 'raboof'
* @param str
*/
reverse(str: string): string;
}
/**
* Functions exported for mixing with underscore object.
*
* Usage:
* _.mixin(_.string.exports());
* interface UnderscoreStatic extends UnderscoreStringStaticExports { }
*/
interface UnderscoreStringStaticExports {
exports(): UnderscoreStringStaticExports;
/**
* Determine if a string is 'blank.'
@@ -98,22 +137,6 @@ interface UnderscoreStatic {
*/
insert(str: string, i: number, substr: string): string;
/**
* Tests if string contains a substring.
* ('foobar', 'ob') => true
* @param str
* @param needle
*/
include(str: string, needle: string): boolean;
/**
* Tests if string contains a substring.
* ('foobar', 'ob') => true
* @param str
* @param needle
*/
contains(str: string, needle: string): boolean;
/**
* Joins strings together with given separator.
* (' ', 'foo', 'bar') => 'foo bar'
@@ -129,13 +152,6 @@ interface UnderscoreStatic {
*/
lines(str: string): any[];
/**
* Return reversed string.
* ('foobar') => 'raboof'
* @param str
*/
reverse(str: string): string;
/**
* Checks if string starts with another string.
* ('image.gif', 'image') => true
@@ -279,7 +295,27 @@ interface UnderscoreStatic {
* @param str
* @param delimiter
*/
words(str: string, delimiter?: string): any[];
words(str: string): string[];
/**
* Split string by delimiter (String or RegExp).
* /\s+/ by default.
* (' I love you ') => ['I','love','you']
* ('I_love_you', '_') => ['I','love','you']
* @param str
* @param delimiter
*/
words(str: string, delimiter: string): string[];
/**
* Split string by delimiter (String or RegExp).
* /\s+/ by default.
* (' I love you ') => ['I','love','you']
* ('I_love_you', '_') => ['I','love','you']
* @param str
* @param delimiter
*/
words(str: string, delimiter: RegExp): string[];
/**
* Pads a string with characters until the total string length is equal to the passed length parameter.
@@ -295,7 +331,7 @@ interface UnderscoreStatic {
* @param padStr
* @param type
*/
pad(str: string, length: number, padStr:string, type?: string): string;
pad(str: string, length: number, padStr?:string, type?: string): string;
/**
* Left-pad a string.
@@ -527,4 +563,4 @@ interface UnderscoreStatic {
}
// TODO interface Underscore<T>
// TODO interface UnderscoreString extends Underscore<string>