Skip to content

Commit 8ea4115

Browse files
committed
refactor: remove unnecessary branches
1 parent ed9f6c1 commit 8ea4115

File tree

1 file changed

+1
-7
lines changed
  • lib/node_modules/@stdlib/string/first/lib

1 file changed

+1
-7
lines changed

lib/node_modules/@stdlib/string/first/lib/main.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,10 @@ function first( str, n ) {
6666
if ( !isString( str ) ) {
6767
throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );
6868
}
69-
if ( str.length === 0 ) {
70-
return '';
71-
}
7269
if ( arguments.length > 1 ) {
7370
if ( !isNonNegativeInteger( n ) ) {
7471
throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );
7572
}
76-
if ( str.length <= n ) {
77-
return str;
78-
}
7973
nextBreak = 0;
8074
while ( n > 0 ) {
8175
nextBreak = nextGraphemeClusterBreak( str, nextBreak );
@@ -84,7 +78,7 @@ function first( str, n ) {
8478
} else {
8579
nextBreak = nextGraphemeClusterBreak( str );
8680
}
87-
// If `nextBreak` equals -1, it means that `str` is a string with a single grapheme cluster. In that case, we return `str` itself:
81+
// Value of `nextBreak` will be -1 if and only if `str` is an empty string or `str` has only 1 extended grapheme cluster...
8882
if ( str === '' || nextBreak === -1 ) {
8983
return str;
9084
}

0 commit comments

Comments
 (0)