stdlib-js / utils-find

@@ -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;
Files Coverage
lib 100.00%
Project Totals (2 files) 100.00%
2285123822
unittests
2251772043
unittests
2361770663
unittests
2322911991
unittests
2438238337
unittests
2399767093
unittests
2519082239
unittests
2478603320
unittests
2559299822
unittests

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading