@stdlib/assert-contains 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -29,7 +29,7 @@ limitations under the License.
29
29
  <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
30
  </details>
31
31
 
32
- # Contains
32
+ # contains
33
33
 
34
34
  [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
35
 
@@ -59,16 +59,23 @@ npm install @stdlib/assert-contains
59
59
  var contains = require( '@stdlib/assert-contains' );
60
60
  ```
61
61
 
62
- #### contains( val, searchValue\[, position] )
62
+ #### contains( value, searchValue\[, position] )
63
63
 
64
- Tests if `val` contains a search value. When `val` is a `string`, the function checks whether the characters of a search string are found in the input string.
64
+ Tests if `value` contains a search value.
65
+
66
+ ```javascript
67
+ var v = contains( [ 1, 2, 3 ], 2 );
68
+ // returns true
69
+ ```
70
+
71
+ When `value` is a string, the function checks whether the characters of a search string are found in the input string.
65
72
 
66
73
  ```javascript
67
74
  var v = contains( 'Hello World', 'World' );
68
75
  // returns true
69
76
  ```
70
77
 
71
- When `val` is an `array-like` object, but not a `string`, the function checks whether the input value contains an element strictly equal to the specified search value.
78
+ When `value` is an array-like object, but not a string, the function checks whether the input value contains an element which is the [same value][@stdlib/assert/is-same-value] as the specified search value.
72
79
 
73
80
  ```javascript
74
81
  var arr = [ null, NaN, 2, 'abc', {} ];
@@ -100,7 +107,7 @@ v = contains( [ true, NaN, false ], true, 1 );
100
107
  // returns false
101
108
  ```
102
109
 
103
- If not provided an `array-like` object, the function throws an error.
110
+ If not provided an array-like object, the function throws an error.
104
111
 
105
112
  <!-- run throws: true -->
106
113
 
@@ -128,8 +135,8 @@ var v = contains( 'hello', 'e', 2.5 );
128
135
 
129
136
  ## Notes
130
137
 
131
- - For `strings`, the function is modeled after [String.prototype.includes][mdn-includes], part of the ECMAScript 6 specification. This function is different from a call to `String.prototype.includes.call` insofar as type-checking is performed for all arguments.
132
- - The function does **not** distinguish between positive and negative zero.
138
+ - For strings, the function is modeled after [String.prototype.includes][mdn-includes], part of the ECMAScript 6 specification. This function is different from a call to `String.prototype.includes.call` insofar as type-checking is performed for all arguments.
139
+ - The function **does** distinguish between positive and negative zero (see [`@stdlib/assert-is-same-value`][@stdlib/assert/is-same-value]).
133
140
  - If `position < 0`, the search is performed for the entire input array or string.
134
141
 
135
142
  </section>
@@ -202,7 +209,7 @@ See [LICENSE][stdlib-license].
202
209
 
203
210
  ## Copyright
204
211
 
205
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
212
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
206
213
 
207
214
  </section>
208
215
 
@@ -215,8 +222,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
215
222
  [npm-image]: http://img.shields.io/npm/v/@stdlib/assert-contains.svg
216
223
  [npm-url]: https://npmjs.org/package/@stdlib/assert-contains
217
224
 
218
- [test-image]: https://github.com/stdlib-js/assert-contains/actions/workflows/test.yml/badge.svg?branch=v0.2.2
219
- [test-url]: https://github.com/stdlib-js/assert-contains/actions/workflows/test.yml?query=branch:v0.2.2
225
+ [test-image]: https://github.com/stdlib-js/assert-contains/actions/workflows/test.yml/badge.svg?branch=v0.3.0
226
+ [test-url]: https://github.com/stdlib-js/assert-contains/actions/workflows/test.yml?query=branch:v0.3.0
220
227
 
221
228
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/assert-contains/main.svg
222
229
  [coverage-url]: https://codecov.io/github/stdlib-js/assert-contains?branch=main
@@ -228,8 +235,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
228
235
 
229
236
  -->
230
237
 
231
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
232
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
238
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
239
+ [chat-url]: https://stdlib.zulipchat.com
233
240
 
234
241
  [stdlib]: https://github.com/stdlib-js/stdlib
235
242
 
@@ -250,6 +257,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
250
257
 
251
258
  [mdn-includes]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
252
259
 
260
+ [@stdlib/assert/is-same-value]: https://www.npmjs.com/package/@stdlib/assert-is-same-value
261
+
253
262
  </section>
254
263
 
255
264
  <!-- /.links -->
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var o=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var g=o(function(h,m){"use strict";var v=require("@stdlib/assert-is-collection"),w=require("@stdlib/assert-is-integer").isPrimitive,s=require("@stdlib/assert-is-string").isPrimitive,f=require("@stdlib/assert-is-nan").isPrimitive,a=require("@stdlib/string-format");function d(r,e,n){var u,t,i;if(!v(r)&&!s(r))throw new TypeError(a("invalid argument. First argument must be array-like. Value: `%s`.",r));if(arguments.length<2)throw new Error("insufficient arguments. Must provide a search value.");if(arguments.length>2){if(!w(n))throw new TypeError(a("invalid argument. Third argument must be an integer. Value: `%s`.",n));t=n,t<0&&(t=0)}else t=0;if(s(r)){if(!s(e))throw new TypeError(a("invalid argument. Second argument must be a string. Value: `%s`.",e));return r.indexOf(e,t)!==-1}if(u=r.length,f(e)){for(i=t;i<u;i++)if(f(r[i]))return!0;return!1}for(i=t;i<u;i++)if(r[i]===e)return!0;return!1}m.exports=d});var l=g();module.exports=l;
1
+ "use strict";var g=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var m=g(function(q,u){"use strict";var o=require("@stdlib/assert-is-collection"),f=require("@stdlib/assert-is-integer").isPrimitive,s=require("@stdlib/assert-is-string").isPrimitive,v=require("@stdlib/array-base-index-of-same-value"),a=require("@stdlib/string-format");function d(e,r,t){var n,i;if(n=s(e),!o(e)&&!n)throw new TypeError(a("invalid argument. First argument must be array-like. Value: `%s`.",e));if(arguments.length<2)throw new Error("insufficient arguments. Must provide a search value.");if(arguments.length>2){if(!f(t))throw new TypeError(a("invalid argument. Third argument must be an integer. Value: `%s`.",t));i=t,i<0&&(i=0)}else i=0;if(n){if(!s(r))throw new TypeError(a("invalid argument. Second argument must be a string. Value: `%s`.",r));return e.indexOf(r,i)!==-1}return v(e,r,i)!==-1}u.exports=d});var w=m();module.exports=w;
2
2
  /**
3
3
  * @license Apache-2.0
4
4
  *
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../lib/main.js", "../lib/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Tests if an array-like value contains a search value.\n*\n* @param {(Collection|string)} val - input value\n* @param {*} searchValue - search value\n* @param {integer} [position=0] - position at which to start searching for `searchValue`\n* @throws {TypeError} first argument must be array-like\n* @throws {Error} must provide a search value\n* @throws {TypeError} second argument must be a string when the first argument is a string\n* @throws {TypeError} third argument must be an integer\n* @returns {boolean} boolean indicating whether one value contains another\n*\n* @example\n* var bool = contains( 'last man standing', 'stand' );\n* // returns true\n*\n* @example\n* var bool = contains( [ 1, 2, 3, 4 ], 2 );\n* // returns true\n*\n* @example\n* var bool = contains( 'presidential election', 'president' );\n* // returns true\n*\n* @example\n* var bool = contains( [ NaN, 2, 3, 4 ], NaN );\n* // returns true\n*\n* @example\n* var bool = contains( 'javaScript', 'js' );\n* // returns false\n*\n* @example\n* var bool = contains( [ 1, 2, 3, {} ], {} );\n* // returns false\n*\n* @example\n* var bool = contains( 'Hidden Treasures', '' );\n* // returns true\n*/\nfunction contains( val, searchValue, position ) {\n\tvar len;\n\tvar pos;\n\tvar i;\n\tif ( !isCollection( val ) && !isString( val ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be array-like. Value: `%s`.', val ) );\n\t}\n\tif ( arguments.length < 2 ) {\n\t\tthrow new Error( 'insufficient arguments. Must provide a search value.' );\n\t}\n\tif ( arguments.length > 2 ) {\n\t\tif ( !isInteger( position ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', position ) );\n\t\t}\n\t\tpos = position;\n\t\tif ( pos < 0 ) {\n\t\t\tpos = 0;\n\t\t}\n\t} else {\n\t\tpos = 0;\n\t}\n\tif ( isString( val ) ) {\n\t\tif ( !isString( searchValue ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', searchValue ) );\n\t\t}\n\t\treturn val.indexOf( searchValue, pos ) !== -1;\n\t}\n\tlen = val.length;\n\tif ( isnan( searchValue ) ) {\n\t\tfor ( i = pos; i < len; i++ ) {\n\t\t\tif ( isnan( val[ i ] ) ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\tfor ( i = pos; i < len; i++ ) {\n\t\tif ( val[ i ] === searchValue ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = contains;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Test if an array-like value contains another value.\n*\n* @module @stdlib/assert-contains\n*\n* @example\n* var contains = require( '@stdlib/assert-contains' );\n*\n* var bool = contains( 'Hello World', 'World' );\n* // returns true\n*\n* bool = contains( 'Hello World', 'world' );\n* // returns false\n*\n* bool = contains( [ 1, 2, 3, 4 ], 2 );\n* // returns true\n*\n* bool = contains( [ NaN, 2, 3, 4 ], NaN );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
- "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAQ,QAAS,uBAAwB,EAAE,YAC3CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAUC,EAAKC,EAAaC,EAAW,CAC/C,IAAIC,EACAC,EACA,EACJ,GAAK,CAACV,EAAcM,CAAI,GAAK,CAACJ,EAAUI,CAAI,EAC3C,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAI,CAAE,EAEzG,GAAK,UAAU,OAAS,EACvB,MAAM,IAAI,MAAO,sDAAuD,EAEzE,GAAK,UAAU,OAAS,EAAI,CAC3B,GAAK,CAACL,EAAWO,CAAS,EACzB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAS,CAAE,EAE9GE,EAAMF,EACDE,EAAM,IACVA,EAAM,EAER,MACCA,EAAM,EAEP,GAAKR,EAAUI,CAAI,EAAI,CACtB,GAAK,CAACJ,EAAUK,CAAY,EAC3B,MAAM,IAAI,UAAWH,EAAQ,mEAAoEG,CAAY,CAAE,EAEhH,OAAOD,EAAI,QAASC,EAAaG,CAAI,IAAM,EAC5C,CAEA,GADAD,EAAMH,EAAI,OACLH,EAAOI,CAAY,EAAI,CAC3B,IAAM,EAAIG,EAAK,EAAID,EAAK,IACvB,GAAKN,EAAOG,EAAK,CAAE,CAAE,EACpB,MAAO,GAGT,MAAO,EACR,CACA,IAAM,EAAII,EAAK,EAAID,EAAK,IACvB,GAAKH,EAAK,CAAE,IAAMC,EACjB,MAAO,GAGT,MAAO,EACR,CAKAR,EAAO,QAAUM,IC3EjB,IAAIM,EAAO,IAKX,OAAO,QAAUA",
6
- "names": ["require_main", "__commonJSMin", "exports", "module", "isCollection", "isInteger", "isString", "isnan", "format", "contains", "val", "searchValue", "position", "len", "pos", "main"]
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar indexOfSameValue = require( '@stdlib/array-base-index-of-same-value' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Tests if an array-like value contains a search value.\n*\n* @param {(Collection|string)} value - input value\n* @param {*} searchValue - search value\n* @param {integer} [position=0] - position at which to start searching for `searchValue`\n* @throws {TypeError} first argument must be array-like\n* @throws {Error} must provide a search value\n* @throws {TypeError} second argument must be a string when the first argument is a string\n* @throws {TypeError} third argument must be an integer\n* @returns {boolean} boolean indicating whether one value contains another\n*\n* @example\n* var bool = contains( 'last man standing', 'stand' );\n* // returns true\n*\n* @example\n* var bool = contains( [ 1, 2, 3, 4 ], 2 );\n* // returns true\n*\n* @example\n* var bool = contains( 'presidential election', 'president' );\n* // returns true\n*\n* @example\n* var bool = contains( [ NaN, 2, 3, 4 ], NaN );\n* // returns true\n*\n* @example\n* var bool = contains( 'javaScript', 'js' );\n* // returns false\n*\n* @example\n* var bool = contains( [ 1, 2, 3, {} ], {} );\n* // returns false\n*\n* @example\n* var bool = contains( 'Hidden Treasures', '' );\n* // returns true\n*/\nfunction contains( value, searchValue, position ) {\n\tvar isStr;\n\tvar pos;\n\n\tisStr = isString( value );\n\tif ( !isCollection( value ) && !isStr ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be array-like. Value: `%s`.', value ) );\n\t}\n\tif ( arguments.length < 2 ) {\n\t\tthrow new Error( 'insufficient arguments. Must provide a search value.' );\n\t}\n\tif ( arguments.length > 2 ) {\n\t\tif ( !isInteger( position ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', position ) );\n\t\t}\n\t\tpos = position;\n\t\tif ( pos < 0 ) {\n\t\t\tpos = 0;\n\t\t}\n\t} else {\n\t\tpos = 0;\n\t}\n\tif ( isStr ) {\n\t\tif ( !isString( searchValue ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', searchValue ) );\n\t\t}\n\t\treturn value.indexOf( searchValue, pos ) !== -1;\n\t}\n\treturn indexOfSameValue( value, searchValue, pos ) !== -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = contains;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Test if an array-like value contains another value.\n*\n* @module @stdlib/assert-contains\n*\n* @example\n* var contains = require( '@stdlib/assert-contains' );\n*\n* var bool = contains( 'Hello World', 'World' );\n* // returns true\n*\n* bool = contains( 'Hello World', 'world' );\n* // returns false\n*\n* bool = contains( [ 1, 2, 3, 4 ], 2 );\n* // returns true\n*\n* bool = contains( [ NaN, 2, 3, 4 ], NaN );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAmB,QAAS,wCAAyC,EACrEC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAUC,EAAOC,EAAaC,EAAW,CACjD,IAAIC,EACAC,EAGJ,GADAD,EAAQP,EAAUI,CAAM,EACnB,CAACN,EAAcM,CAAM,GAAK,CAACG,EAC/B,MAAM,IAAI,UAAWL,EAAQ,oEAAqEE,CAAM,CAAE,EAE3G,GAAK,UAAU,OAAS,EACvB,MAAM,IAAI,MAAO,sDAAuD,EAEzE,GAAK,UAAU,OAAS,EAAI,CAC3B,GAAK,CAACL,EAAWO,CAAS,EACzB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAS,CAAE,EAE9GE,EAAMF,EACDE,EAAM,IACVA,EAAM,EAER,MACCA,EAAM,EAEP,GAAKD,EAAQ,CACZ,GAAK,CAACP,EAAUK,CAAY,EAC3B,MAAM,IAAI,UAAWH,EAAQ,mEAAoEG,CAAY,CAAE,EAEhH,OAAOD,EAAM,QAASC,EAAaG,CAAI,IAAM,EAC9C,CACA,OAAOP,EAAkBG,EAAOC,EAAaG,CAAI,IAAM,EACxD,CAKAX,EAAO,QAAUM,IC9DjB,IAAIM,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "isCollection", "isInteger", "isString", "indexOfSameValue", "format", "contains", "value", "searchValue", "position", "isStr", "pos", "main"]
7
7
  }
@@ -27,13 +27,13 @@ import { ArrayLike } from '@stdlib/types/array';
27
27
  *
28
28
  * ## Notes
29
29
  *
30
- * - When `val` is a string, the function checks whether the characters of the search string are found in the input string. The search is case-sensitive.
31
- * - When `val` is an array-like object, the function checks whether the input array contains an element strictly equal to the specified search value.
30
+ * - When `value` is a string, the function checks whether the characters of the search string are found in the input string. The search is case-sensitive.
31
+ * - When `value` is an array-like object, the function checks whether the input array contains an element which is the same as the specified search value.
32
32
  * - For strings, this function is modeled after `String.prototype.includes`, part of the ECMAScript 6 specification. This function is different from a call to `String.prototype.includes.call` insofar as type-checking is performed for all arguments.
33
- * - The function does not distinguish between positive and negative zero.
33
+ * - The function does distinguish between positive and negative zero.
34
34
  * - If `position < 0`, the search is performed for the entire input array or string.
35
35
  *
36
- * @param val - input value
36
+ * @param value - input value
37
37
  * @param searchValue - search value
38
38
  * @param position - position at which to start searching for `searchValue` (default: 0)
39
39
  * @throws second argument must be a primitive string primitive when the first argument is a string
@@ -67,7 +67,7 @@ import { ArrayLike } from '@stdlib/types/array';
67
67
  * var bool = contains( 'Hidden Treasures', '' );
68
68
  * // returns true
69
69
  */
70
- declare function contains( val: ArrayLike<any>, searchValue: any, position?: number ): boolean;
70
+ declare function contains( value: ArrayLike<unknown>, searchValue: unknown, position?: number ): boolean;
71
71
 
72
72
 
73
73
  // EXPORTS //
package/lib/main.js CHANGED
@@ -23,7 +23,7 @@
23
23
  var isCollection = require( '@stdlib/assert-is-collection' );
24
24
  var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
25
25
  var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
26
- var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;
26
+ var indexOfSameValue = require( '@stdlib/array-base-index-of-same-value' );
27
27
  var format = require( '@stdlib/string-format' );
28
28
 
29
29
 
@@ -32,7 +32,7 @@ var format = require( '@stdlib/string-format' );
32
32
  /**
33
33
  * Tests if an array-like value contains a search value.
34
34
  *
35
- * @param {(Collection|string)} val - input value
35
+ * @param {(Collection|string)} value - input value
36
36
  * @param {*} searchValue - search value
37
37
  * @param {integer} [position=0] - position at which to start searching for `searchValue`
38
38
  * @throws {TypeError} first argument must be array-like
@@ -69,12 +69,13 @@ var format = require( '@stdlib/string-format' );
69
69
  * var bool = contains( 'Hidden Treasures', '' );
70
70
  * // returns true
71
71
  */
72
- function contains( val, searchValue, position ) {
73
- var len;
72
+ function contains( value, searchValue, position ) {
73
+ var isStr;
74
74
  var pos;
75
- var i;
76
- if ( !isCollection( val ) && !isString( val ) ) {
77
- throw new TypeError( format( 'invalid argument. First argument must be array-like. Value: `%s`.', val ) );
75
+
76
+ isStr = isString( value );
77
+ if ( !isCollection( value ) && !isStr ) {
78
+ throw new TypeError( format( 'invalid argument. First argument must be array-like. Value: `%s`.', value ) );
78
79
  }
79
80
  if ( arguments.length < 2 ) {
80
81
  throw new Error( 'insufficient arguments. Must provide a search value.' );
@@ -90,27 +91,13 @@ function contains( val, searchValue, position ) {
90
91
  } else {
91
92
  pos = 0;
92
93
  }
93
- if ( isString( val ) ) {
94
+ if ( isStr ) {
94
95
  if ( !isString( searchValue ) ) {
95
96
  throw new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', searchValue ) );
96
97
  }
97
- return val.indexOf( searchValue, pos ) !== -1;
98
- }
99
- len = val.length;
100
- if ( isnan( searchValue ) ) {
101
- for ( i = pos; i < len; i++ ) {
102
- if ( isnan( val[ i ] ) ) {
103
- return true;
104
- }
105
- }
106
- return false;
107
- }
108
- for ( i = pos; i < len; i++ ) {
109
- if ( val[ i ] === searchValue ) {
110
- return true;
111
- }
98
+ return value.indexOf( searchValue, pos ) !== -1;
112
99
  }
113
- return false;
100
+ return indexOfSameValue( value, searchValue, pos ) !== -1;
114
101
  }
115
102
 
116
103
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/assert-contains",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Test if an array-like value contains a search value.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -30,9 +30,9 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@stdlib/assert-is-collection": "^0.2.1",
33
+ "@stdlib/array-base-index-of-same-value": "github:stdlib-js/array-base-index-of-same-value#main",
34
+ "@stdlib/assert-is-collection": "^0.2.2",
34
35
  "@stdlib/assert-is-integer": "^0.2.2",
35
- "@stdlib/assert-is-nan": "^0.2.2",
36
36
  "@stdlib/assert-is-string": "^0.2.2",
37
37
  "@stdlib/string-format": "^0.2.2",
38
38
  "@stdlib/error-tools-fmtprodmsg": "^0.2.2"