Gathering detailed insights and metrics for @smakss/random-array-element
Gathering detailed insights and metrics for @smakss/random-array-element
Gathering detailed insights and metrics for @smakss/random-array-element
Gathering detailed insights and metrics for @smakss/random-array-element
Selects a random array element without repetition.
npm install @smakss/random-array-element
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Upgrade dependencies
Updated on Dec 31, 2023
Stable release of 2.0.2
Updated on Nov 28, 2023
Upgrade dependencies
Updated on Nov 28, 2023
Update package.json and dependencies
Updated on Nov 16, 2023
Migrate to typescript and enhance DX tools
Updated on Nov 04, 2023
Migrate to typescript
Updated on Nov 04, 2023
TypeScript (52.65%)
JavaScript (41.35%)
Shell (6.01%)
Total Downloads
11,525
Last Day
2
Last Week
10
Last Month
64
Last Year
1,770
MIT License
4 Stars
72 Commits
1 Watchers
7 Branches
1 Contributors
Updated on Nov 04, 2023
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
Published on
Dec 31, 2023
Cumulative downloads
Total Downloads
Last Day
100%
2
Compared to previous day
Last Week
100%
10
Compared to previous week
Last Month
-76.1%
64
Compared to previous month
Last Year
-16.5%
1,770
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
5 existing vulnerabilities detected
Details
Reason
Found 0/18 approved changesets -- score normalized to 0
Reason
dangerous workflow patterns detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
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-06-30
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