randex 0.12.0 → 0.13.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 +21 -2
- package/lib/custom/array.d.ts +1 -0
- package/lib/custom/array.js +21 -0
- package/lib/test/array.test.d.ts +1 -0
- package/lib/test/array.test.js +26 -0
- package/lib/test/number-array.test.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Installation:
|
|
|
14
14
|
npm i randex
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
|
|
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
|
|
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;
|
|
@@ -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);
|