@tmlmobilidade/utils 20250725.239.2 → 20250725.246.45
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/dist/src/random/generate-random-number.js +2 -2
- package/dist/src/random/generate-random-string.d.ts +2 -2
- package/dist/src/random/generate-random-string.js +2 -2
- package/dist/src/random/generate-random-token.d.ts +7 -0
- package/dist/src/random/generate-random-token.js +9 -3
- package/package.json +2 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import
|
|
2
|
+
import crypto from 'crypto';
|
|
3
3
|
/**
|
|
4
4
|
* Generates a secure random number between 0 and 1.
|
|
5
5
|
* This function uses the Web Crypto API so it is suitable
|
|
@@ -9,6 +9,6 @@ import webcrypto from 'crypto';
|
|
|
9
9
|
*/
|
|
10
10
|
export function generateRandomNumber() {
|
|
11
11
|
const array = new Uint32Array(1);
|
|
12
|
-
|
|
12
|
+
crypto.getRandomValues(array);
|
|
13
13
|
return array[0] / 2 ** 32;
|
|
14
14
|
}
|
|
@@ -4,8 +4,8 @@ interface GenerateRandomStringProps {
|
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
6
|
* Creates a random string of a given length and type.
|
|
7
|
-
* @param length The length of the string to generate.
|
|
8
|
-
* @param type The type of characters to include in the string.
|
|
7
|
+
* @param length The length of the string to generate. Defaults to `6`.
|
|
8
|
+
* @param type The type of characters to include in the string. Defaults to `alphanumeric`.
|
|
9
9
|
* @returns A random string of the specified length.
|
|
10
10
|
*/
|
|
11
11
|
export declare function generateRandomString({ length, type }: GenerateRandomStringProps): string;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { generateRandomNumber } from './generate-random-number.js';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a random string of a given length and type.
|
|
5
|
-
* @param length The length of the string to generate.
|
|
6
|
-
* @param type The type of characters to include in the string.
|
|
5
|
+
* @param length The length of the string to generate. Defaults to `6`.
|
|
6
|
+
* @param type The type of characters to include in the string. Defaults to `alphanumeric`.
|
|
7
7
|
* @returns A random string of the specified length.
|
|
8
8
|
*/
|
|
9
9
|
export function generateRandomString({ length = 6, type = 'alphanumeric' }) {
|
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a secure random token.
|
|
3
|
+
* This function uses the Node.js crypto module to generate
|
|
4
|
+
* a random token suitable for cryptographic purposes.
|
|
5
|
+
* @returns A random token as a hexadecimal string.
|
|
6
|
+
* @see https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback
|
|
7
|
+
*/
|
|
1
8
|
export declare function generateRandomToken(): string;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
/**
|
|
4
|
+
* Generates a secure random token.
|
|
5
|
+
* This function uses the Node.js crypto module to generate
|
|
6
|
+
* a random token suitable for cryptographic purposes.
|
|
7
|
+
* @returns A random token as a hexadecimal string.
|
|
8
|
+
* @see https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback
|
|
9
|
+
*/
|
|
4
10
|
export function generateRandomToken() {
|
|
5
|
-
return
|
|
11
|
+
return crypto.randomBytes(32).toString('hex');
|
|
6
12
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmlmobilidade/utils",
|
|
3
|
-
"version": "20250725.
|
|
3
|
+
"version": "20250725.246.45",
|
|
4
4
|
"author": "João de Vasconcelos & Jusi Monteiro",
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"homepage": "https://github.com/tmlmobilidade/services#readme",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"luxon": "3.7.1",
|
|
48
48
|
"mergekit": "3.0.6",
|
|
49
49
|
"papaparse": "5.5.3",
|
|
50
|
-
"uuid": "11.1.0",
|
|
51
50
|
"zod": "3.25.76"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
@@ -55,7 +54,7 @@
|
|
|
55
54
|
"@tmlmobilidade/tsconfig": "*",
|
|
56
55
|
"@tmlmobilidade/types": "*",
|
|
57
56
|
"@types/luxon": "3.6.2",
|
|
58
|
-
"@types/node": "24.0
|
|
57
|
+
"@types/node": "24.1.0",
|
|
59
58
|
"@types/papaparse": "5.3.16",
|
|
60
59
|
"resolve-tspaths": "0.8.23",
|
|
61
60
|
"rimraf": "6.0.1",
|