randex 1.1.0 → 1.2.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/README.md CHANGED
@@ -35,6 +35,7 @@ Many
35
35
 
36
36
  Generic Type:
37
37
  - [array](#array)
38
+ - [spread](#spread)
38
39
  - [RandexSpreader](#randexspreader)
39
40
 
40
41
  Deeps:
@@ -476,6 +477,25 @@ Randex.array(["1", "2", "3", "4"], 2);
476
477
  // ["1", "3"]
477
478
  ```
478
479
 
480
+ ## spread
481
+
482
+ `Randex.spread(array, count)` returns a new array containing the requested
483
+ number of randomly selected items. Items are selected without replacement
484
+ until the source array is exhausted. If `count` is greater than the source
485
+ array length, the selection pool is refilled automatically.
486
+
487
+ ```ts
488
+ import Randex from "randex";
489
+
490
+ Randex.spread(["red", "green", "blue"], 5);
491
+ // ["green", "red", "blue", "red", "green"]
492
+ ```
493
+
494
+ The method returns an empty array when the source array is empty or when
495
+ `count` is zero or negative. Each call starts with a new selection pool. Use
496
+ [`RandexSpreader`](#randexspreader) when the pool should continue between
497
+ multiple calls.
498
+
479
499
  ## RandexSpreader
480
500
 
481
501
  Generates random values from an array without replacement until every item has
@@ -49,4 +49,5 @@ export declare class Randex {
49
49
  (from: number, to: number, options?: import("../interfaces").RandomNumberOptions | undefined): number[];
50
50
  };
51
51
  };
52
+ static spread<TItem>(array: TItem[], count: number): TItem[];
52
53
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Randex = void 0;
4
+ var utils_1 = require("../utils");
4
5
  var bool_1 = require("./bool");
5
6
  var email_1 = require("./email");
6
7
  var filenameX_1 = require("./filenameX");
@@ -47,6 +48,10 @@ var Randex = /** @class */ (function () {
47
48
  Randex.many = function (count) {
48
49
  return { word: (0, word_1.randexManyWord)(count), phrase: (0, phrase_1.randexManyPhrase)(count), sentence: (0, sentence_1.randexManySentence)(count), number: (0, number_1.randexManyNumber)(count) };
49
50
  };
51
+ Randex.spread = function (array, count) {
52
+ var picker = new utils_1.RandexSpreader(array);
53
+ return picker.spread(count);
54
+ };
50
55
  Randex.random = random_1.randexRandom;
51
56
  Randex.bool = bool_1.randexBool;
52
57
  Randex.email = email_1.randexEmail;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "randex",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",