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 1818
1919// TypeScript Version: 4.1
2020
21+ type Capitalize < S extends string > = S extends `${infer F } ${infer R } ` ? `${Uppercase < F > } ${R } ` : S ;
22+
2123/**
2224* Capitalizes the first character in a string.
2325*
4042* var out = capitalize( 'Hidden Treasures' );
4143* // returns 'Hidden Treasures'
4244*/
43- declare function capitalize ( str : string ) : string ;
45+ declare function capitalize < S extends string > ( str : S ) : Capitalize < S > ;
4446
4547
4648// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,11 @@ import capitalize = require( './index' );
2323
2424// The function returns a string...
2525{
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
2731}
2832
2933// 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 2828* var str = lowercase( 'bEEp' );
2929* // returns 'beep'
3030*/
31- declare function lowercase ( str : string ) : string ;
31+ declare function lowercase < S extends string > ( str : S ) : Lowercase < S > ;
3232
3333
3434// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,9 @@ import lowercase = require( './index' );
2323
2424// The function returns a string...
2525{
26- lowercase ( 'abc' ) ; // $ExpectType string
26+ lowercase ( 'ABC' ) ; // $ExpectType "abc"
27+ lowercase ( 'Beep BOOP' ) ; // $ExpectType "beep boop"
28+ lowercase ( 'abc' as string ) ; // $ExpectType string
2729}
2830
2931// 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 1818
1919// TypeScript Version: 4.1
2020
21+ type Uncapitalize < S extends string > = S extends `${infer F } ${infer R } ` ? `${Lowercase < F > } ${R } ` : S ;
22+
2123/**
2224* Uncapitalizes the first character of a string.
2325*
4042* var out = uncapitalize( 'Hidden Treasures' );
4143* // returns 'hidden Treasures'
4244*/
43- declare function uncapitalize ( str : string ) : string ;
45+ declare function uncapitalize < S extends string > ( str : S ) : Uncapitalize < S > ;
4446
4547
4648// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,11 @@ import uncapitalize = require( './index' );
2323
2424// The function returns a string...
2525{
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
2731}
2832
2933// 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 2828* var str = uppercase( 'bEEp' );
2929* // returns 'BEEP'
3030*/
31- declare function uppercase ( str : string ) : string ;
31+ declare function uppercase < S extends string > ( str : S ) : Uppercase < S > ;
3232
3333
3434// EXPORTS //
Original file line number Diff line number Diff line change @@ -23,7 +23,11 @@ import uppercase = require( './index' );
2323
2424// The function returns a string...
2525{
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
2731}
2832
2933// 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 1818
1919// TypeScript Version: 4.1
2020
21+ type Capitalize < S extends string > = S extends `${infer F } ${infer R } ` ? `${Uppercase < F > } ${R } ` : S ;
22+
2123/**
2224* Capitalizes the first character in a string.
2325*
4042* var out = capitalize( 'Hidden Treasures' );
4143* // returns 'Hidden Treasures'
4244*/
43- declare function capitalize ( str : string ) : string ;
45+ declare function capitalize < S extends string > ( str : S ) : Capitalize < S > ;
4446
4547
4648// EXPORTS //
Original file line number Diff line number Diff line change @@ -21,9 +21,13 @@ import capitalize = require( './index' );
2121
2222// TESTS //
2323
24- // The function returns a string...
24+ // The function returns a capitalized string...
2525{
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
2731}
2832
2933// 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