Gathering detailed insights and metrics for @smakss/random-array-element
Gathering detailed insights and metrics for @smakss/random-array-element
npm install @smakss/random-array-element
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Upgrade dependencies
Published on 31 Dec 2023
Stable release of 2.0.2
Published on 28 Nov 2023
Upgrade dependencies
Published on 28 Nov 2023
Update package.json and dependencies
Published on 16 Nov 2023
Migrate to typescript and enhance DX tools
Published on 04 Nov 2023
Migrate to typescript
Published on 04 Nov 2023
TypeScript (52.65%)
JavaScript (41.35%)
Shell (6.01%)
Total Downloads
10,802
Last Day
23
Last Week
77
Last Month
226
Last Year
1,157
4 Stars
72 Commits
1 Watching
7 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
2.0.3
Package Id
@smakss/random-array-element@2.0.3
Unpacked Size
14.21 kB
Size
3.64 kB
File Count
9
NPM Version
10.2.3
Node Version
18.19.0
Publised On
31 Dec 2023
Cumulative downloads
Total Downloads
Last day
-67.1%
23
Compared to previous day
Last week
-35.3%
77
Compared to previous week
Last month
276.7%
226
Compared to previous month
Last year
-56.9%
1,157
Compared to previous year
Selecting a random element from an array is simple with Math.random()
. However, if you need to ensure that each element is only selected once until all elements have been chosen, @smakss/random-array-element
is the ideal solution. Utilizing closures, this package allows you to initialize a function once and then repeatedly obtain unique, randomly-selected elements from your array, without repeats until the array is exhausted.
You can check the working demo on RunKit.
or
Install the package using npm or Yarn:
1npm i @smakss/random-array-element 2# or 3yarn add @smakss/random-array-element
To include it with CommonJS module you can do this:
1const randomArrayElement = require('@smakss/random-array-element');
For ECMAScript modules:
1import randomArrayElement from '@smakss/random-array-element';
Example usage:
1// Initialize once for an array
2const getRandomElement = randomArrayElement(['apple', 'banana', 'cherry']);
3
4console.log(getRandomElement()); // Result: 'banana' (example output)
5console.log(getRandomElement()); // Result: 'apple' (example output)
6// ...after all items have been returned, it resets.
7console.log(getRandomElement()); // Result: 'cherry' (example output)
8// ...continues to return a new random item.
If an empty or non-array input is passed, the function will return -1, indicating no selection can be made:
1const getRandomElement = randomArrayElement([]); 2console.log(getRandomElement()); // Result: -1
Contributions are welcome! Please see CONTRIBUTING.md for guidelines and details.
To ensure a welcoming and safe community, our Code of Conduct outlines expected behaviors for all participants.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dangerous workflow patterns detected
Details
Reason
Found 0/18 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
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 2025-01-27
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