Skip to content

Commit 482b4ab

Browse files
committed
Auto-generated commit
1 parent e39790e commit 482b4ab

File tree

11 files changed

+23
-39
lines changed

11 files changed

+23
-39
lines changed

.github/.keepalive

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2022-09-01T00:43:32.321Z
1+
2022-10-01T01:08:01.047Z

README.md

+1-1
Original file line numberDiff line numberDiff 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
6464
var str = startcase( 'beep boop a foo bar' );

benchmark/benchmark.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,27 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
25-
var fromCodePoint = require( '@stdlib/string-from-code-point' );
2625
var pkg = require( './../package.json' ).name;
2726
var startcase = require( './../lib' );
2827

2928

3029
// MAIN //
3130

3231
bench( 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
}

docs/repl.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
----------

docs/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
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' );

docs/types/test.ts

+2-2
Original file line numberDiff line numberDiff 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
}

examples/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
var startcase = require( './../lib' );
2222

23-
var str;
24-
25-
str = startcase( 'beep boop foo bar' );
23+
var str = startcase( 'beep boop foo bar' );
2624
console.log( str );
2725
// => 'Beep Boop Foo Bar'
2826

lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
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;

lib/startcase.js renamed to lib/main.js

+2-20
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
// MODULES //
2222

2323
var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
24-
var reWhitespace = require( '@stdlib/regexp-whitespace' );
2524
var 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
*/
4141
function 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

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,15 @@
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",

test/test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tape( 'main export is a function', function test( t ) {
3232
t.end();
3333
});
3434

35-
tape( 'the function throws an error if not provided a primitive string', function test( t ) {
35+
tape( 'the function throws an error if not provided a string', function test( t ) {
3636
var values;
3737
var i;
3838

@@ -42,6 +42,7 @@ tape( 'the function throws an error if not provided a primitive string', functio
4242
null,
4343
void 0,
4444
true,
45+
false,
4546
[],
4647
{},
4748
function noop() {}

0 commit comments

Comments
 (0)