Gathering detailed insights and metrics for utils-indexof
Gathering detailed insights and metrics for utils-indexof
Gathering detailed insights and metrics for utils-indexof
Gathering detailed insights and metrics for utils-indexof
Returns the first index at which a given element can be found.
npm install utils-indexof
Typescript
Module System
Node Version
NPM Version
97.9
Supply Chain
99.4
Quality
74.4
Maintenance
100
Vulnerability
100
License
JavaScript (67.5%)
Makefile (32.5%)
Total Downloads
28,166,839
Last Day
3,192
Last Week
27,682
Last Month
131,245
Last Year
2,836,821
2 Stars
24 Commits
3 Watching
1 Branches
1 Contributors
Latest Version
1.0.0
Package Id
utils-indexof@1.0.0
Size
3.92 kB
NPM Version
2.14.7
Node Version
4.2.3
Publised On
01 Mar 2016
Cumulative downloads
Total Downloads
Last day
-39.3%
3,192
Compared to previous day
Last week
-11%
27,682
Compared to previous week
Last month
-13.8%
131,245
Compared to previous month
Last year
-60%
2,836,821
Compared to previous year
2
8
Returns the first index at which a given element can be found.
1$ npm install utils-indexof
1var indexOf = require( 'utils-indexof' );
Returns the first index at which a given element can be found.
1var arr = [ 4, 3, 2, 1 ]; 2 3var idx = indexOf( arr, 3 ); 4// returns 1
If a searchElement
is not present in an input array
, the function
returns -1
.
1var arr = [ 4, 3, 2, 1 ]; 2 3var idx = indexOf( arr, 5 ); 4// returns -1
By default, the implementation searches an input array
beginning from the first element. To start searching from a different element, specify a fromIndex
.
1var arr = [ 1, 2, 3, 4, 5, 2, 6 ]; 2 3var idx = indexOf( arr, 2, 3 ); 4// returns 5
If a fromIndex
exceeds the input array
length, the function
returns -1
.
1var arr = [ 1, 2, 3, 4, 2, 5 ]; 2 3var idx = indexOf( arr, 2, 10 ); 4// returns -1
If a fromIndex
is less than 0
, the starting index is determined relative to the last index (with the last index being equivalent to fromIndex = -1
).
1var arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ]; 2 3var idx = indexOf( arr, 2, -4 ); 4// returns 5 5 6idx = indexOf( arr, 2, -1 ); 7// returns 7
If fromIndex
is less than 0
and its absolute value exceeds the input array
length, the function
searches the entire input array
.
1var arr = [ 1, 2, 3, 4, 5, 2, 6 ]; 2 3var idx = indexOf( arr, 2, -10 ); 4// returns 1
The first argument is not limited to arrays
, but may be any array-like object
.
1var str = 'bebop'; 2 3var idx = indexOf( str, 'o' ); 4// returns 3
Search is performed using strict equality comparison. Thus,
1var arr = [ 1, [1,2,3], 3 ]; 2 3var idx = indexOf( arr, [1,2,3] ); 4// returns -1
This implementation is not ECMAScript Standard compliant. Notably, the standard specifies that an array
be searched by calling hasOwnProperty
(thus, for most cases, incurring a performance penalty), and the standard does not accommodate a searchElement
equal to NaN
. In this implementation, the following is possible:
1// Locate the first element which is NaN... 2var arr = [ 1, NaN, 2, NaN ]; 3 4var idx = indexOf( arr, NaN ); 5// returns 1 6 7// Prototype properties may be searched as well... 8function Obj() { 9 this[ 0 ] = 'beep'; 10 this[ 1 ] = 'boop'; 11 this[ 2 ] = 'woot'; 12 this[ 3 ] = 'bap'; 13 this.length = 4; 14 return this; 15} 16Obj.prototype[ 2 ] = 'bop'; 17 18var obj = new Obj(); 19 20idx = indexOf( obj, 'bop' ); 21// returns -1 22 23delete obj[ 2 ]; 24 25idx = indexOf( obj, 'bop' ); 26// returns 2
1var indexOf = require( 'utils-indexof' ); 2 3var arr; 4var obj; 5var str; 6var idx; 7var i; 8 9// Arrays... 10arr = new Array( 10 ); 11for ( i = 0; i < arr.length; i++ ) { 12 arr[ i ] = i * 10; 13} 14idx = indexOf( arr, 40 ); 15 16console.log( idx ); 17// returns 4 18 19 20// Array-like objects... 21obj = { 22 '0': 'beep', 23 '1': 'boop', 24 '2': 'bap', 25 '3': 'bop', 26 'length': 4 27}; 28 29idx = indexOf( obj, 'bap' ); 30 31console.log( idx ); 32// returns 2 33 34 35// Strings... 36str = 'beepboopbop'; 37 38idx = indexOf( str, 'o' ); 39 40console.log( idx ); 41// returns 5
To run the example code from the top-level application directory,
1$ node ./examples/index.js
This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
1$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
1$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
1$ make view-cov
This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:
1$ make test-browsers
To view the tests in a local web browser,
1$ make view-browser-tests
Copyright © 2016. Athan Reines.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/22 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More