randex 0.12.0 → 0.14.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
@@ -14,7 +14,7 @@ Installation:
14
14
  npm i randex
15
15
  ```
16
16
 
17
- Functions:
17
+ Strings:
18
18
 
19
19
  - [random](#random)
20
20
  - [randomFileName](#randomfilename)
@@ -22,9 +22,14 @@ Functions:
22
22
  - [randomEmail](#randomemail)
23
23
  - [randomName](#randomname)
24
24
  - [randomFullName](#randomfullname)
25
+
26
+ Numbers:
25
27
  - [randomNumber](#randomnumber)
26
28
  - [randomNumberArray](#randomnumberarray)
27
29
 
30
+ Generic Type:
31
+ - [randomArray](#randomarray)
32
+
28
33
  Deeps:
29
34
 
30
35
  - [Customization](#customization)
@@ -312,7 +317,7 @@ randomNumber([3, 7]);
312
317
 
313
318
  ## randomNumberArray
314
319
 
315
- Generates random array with values from from a range.
320
+ Generates random array with values from a range.
316
321
 
317
322
  ```ts
318
323
  import { randomNumberArray } from "randex";
@@ -324,6 +329,20 @@ randomNumberArray(3, 2);
324
329
  randomNumber([3, 7], 3);
325
330
  ```
326
331
 
332
+ ## randomArray
333
+
334
+ Generates random array with values from defined array.
335
+
336
+ ```ts
337
+ import { randomArray } from "randex";
338
+
339
+ // Generates an array (with length equals 2) with values picked from defined array as the first parameter.
340
+ randomArray([1, 2, 3, 4], 2);
341
+ // [2, 4]
342
+ randomArray(["1", "2", "3", "4"], 2);
343
+ // ["1", "3"]
344
+ ```
345
+
327
346
 
328
347
  ## Customization
329
348
 
@@ -0,0 +1 @@
1
+ export declare function randomArray<T>(array: T[], count: number): T[];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randomArray = void 0;
4
+ var number_1 = require("./number");
5
+ function randomArray(array, count) {
6
+ var result = [];
7
+ var maxCount = array.length;
8
+ var uniqueArray = [];
9
+ for (var i = 0; i < array.length; i++) {
10
+ uniqueArray.push(array[i]);
11
+ }
12
+ for (var i = 0; i < count && i < maxCount; i++) {
13
+ var arrayCount = uniqueArray.length - 1;
14
+ var index = (0, number_1.randomNumber)(arrayCount);
15
+ var value = uniqueArray[index];
16
+ result.push(value);
17
+ uniqueArray.splice(index, 1);
18
+ }
19
+ return result;
20
+ }
21
+ exports.randomArray = randomArray;
@@ -5,3 +5,4 @@ export * from "./username";
5
5
  export * from "./fullname";
6
6
  export * from "./number";
7
7
  export * from "./number-array";
8
+ export * from "./array";
@@ -21,3 +21,4 @@ __exportStar(require("./username"), exports);
21
21
  __exportStar(require("./fullname"), exports);
22
22
  __exportStar(require("./number"), exports);
23
23
  __exportStar(require("./number-array"), exports);
24
+ __exportStar(require("./array"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var array_1 = require("../custom/array");
4
+ function testUniqueArray(array, count) {
5
+ var value = (0, array_1.randomArray)(array, count);
6
+ var uniqueResult = [];
7
+ var _loop_1 = function (i) {
8
+ var uniqueValue = value[i];
9
+ expect(uniqueResult.find(function (x) { return x === uniqueValue; })).toBeFalsy();
10
+ uniqueResult.push(uniqueValue);
11
+ };
12
+ for (var i = 0; i < count; i++) {
13
+ _loop_1(i);
14
+ }
15
+ }
16
+ describe("randomNumberArray", function () {
17
+ it("param: number", function () {
18
+ testUniqueArray([1, 2, 3, 4, 5, 6], 6);
19
+ });
20
+ it("param: string", function () {
21
+ testUniqueArray(["1", "2", "3", "4", "5", "6"], 6);
22
+ });
23
+ it("max count - array count", function () {
24
+ testUniqueArray([1, 2, 3, 4, 5, 6], 8);
25
+ });
26
+ });
@@ -9,6 +9,7 @@ function testNumber(min, max, count) {
9
9
  expect(uniqueResult.find(function (x) { return x === uniqueValue; })).toBeFalsy();
10
10
  expect(value[i]).toBeGreaterThanOrEqual(min);
11
11
  expect(value[i]).toBeLessThanOrEqual(max);
12
+ uniqueResult.push(uniqueValue);
12
13
  };
13
14
  for (var i = 0; i < count; i++) {
14
15
  _loop_1(i);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "randex",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",