Skip to content

Commit cd79399

Browse files
committed
Require stride to be a positive integer
1 parent c94d85b commit cd79399

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/node_modules/@stdlib/iter/strided/lib/main.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
// MODULES //
2222

2323
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24-
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' );
24+
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
25+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' );
2526
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2627
var isFunction = require( '@stdlib/assert/is-function' );
2728
var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
@@ -35,11 +36,11 @@ var iteratorSymbol = require( '@stdlib/symbol/iterator' );
3536
* Returns an iterator which steps by a specified amount.
3637
*
3738
* @param {Iterator} iterator - input iterator
38-
* @param {NonNegativeInteger} stride - stride
39+
* @param {PositiveInteger} stride - stride
3940
* @param {NonNegativeInteger} [offset=0] - offset
4041
* @param {boolean} [eager=false] - boolean indicating whether to eagerly advance the input iterator when provided a non-zero offset.
4142
* @throws {TypeError} first argument must be an iterator protocol-compliant object
42-
* @throws {TypeError} second argument must be a nonnegative integer
43+
* @throws {TypeError} second argument must be a positive integer
4344
* @throws {TypeError} third argument must be a nonnegative integer
4445
* @throws {TypeError} fourth argument must be a boolean
4546
* @returns {Iterator} iterator
@@ -73,8 +74,8 @@ function iterStrided( iterator, stride, offset, eager ) {
7374
if ( !isIteratorLike( iterator ) ) {
7475
throw new TypeError( 'invalid argument. First argument must be an iterator protocol-compliant object. Value: `' + iterator + '`.' );
7576
}
76-
if ( !isNonNegativeInteger( stride ) ) {
77-
throw new TypeError( 'invalid argument. Second argument must be a nonnegative integer. Value: `' + stride + '`.' );
77+
if ( !isPositiveInteger( stride ) ) {
78+
throw new TypeError( 'invalid argument. Second argument must be a positive integer. Value: `' + stride + '`.' );
7879
}
7980
if ( arguments.length === 3 ) {
8081
if ( !isNonNegativeInteger( offset ) ) {

lib/node_modules/@stdlib/iter/strided/test/test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,14 @@ tape( 'the function throws an error if provided an iterator argument which is no
154154
}
155155
});
156156

157-
tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) {
157+
tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) {
158158
var values;
159159
var i;
160160

161161
values = [
162162
'5',
163163
-5,
164+
0,
164165
3.14,
165166
NaN,
166167
true,
@@ -184,13 +185,14 @@ tape( 'the function throws an error if provided a second argument which is not a
184185
}
185186
});
186187

187-
tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (three arguments)', function test( t ) {
188+
tape( 'the function throws an error if provided a second argument which is not a positive integer (three arguments)', function test( t ) {
188189
var values;
189190
var i;
190191

191192
values = [
192193
'5',
193194
-5,
195+
0,
194196
3.14,
195197
NaN,
196198
true,
@@ -214,13 +216,14 @@ tape( 'the function throws an error if provided a second argument which is not a
214216
}
215217
});
216218

217-
tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (four arguments)', function test( t ) {
219+
tape( 'the function throws an error if provided a second argument which is not a positive integer (four arguments)', function test( t ) {
218220
var values;
219221
var i;
220222

221223
values = [
222224
'5',
223225
-5,
226+
0,
224227
3.14,
225228
NaN,
226229
true,

0 commit comments

Comments
 (0)