File tree Expand file tree Collapse file tree 16 files changed +53
-17
lines changed
lib/node_modules/@stdlib/string Expand file tree Collapse file tree 16 files changed +53
-17
lines changed Original file line number Diff line number Diff line change 18
18
19
19
// TypeScript Version: 4.1
20
20
21
+ type Capitalize < S extends string > = S extends `${infer F } ${infer R } ` ? `${Uppercase < F > } ${R } ` : S ;
22
+
21
23
/**
22
24
* Capitalizes the first character in a string.
23
25
*
40
42
* var out = capitalize( 'Hidden Treasures' );
41
43
* // returns 'Hidden Treasures'
42
44
*/
43
- declare function capitalize ( str : string ) : string ;
45
+ declare function capitalize < S extends string > ( str : S ) : Capitalize < S > ;
44
46
45
47
46
48
// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,11 @@ import capitalize = require( './index' );
23
23
24
24
// The function returns a string...
25
25
{
26
- capitalize ( 'abc' ) ; // $ExpectType string
26
+ capitalize ( 'abc' ) ; // $ExpectType "Abc"
27
+ capitalize ( 'beep boop' ) ; // $ExpectType "Beep boop"
28
+ capitalize ( 'a' ) ; // $ExpectType "A"
29
+ capitalize ( 'A' ) ; // $ExpectType "A"
30
+ capitalize ( 'abc' as string ) ; // $ExpectType string
27
31
}
28
32
29
33
// The compiler throws an error if the function is provided a value other than a string...
Original file line number Diff line number Diff line change 28
28
* var str = lowercase( 'bEEp' );
29
29
* // returns 'beep'
30
30
*/
31
- declare function lowercase ( str : string ) : string ;
31
+ declare function lowercase < S extends string > ( str : S ) : Lowercase < S > ;
32
32
33
33
34
34
// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,9 @@ import lowercase = require( './index' );
23
23
24
24
// The function returns a string...
25
25
{
26
- lowercase ( 'abc' ) ; // $ExpectType string
26
+ lowercase ( 'ABC' ) ; // $ExpectType "abc"
27
+ lowercase ( 'Beep BOOP' ) ; // $ExpectType "beep boop"
28
+ lowercase ( 'abc' as string ) ; // $ExpectType string
27
29
}
28
30
29
31
// The compiler throws an error if the function is provided a value other than a string...
Original file line number Diff line number Diff line change 18
18
19
19
// TypeScript Version: 4.1
20
20
21
+ type Uncapitalize < S extends string > = S extends `${infer F } ${infer R } ` ? `${Lowercase < F > } ${R } ` : S ;
22
+
21
23
/**
22
24
* Uncapitalizes the first character of a string.
23
25
*
40
42
* var out = uncapitalize( 'Hidden Treasures' );
41
43
* // returns 'hidden Treasures'
42
44
*/
43
- declare function uncapitalize ( str : string ) : string ;
45
+ declare function uncapitalize < S extends string > ( str : S ) : Uncapitalize < S > ;
44
46
45
47
46
48
// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,11 @@ import uncapitalize = require( './index' );
23
23
24
24
// The function returns a string...
25
25
{
26
- uncapitalize ( 'Last man standing' ) ; // $ExpectType string
26
+ uncapitalize ( 'Last man standing' ) ; // $ExpectType "last man standing"
27
+ uncapitalize ( 'Hello World!' ) ; // $ExpectType "hello World!"
28
+ uncapitalize ( 'BeepBoop' ) ; // $ExpectType "beepBoop"
29
+ uncapitalize ( 'A' ) ; // $ExpectType "a"
30
+ uncapitalize ( 'foo' as string ) ; // $ExpectType string
27
31
}
28
32
29
33
// The compiler throws an error if the function is provided a value other than a string...
Original file line number Diff line number Diff line change 28
28
* var str = uppercase( 'bEEp' );
29
29
* // returns 'BEEP'
30
30
*/
31
- declare function uppercase ( str : string ) : string ;
31
+ declare function uppercase < S extends string > ( str : S ) : Uppercase < S > ;
32
32
33
33
34
34
// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,11 @@ import uppercase = require( './index' );
23
23
24
24
// The function returns a string...
25
25
{
26
- uppercase ( 'Last man standing' ) ; // $ExpectType string
26
+ uppercase ( 'Last man standing' ) ; // $ExpectType "LAST MAN STANDING"
27
+ uppercase ( 'Hello World!' ) ; // $ExpectType "HELLO WORLD!"
28
+ uppercase ( 'beep' ) ; // $ExpectType "BEEP"
29
+ uppercase ( 'BOOP' ) ; // $ExpectType "BOOP"
30
+ uppercase ( 'foo' as string ) ; // $ExpectType string
27
31
}
28
32
29
33
// The compiler throws an error if the function is provided a value other than a string...
Original file line number Diff line number Diff line change 18
18
19
19
// TypeScript Version: 4.1
20
20
21
+ type Capitalize < S extends string > = S extends `${infer F } ${infer R } ` ? `${Uppercase < F > } ${R } ` : S ;
22
+
21
23
/**
22
24
* Capitalizes the first character in a string.
23
25
*
40
42
* var out = capitalize( 'Hidden Treasures' );
41
43
* // returns 'Hidden Treasures'
42
44
*/
43
- declare function capitalize ( str : string ) : string ;
45
+ declare function capitalize < S extends string > ( str : S ) : Capitalize < S > ;
44
46
45
47
46
48
// EXPORTS //
Original file line number Diff line number Diff line change @@ -21,9 +21,13 @@ import capitalize = require( './index' );
21
21
22
22
// TESTS //
23
23
24
- // The function returns a string...
24
+ // The function returns a capitalized string...
25
25
{
26
- capitalize ( 'abc' ) ; // $ExpectType string
26
+ capitalize ( 'abc' ) ; // $ExpectType "Abc"
27
+ capitalize ( 'beep boop' ) ; // $ExpectType "Beep boop"
28
+ capitalize ( 'a' ) ; // $ExpectType "A"
29
+ capitalize ( 'A' ) ; // $ExpectType "A"
30
+ capitalize ( 'abc' as string ) ; // $ExpectType string
27
31
}
28
32
29
33
// The compiler throws an error if the function is provided a value other than a string...
Original file line number Diff line number Diff line change 28
28
* var str = lowercase( 'bEEp' );
29
29
* // returns 'beep'
30
30
*/
31
- declare function lowercase ( str : string ) : string ;
31
+ declare function lowercase < S extends string > ( str : S ) : Lowercase < S > ;
32
32
33
33
34
34
// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,9 @@ import lowercase = require( './index' );
23
23
24
24
// The function returns a string...
25
25
{
26
- lowercase ( 'abc' ) ; // $ExpectType string
26
+ lowercase ( 'ABC' ) ; // $ExpectType "abc"
27
+ lowercase ( 'Beep BOOP' ) ; // $ExpectType "beep boop"
28
+ lowercase ( 'abc' as string ) ; // $ExpectType string
27
29
}
28
30
29
31
// The compiler throws an error if the function is provided a value other than a string...
Original file line number Diff line number Diff line change 18
18
19
19
// TypeScript Version: 4.1
20
20
21
+ type Uncapitalize < S extends string > = S extends `${infer F } ${infer R } ` ? `${Lowercase < F > } ${R } ` : S ;
22
+
21
23
/**
22
24
* Uncapitalizes the first character of a string.
23
25
*
40
42
* var out = uncapitalize( 'Hidden Treasures' );
41
43
* // returns 'hidden Treasures'
42
44
*/
43
- declare function uncapitalize ( str : string ) : string ;
45
+ declare function uncapitalize < S extends string > ( str : S ) : Uncapitalize < S > ;
44
46
45
47
46
48
// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,11 @@ import uncapitalize = require( './index' );
23
23
24
24
// The function returns a string...
25
25
{
26
- uncapitalize ( 'Last man standing' ) ; // $ExpectType string
26
+ uncapitalize ( 'Last man standing' ) ; // $ExpectType "last man standing"
27
+ uncapitalize ( 'Hello World!' ) ; // $ExpectType "hello World!"
28
+ uncapitalize ( 'BeepBoop' ) ; // $ExpectType "beepBoop"
29
+ uncapitalize ( 'A' ) ; // $ExpectType "a"
30
+ uncapitalize ( 'foo' as string ) ; // $ExpectType string
27
31
}
28
32
29
33
// The compiler throws an error if the function is provided a value other than a string...
Original file line number Diff line number Diff line change 28
28
* var str = uppercase( 'bEEp' );
29
29
* // returns 'BEEP'
30
30
*/
31
- declare function uppercase ( str : string ) : string ;
31
+ declare function uppercase < S extends string > ( str : S ) : Uppercase < S > ;
32
32
33
33
34
34
// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,11 @@ import uppercase = require( './index' );
23
23
24
24
// The function returns a string...
25
25
{
26
- uppercase ( 'Last man standing' ) ; // $ExpectType string
26
+ uppercase ( 'Last man standing' ) ; // $ExpectType "LAST MAN STANDING"
27
+ uppercase ( 'Hello World!' ) ; // $ExpectType "HELLO WORLD!"
28
+ uppercase ( 'beep' ) ; // $ExpectType "BEEP"
29
+ uppercase ( 'BOOP' ) ; // $ExpectType "BOOP"
30
+ uppercase ( 'foo' as string ) ; // $ExpectType string
27
31
}
28
32
29
33
// The compiler throws an error if the function is provided a value other than a string...
You can’t perform that action at this time.
0 commit comments