Преглед на файлове

feat(ts) migrate modules\util\RandomUtil to TS

master
Naman Jain преди 4 месеца
родител
ревизия
5189885a9d
No account linked to committer's email address
променени са 2 файла, в които са добавени 7 реда и са изтрити 7 реда
  1. 0
    0
      modules/util/MathUtil.spec.ts
  2. 7
    7
      modules/util/RandomUtil.ts

modules/util/MathUtil.spec.js → modules/util/MathUtil.spec.ts Целия файл


modules/util/RandomUtil.js → modules/util/RandomUtil.ts Целия файл

@@ -16,7 +16,7 @@ const HEX_DIGITS = '0123456789abcdef';
16 16
  * @param max the maximum value for the generated number
17 17
  * @returns random int number
18 18
  */
19
-function randomInt(min, max) {
19
+export function randomInt(min: number, max: number): number {
20 20
     return Math.floor(Math.random() * (max - min + 1)) + min;
21 21
 }
22 22
 
@@ -25,7 +25,7 @@ function randomInt(min, max) {
25 25
  * @param {Array|string} arr source
26 26
  * @returns array element or string character
27 27
  */
28
-function randomElement(arr) {
28
+export function randomElement<T>(arr: T[] | string): T | string {
29 29
     return arr[randomInt(0, arr.length - 1)];
30 30
 }
31 31
 
@@ -34,7 +34,7 @@ function randomElement(arr) {
34 34
  * @param {number} length expected string length
35 35
  * @returns {string} random string of specified length
36 36
  */
37
-function randomAlphanumStr(length) {
37
+export function randomAlphanumStr(length: number): string {
38 38
     let result = '';
39 39
 
40 40
     for (let i = 0; i < length; i += 1) {
@@ -52,15 +52,15 @@ const RandomUtil = {
52 52
      * Returns a random hex digit.
53 53
      * @returns {*}
54 54
      */
55
-    randomHexDigit() {
56
-        return randomElement(HEX_DIGITS);
55
+    randomHexDigit(): string {
56
+        return randomElement(HEX_DIGITS) as string;
57 57
     },
58 58
 
59 59
     /**
60 60
      * Returns a random string of hex digits with length 'len'.
61 61
      * @param len the length.
62 62
      */
63
-    randomHexString(len) {
63
+    randomHexString(len: number): string {
64 64
         let ret = '';
65 65
 
66 66
         while (len--) { // eslint-disable-line no-param-reassign
@@ -74,4 +74,4 @@ const RandomUtil = {
74 74
     randomInt
75 75
 };
76 76
 
77
-module.exports = RandomUtil;
77
+export default RandomUtil;

Loading…
Отказ
Запис