Skip to content

Commit f12efb9

Browse files
committed
Dual package functionality got added
1 parent b907db5 commit f12efb9

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

Readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
![npm](https://img.shields.io/npm/v/@smakss/random-array-element) ![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/@smakss/random-array-element) ![NPM](https://img.shields.io/npm/l/@smakss/random-array-element) ![npm](https://img.shields.io/npm/dm/@smakss/random-array-element) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@smakss/random-array-element)
44

5-
In order to select an element within an array, you can simply use `Math.random()` but what about when you don't want to select an element that selected before. Here this package will came to use.
5+
In order to select an element within an array, you can simply use `Math.random()` but what about when you don't want to select an element that selected before. Here this package will came to use.
66

77
## How it works?
88

99
To install it you can simply do the following command:
1010

11-
```
11+
```
1212
npm i @smakss/random-array-element
1313
or
1414
yarn add @smakss/random-array-element
@@ -27,6 +27,7 @@ import randomArrayElement from '@smakss/random-array-element'
2727
```
2828

2929
then to use it within your application you can do it just like this:
30+
3031
```
3132
const chooser = randomArrayElement(['Foo', 'Bar', 'FU', 'FooBar']);
3233
@@ -35,4 +36,4 @@ chooser() // Bar
3536
chooser() // FU
3637
chooser() // FooBar
3738
chooser() // Foo (only repeats once all items within the array are exhausted.)
38-
```
39+
```

index.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict'
2+
module.exports = function randomItemWithNoRepetition(array) {
3+
var copy = array.slice()
4+
return function () {
5+
copy.length < 1 && (copy = array.slice())
6+
var index = Math.floor(Math.random() * copy.length),
7+
item = copy[index]
8+
return copy.splice(index, 1), item
9+
}
10+
}

index.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
import randomItemWithNoRepetition from './index.cjs'
3+
export default randomItemWithNoRepetition

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
{
22
"name": "@smakss/random-array-element",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Select random array element without repetition.",
5-
"main": "index.min.js",
5+
"type": "module",
6+
"main": "./index.cjs",
7+
"exports": {
8+
"import": "./index.mjs",
9+
"require": "./index.cjs"
10+
},
611
"repository": {
712
"type": "git",
813
"url": "git+https://github.com/SMAliKSS/random-array-element.git"
914
},
1015
"keywords": [
16+
"ES5",
17+
"ES6",
1118
"npm",
1219
"yarn",
1320
"array",

0 commit comments

Comments
 (0)