File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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' );
5858
5959#### startcase( str )
6060
61- Capitalizes the first letter of each word in a ` string ` .
61+ Capitalizes the first letter of each word in a string.
6262
6363``` javascript
6464var str = startcase ( ' beep boop a foo bar' );
Original file line number Diff line number Diff line change 2222
2323var bench = require ( '@stdlib/bench' ) ;
2424var isString = require ( '@stdlib/assert-is-string' ) . isPrimitive ;
25- var fromCodePoint = require ( '@stdlib/string-from-code-point' ) ;
2625var pkg = require ( './../package.json' ) . name ;
2726var startcase = require ( './../lib' ) ;
2827
2928
3029// MAIN //
3130
3231bench ( pkg , function benchmark ( b ) {
33- var str ;
32+ var values ;
3433 var out ;
3534 var i ;
3635
36+ values = [
37+ 'beep boop' ,
38+ 'foo bar' ,
39+ 'xyz abc'
40+ ] ;
41+
3742 b . tic ( ) ;
3843 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' ) {
4246 b . fail ( 'should return a string' ) ;
4347 }
4448 }
Original file line number Diff line number Diff line change 11
22{{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.
44
55 Parameters
66 ----------
Original file line number Diff line number Diff line change 2222* Capitalizes the first letter of each word in an input string.
2323*
2424* @param str - string to convert
25- * @returns start case string
25+ * @returns start-cased string
2626*
2727* @example
2828* 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' );
2626 startcase ( 'Last man standing' ) ; // $ExpectType string
2727}
2828
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...
3030{
3131 startcase ( true ) ; // $ExpectError
3232 startcase ( false ) ; // $ExpectError
@@ -38,7 +38,7 @@ import startcase = require( './index' );
3838 startcase ( ( x : number ) : number => x ) ; // $ExpectError
3939}
4040
41- // The function does not compile if provided insufficient arguments...
41+ // The compiler throws an error if the function is provided insufficient arguments...
4242{
4343 startcase ( ) ; // $ExpectError
4444}
Original file line number Diff line number Diff line change 2020
2121var startcase = require ( './../lib' ) ;
2222
23- var str ;
24-
25- str = startcase ( 'beep boop foo bar' ) ;
23+ var str = startcase ( 'beep boop foo bar' ) ;
2624console . log ( str ) ;
2725// => 'Beep Boop Foo Bar'
2826
Original file line number Diff line number Diff line change 3232
3333// MODULES //
3434
35- var startcase = require ( './startcase .js' ) ;
35+ var main = require ( './main .js' ) ;
3636
3737
3838// EXPORTS //
3939
40- module . exports = startcase ;
40+ module . exports = main ;
Original file line number Diff line number Diff line change 2121// MODULES //
2222
2323var isString = require ( '@stdlib/assert-is-string' ) . isPrimitive ;
24- var reWhitespace = require ( '@stdlib/regexp-whitespace' ) ;
2524var format = require ( '@stdlib/string-format' ) ;
25+ var base = require ( '@stdlib/string-base-startcase' ) ;
2626
2727
2828// MAIN //
@@ -39,28 +39,10 @@ var format = require( '@stdlib/string-format' );
3939* // returns 'Beep Boop Foo Bar'
4040*/
4141function startcase ( str ) {
42- var cap ;
43- var out ;
44- var ch ;
45- var i ;
4642 if ( ! isString ( str ) ) {
4743 throw new TypeError ( format ( 'invalid argument. Must provide a string. Value: `%s`.' , str ) ) ;
4844 }
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 ) ;
6446}
6547
6648
Original file line number Diff line number Diff line change 4444 "@stdlib/cli-ctor" : " ^0.0.x" ,
4545 "@stdlib/fs-read-file" : " ^0.0.x" ,
4646 "@stdlib/process-read-stdin" : " ^0.0.x" ,
47- "@stdlib/regexp-whitespace" : " ^0.0.x" ,
4847 "@stdlib/streams-node-stdin" : " ^0.0.x" ,
48+ "@stdlib/string-base-startcase" : " ^0.0.x" ,
4949 "@stdlib/string-format" : " ^0.0.x"
5050 },
5151 "devDependencies" : {
5252 "@stdlib/assert-is-browser" : " ^0.0.x" ,
5353 "@stdlib/assert-is-windows" : " ^0.0.x" ,
5454 "@stdlib/bench" : " ^0.0.x" ,
5555 "@stdlib/process-exec-path" : " ^0.0.x" ,
56- "@stdlib/string-from-code-point" : " ^0.0.x" ,
5756 "@stdlib/string-replace" : " ^0.0.x" ,
5857 "tape" : " git+https://github.com/kgryte/tape.git#fix/globby" ,
5958 "proxyquire" : " ^2.0.0" ,
You can’t perform that action at this time.
0 commit comments