File tree Expand file tree Collapse file tree 11 files changed +23
-39
lines changed Expand file tree Collapse file tree 11 files changed +23
-39
lines changed Original file line number Diff line number Diff line change 1
- 2022-09-01T00:43:32.321Z
1
+ 2022-10-01T01:08:01.047Z
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ var startcase = require( '@stdlib/string-startcase' );
58
58
59
59
#### startcase( str )
60
60
61
- Capitalizes the first letter of each word in a ` string ` .
61
+ Capitalizes the first letter of each word in a string.
62
62
63
63
``` javascript
64
64
var str = startcase ( ' beep boop a foo bar' );
Original file line number Diff line number Diff line change 22
22
23
23
var bench = require ( '@stdlib/bench' ) ;
24
24
var isString = require ( '@stdlib/assert-is-string' ) . isPrimitive ;
25
- var fromCodePoint = require ( '@stdlib/string-from-code-point' ) ;
26
25
var pkg = require ( './../package.json' ) . name ;
27
26
var startcase = require ( './../lib' ) ;
28
27
29
28
30
29
// MAIN //
31
30
32
31
bench ( pkg , function benchmark ( b ) {
33
- var str ;
32
+ var values ;
34
33
var out ;
35
34
var i ;
36
35
36
+ values = [
37
+ 'beep boop' ,
38
+ 'foo bar' ,
39
+ 'xyz abc'
40
+ ] ;
41
+
37
42
b . tic ( ) ;
38
43
for ( i = 0 ; i < b . iterations ; i ++ ) {
39
- str = fromCodePoint ( i % 126 ) + 'eep boop foo bar tic toc' ;
40
- out = startcase ( str ) ;
41
- if ( ! isString ( out ) ) {
44
+ out = startcase ( values [ i % values . length ] ) ;
45
+ if ( typeof out !== 'string' ) {
42
46
b . fail ( 'should return a string' ) ;
43
47
}
44
48
}
Original file line number Diff line number Diff line change 1
1
2
2
{{alias}}( str )
3
- Capitalizes the first letter of each word in an input ` string` .
3
+ Capitalizes the first letter of each word in an input string.
4
4
5
5
Parameters
6
6
----------
Original file line number Diff line number Diff line change 22
22
* Capitalizes the first letter of each word in an input string.
23
23
*
24
24
* @param str - string to convert
25
- * @returns start case string
25
+ * @returns start-cased string
26
26
*
27
27
* @example
28
28
* var str = startcase( 'beep boop foo bar' );
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ import startcase = require( './index' );
26
26
startcase ( 'Last man standing' ) ; // $ExpectType string
27
27
}
28
28
29
- // The function does not compile if provided a value other than a string...
29
+ // The compiler throws an error if the function is provided a value other than a string...
30
30
{
31
31
startcase ( true ) ; // $ExpectError
32
32
startcase ( false ) ; // $ExpectError
@@ -38,7 +38,7 @@ import startcase = require( './index' );
38
38
startcase ( ( x : number ) : number => x ) ; // $ExpectError
39
39
}
40
40
41
- // The function does not compile if provided insufficient arguments...
41
+ // The compiler throws an error if the function is provided insufficient arguments...
42
42
{
43
43
startcase ( ) ; // $ExpectError
44
44
}
Original file line number Diff line number Diff line change 20
20
21
21
var startcase = require ( './../lib' ) ;
22
22
23
- var str ;
24
-
25
- str = startcase ( 'beep boop foo bar' ) ;
23
+ var str = startcase ( 'beep boop foo bar' ) ;
26
24
console . log ( str ) ;
27
25
// => 'Beep Boop Foo Bar'
28
26
Original file line number Diff line number Diff line change 32
32
33
33
// MODULES //
34
34
35
- var startcase = require ( './startcase .js' ) ;
35
+ var main = require ( './main .js' ) ;
36
36
37
37
38
38
// EXPORTS //
39
39
40
- module . exports = startcase ;
40
+ module . exports = main ;
Original file line number Diff line number Diff line change 21
21
// MODULES //
22
22
23
23
var isString = require ( '@stdlib/assert-is-string' ) . isPrimitive ;
24
- var reWhitespace = require ( '@stdlib/regexp-whitespace' ) ;
25
24
var format = require ( '@stdlib/string-format' ) ;
25
+ var base = require ( '@stdlib/string-base-startcase' ) ;
26
26
27
27
28
28
// MAIN //
@@ -39,28 +39,10 @@ var format = require( '@stdlib/string-format' );
39
39
* // returns 'Beep Boop Foo Bar'
40
40
*/
41
41
function startcase ( str ) {
42
- var cap ;
43
- var out ;
44
- var ch ;
45
- var i ;
46
42
if ( ! isString ( str ) ) {
47
43
throw new TypeError ( format ( 'invalid argument. Must provide a string. Value: `%s`.' , str ) ) ;
48
44
}
49
- cap = true ;
50
- out = '' ;
51
- for ( i = 0 ; i < str . length ; i ++ ) {
52
- ch = str . charAt ( i ) ;
53
- if ( reWhitespace . REGEXP . test ( ch ) ) {
54
- out += ch ;
55
- cap = true ;
56
- } else if ( cap ) {
57
- out += ch . toUpperCase ( ) ;
58
- cap = false ;
59
- } else {
60
- out += ch ;
61
- }
62
- }
63
- return out ;
45
+ return base ( str ) ;
64
46
}
65
47
66
48
Original file line number Diff line number Diff line change 44
44
"@stdlib/cli-ctor" : " ^0.0.x" ,
45
45
"@stdlib/fs-read-file" : " ^0.0.x" ,
46
46
"@stdlib/process-read-stdin" : " ^0.0.x" ,
47
- "@stdlib/regexp-whitespace" : " ^0.0.x" ,
48
47
"@stdlib/streams-node-stdin" : " ^0.0.x" ,
48
+ "@stdlib/string-base-startcase" : " ^0.0.x" ,
49
49
"@stdlib/string-format" : " ^0.0.x"
50
50
},
51
51
"devDependencies" : {
52
52
"@stdlib/assert-is-browser" : " ^0.0.x" ,
53
53
"@stdlib/assert-is-windows" : " ^0.0.x" ,
54
54
"@stdlib/bench" : " ^0.0.x" ,
55
55
"@stdlib/process-exec-path" : " ^0.0.x" ,
56
- "@stdlib/string-from-code-point" : " ^0.0.x" ,
57
56
"@stdlib/string-replace" : " ^0.0.x" ,
58
57
"tape" : " git+https://github.com/kgryte/tape.git#fix/globby" ,
59
58
"proxyquire" : " ^2.0.0" ,
You can’t perform that action at this time.
0 commit comments