Skip to content

Commit 2ae1ed6

Browse files
committed
Update code style and apply fixes
1 parent 66ac7c9 commit 2ae1ed6

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

lib/node_modules/@stdlib/nlp/porter-stemmer/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# porterStemmer
2222

23-
> Extracts the stem of a given word.
23+
> Extract the stem of a given word.
2424
2525
<section class="intro">
2626

lib/node_modules/@stdlib/nlp/porter-stemmer/docs/repl.txt

-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616
--------
1717
> var out = {{alias}}( 'walking' )
1818
'walk'
19-
2019
> out = {{alias}}( 'walked' )
2120
'walk'
22-
2321
> out = {{alias}}( 'walks' )
2422
'walk'
25-
2623
> out = {{alias}}( '' )
2724
''
2825

lib/node_modules/@stdlib/nlp/porter-stemmer/docs/types/test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import porterStemmer = require( './index' );
2626
porterStemmer( 'worldwide' ); // $ExpectType string
2727
}
2828

29-
// The function does not compile if not provided a string...
29+
// The compiler throws an error if the function is not provided a string...
3030
{
3131
porterStemmer( true ); // $ExpectError
3232
porterStemmer( false ); // $ExpectError
@@ -36,7 +36,7 @@ import porterStemmer = require( './index' );
3636
porterStemmer( ( x: number ): number => x ); // $ExpectError
3737
}
3838

39-
// The function does not compile if provided insufficient arguments...
39+
// The compiler throws an error if the function is provided insufficient arguments...
4040
{
4141
porterStemmer(); // $ExpectError
4242
}

lib/node_modules/@stdlib/nlp/porter-stemmer/lib/main.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
3434
var endsWith = require( '@stdlib/string/ends-with' );
3535
var lowercase = require( '@stdlib/string/lowercase' );
36+
var replace = require( '@stdlib/string/replace' );
3637

3738

3839
// VARIABLES //
@@ -141,42 +142,38 @@ function porterStemmer( word ) {
141142
if ( !isString( word ) ) {
142143
throw new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + word + '`.' );
143144
}
144-
if ( word.length < 3) {
145+
if ( word.length < 3 ) {
145146
return word;
146147
}
147148
word = lowercase( word );
148-
firstch = word.substr( 0, 1 );
149+
firstch = word[ 0 ];
149150
if ( firstch === 'y' ) {
150151
word = firstch.toUpperCase() + word.substr( 1 );
151152
}
152153

153154
// Step 1a:
154155
if ( RE_STEP1A.test( word ) ) {
155-
word = word.replace( RE_STEP1A, '$1$2' );
156-
}
157-
else if ( RE2_STEP1A.test( word ) ) {
158-
word = word.replace( RE2_STEP1A, '$1$2' );
156+
word = replace( word, RE_STEP1A, '$1$2' );
157+
} else if ( RE2_STEP1A.test( word ) ) {
158+
word = replace( word, RE2_STEP1A, '$1$2' );
159159
}
160160

161161
// Step 1b:
162162
if ( RE_STEP1B.test( word ) ) {
163163
fp = RE_STEP1B.exec( word );
164164
if ( RE_MGR0.test( fp[ 1 ] ) ) {
165-
word = word.replace( RE_LAST, '' );
165+
word = replace( word, RE_LAST, '' );
166166
}
167-
}
168-
else if ( RE2_STEP1B.test( word ) ) {
167+
} else if ( RE2_STEP1B.test( word ) ) {
169168
fp = RE2_STEP1B.exec( word );
170169
stem = fp[ 1 ];
171170
if ( RE_SV.test( stem ) ) {
172171
word = stem;
173172
if ( RE_ATBLIZ.test( word ) ) {
174173
word += 'e';
175-
}
176-
else if ( RE_DOUBLE.test( word ) ) {
177-
word = word.replace( RE_LAST, '' );
178-
}
179-
else if ( RE_CV.test( word ) ) {
174+
} else if ( RE_DOUBLE.test( word ) ) {
175+
word = replace( word, RE_LAST, '' );
176+
} else if ( RE_CV.test( word ) ) {
180177
word += 'e';
181178
}
182179
}
@@ -238,7 +235,7 @@ function porterStemmer( word ) {
238235
}
239236
}
240237
if ( endsWith( word, 'll' ) && RE_MGR1.test( word ) ) {
241-
word = word.replace( RE_LAST, '' );
238+
word = replace( word, RE_LAST, '' );
242239
}
243240

244241
// Turn initial Y back to y:

lib/node_modules/@stdlib/nlp/porter-stemmer/test/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ tape( 'if the first argument is not a string primitive, the function throws an e
4949
5,
5050
null,
5151
true,
52-
undefined,
52+
void 0,
5353
NaN,
5454
[],
5555
{},
@@ -76,12 +76,12 @@ tape( 'the function stems an input string using the Porter stemming algorithm',
7676
for ( i = 0; i < words.original.length; i++ ) {
7777
expected = words.stemmed[ i ];
7878
actual = porterStemmer( words.original[ i ] );
79-
t.deepEqual( actual, expected, 'returns the expected string' );
79+
t.equal( actual, expected, 'returns the expected string' );
8080
}
8181
t.end();
8282
});
8383

84-
tape( 'the function returns an emptry string if provided an empty string', function test( t ) {
84+
tape( 'the function returns an empty string if provided an empty string', function test( t ) {
8585
var out = porterStemmer( '' );
8686
t.equal( isEmptyString( out ), true, 'returns an empty string' );
8787
t.end();

0 commit comments

Comments
 (0)