From aa9b8d412791ba4f31d23527faa3a0aa6e08420a Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Wed, 6 Sep 2023 13:24:39 +0200 Subject: [PATCH 1/2] [TS migration] Migrate 'NumberUtils.js' lib to TypeScript --- src/libs/{NumberUtils.js => NumberUtils.ts} | 22 ++++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) rename src/libs/{NumberUtils.js => NumberUtils.ts} (79%) diff --git a/src/libs/NumberUtils.js b/src/libs/NumberUtils.ts similarity index 79% rename from src/libs/NumberUtils.js rename to src/libs/NumberUtils.ts index ee0b8a8fa397..0ae9b0bb715f 100644 --- a/src/libs/NumberUtils.js +++ b/src/libs/NumberUtils.ts @@ -1,11 +1,9 @@ -import _ from 'underscore'; import CONST from '../CONST'; /** * Generates a random positive 64 bit numeric string by randomly generating the left, middle, and right parts and concatenating them. Used to generate client-side ids. - * @returns {String} string representation of a randomly generated 64 bit signed integer */ -function rand64() { +function rand64(): string { // Max 64-bit signed: // 9,223,372,036,854,775,807 // The left part of the max 64-bit number *+1* because we're flooring it. @@ -38,24 +36,20 @@ function rand64() { /** * Returns a hexadecimal value of the specified length - * @param {Number} num - * @returns {String} */ -function generateHexadecimalValue(num) { - return _.times(num, () => Math.floor(Math.random() * 16).toString(16)) - .join('') - .toUpperCase(); +function generateHexadecimalValue(num: number): string { + const result: string[] = []; + for (let i = 0; i < num; i++) { + result.push(Math.floor(Math.random() * 16).toString(16)); + } + return result.join('').toUpperCase(); } /** * Generates a random integer between a and b * It's and equivalent of _.random(a, b) - * - * @param {Number} a - * @param {Number} b - * @returns {Number} random integer between a and b */ -function generateRandomInt(a, b) { +function generateRandomInt(a: number, b: number): number { const lower = Math.ceil(Math.min(a, b)); const upper = Math.floor(Math.max(a, b)); return Math.floor(lower + Math.random() * (upper - lower + 1)); From 274bef5e802a70e76801d225bd26538125d81439 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Mon, 11 Sep 2023 13:58:05 +0200 Subject: [PATCH 2/2] Add return descriptions --- src/libs/NumberUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/NumberUtils.ts b/src/libs/NumberUtils.ts index 0ae9b0bb715f..0d2b4135c5b6 100644 --- a/src/libs/NumberUtils.ts +++ b/src/libs/NumberUtils.ts @@ -2,6 +2,8 @@ import CONST from '../CONST'; /** * Generates a random positive 64 bit numeric string by randomly generating the left, middle, and right parts and concatenating them. Used to generate client-side ids. + * + * @returns string representation of a randomly generated 64 bit signed integer */ function rand64(): string { // Max 64-bit signed: @@ -48,6 +50,8 @@ function generateHexadecimalValue(num: number): string { /** * Generates a random integer between a and b * It's and equivalent of _.random(a, b) + * + * @returns random integer between a and b */ function generateRandomInt(a: number, b: number): number { const lower = Math.ceil(Math.min(a, b));