stdlib-js / utils-find

Compare e7bf8b3 ... +0 ... 7993575

Coverage Reach
find.js index.js

Flags

Flags have been temporarily removed from this view while the flagging feature is refactored for better performance and user experience.

You can still use flags when viewing individual files. Flag-level thresholds will also remain on pull and merge requests in your repository provider.

More information can be found in our documentation.


@@ -26,9 +26,15 @@
Loading
26 26
var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
27 27
var isCollection = require( '@stdlib/assert-is-collection' );
28 28
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
29 +
var indexOf = require( '@stdlib/utils-index-of' );
29 30
var format = require( '@stdlib/string-format' );
30 31
31 32
33 +
// VARIABLES //
34 +
35 +
var RETURNS = [ 'values', 'indices', '*' ];
36 +
37 +
32 38
// MAIN //
33 39
34 40
/**
@@ -104,7 +110,6 @@
Loading
104 110
* }
105 111
*/
106 112
function find( arr, options, clbk ) { // eslint-disable-line stdlib/no-redeclare
107 -
	var returns;
108 113
	var count;
109 114
	var mode;
110 115
	var opts;
@@ -117,7 +122,6 @@
Loading
117 122
	var v;
118 123
119 124
	mode = 0;
120 -
	returns = [ 'values', 'indices', '*' ];
121 125
122 126
	if ( !isCollection( arr ) && !isString( arr ) ) {
123 127
		throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );
@@ -139,15 +143,15 @@
Loading
139 143
	if ( hasOwnProp( opts, 'k' ) ) {
140 144
		k = opts.k;
141 145
		if ( !isInteger( k ) ) {
142 -
			throw new TypeError( format( 'invalid argument. `k` must be an integer. Value: `%s`.', k ) );
146 +
			throw new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'k', k ) );
143 147
		}
144 148
	} else {
145 149
		k = len;
146 150
	}
147 151
	if ( hasOwnProp( opts, 'returns' ) ) {
148 152
		ret = opts.returns;
149 -
		if ( !isString( ret ) || returns.indexOf( ret ) === -1 ) {
150 -
			throw new TypeError( format( 'invalid argument. `returns` option must be a string and have one of the following values: `values`, `indices`, `all`. Value: `%s`.', ret ) );
153 +
		if ( !isString( ret ) || indexOf( RETURNS, ret ) === -1 ) {
154 +
			throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'returns', RETURNS.join( '", "' ), ret ) );
151 155
		}
152 156
		if ( ret === 'values' ) {
153 157
			mode = 1;

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
lib 100.00%
Project Totals (2 files) 100.00%
Loading