@tmlmobilidade/utils 20250725.154.46 → 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/index.d.ts CHANGED
@@ -2,12 +2,11 @@ export * from './src/batching/index.js';
2
2
  export * from './src/convert-object.js';
3
3
  export * from './src/dates/index.js';
4
4
  export * from './src/files/files.js';
5
- export * from './src/generate-random-string.js';
6
- export * from './src/generate-random-token.js';
7
5
  export * from './src/generic/index.js';
8
6
  export * from './src/geo/index.js';
9
7
  export * from './src/http.js';
10
8
  export * from './src/navigation/index.js';
11
9
  export * from './src/permissions.js';
10
+ export * from './src/random/index.js';
12
11
  export * from './src/singleton-proxy.js';
13
12
  export * from './src/strings/index.js';
package/dist/index.js CHANGED
@@ -2,12 +2,11 @@ export * from './src/batching/index.js';
2
2
  export * from './src/convert-object.js';
3
3
  export * from './src/dates/index.js';
4
4
  export * from './src/files/files.js';
5
- export * from './src/generate-random-string.js';
6
- export * from './src/generate-random-token.js';
7
5
  export * from './src/generic/index.js';
8
6
  export * from './src/geo/index.js';
9
7
  export * from './src/http.js';
10
8
  export * from './src/navigation/index.js';
11
9
  export * from './src/permissions.js';
10
+ export * from './src/random/index.js';
12
11
  export * from './src/singleton-proxy.js';
13
12
  export * from './src/strings/index.js';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generates a secure random number between 0 and 1.
3
+ * This function uses the Web Crypto API so it is suitable
4
+ * for cryptographic purposes.
5
+ * @returns A random number between 0 and 1
6
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
7
+ */
8
+ export declare function generateRandomNumber(): number;
@@ -0,0 +1,14 @@
1
+ /* * */
2
+ import crypto from 'crypto';
3
+ /**
4
+ * Generates a secure random number between 0 and 1.
5
+ * This function uses the Web Crypto API so it is suitable
6
+ * for cryptographic purposes.
7
+ * @returns A random number between 0 and 1
8
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
9
+ */
10
+ export function generateRandomNumber() {
11
+ const array = new Uint32Array(1);
12
+ crypto.getRandomValues(array);
13
+ return array[0] / 2 ** 32;
14
+ }
@@ -0,0 +1,12 @@
1
+ interface GenerateRandomStringProps {
2
+ length?: number;
3
+ type?: 'alphanumeric' | 'numeric';
4
+ }
5
+ /**
6
+ * Creates a random string of a given length and type.
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
+ * @returns A random string of the specified length.
10
+ */
11
+ export declare function generateRandomString({ length, type }: GenerateRandomStringProps): string;
12
+ export {};
@@ -1,11 +1,12 @@
1
1
  /* * */
2
+ import { generateRandomNumber } from './generate-random-number.js';
2
3
  /**
3
4
  * Creates a random string of a given length and type.
4
- * @param length - The length of the string to generate.
5
- * @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`.
6
7
  * @returns A random string of the specified length.
7
8
  */
8
- export function generateRandomString({ length = 6, type = 'alphanumeric' } = {}) {
9
+ export function generateRandomString({ length = 6, type = 'alphanumeric' }) {
9
10
  //
10
11
  const numericSet = '0123456789';
11
12
  const alphanumericSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
@@ -20,7 +21,7 @@ export function generateRandomString({ length = 6, type = 'alphanumeric' } = {})
20
21
  }
21
22
  let result = '';
22
23
  for (let i = 0; i < length; i++) {
23
- result += allowedCharacters.charAt(Math.floor(Math.random() * allowedCharacters.length));
24
+ result += allowedCharacters.charAt(Math.floor(generateRandomNumber() * allowedCharacters.length));
24
25
  }
25
26
  return result;
26
27
  //
@@ -0,0 +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
+ */
8
+ export declare function generateRandomToken(): string;
@@ -0,0 +1,12 @@
1
+ /* * */
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
+ */
10
+ export function generateRandomToken() {
11
+ return crypto.randomBytes(32).toString('hex');
12
+ }
@@ -0,0 +1,3 @@
1
+ export * from './generate-random-number.js';
2
+ export * from './generate-random-string.js';
3
+ export * from './generate-random-token.js';
@@ -0,0 +1,3 @@
1
+ export * from './generate-random-number.js';
2
+ export * from './generate-random-string.js';
3
+ export * from './generate-random-token.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/utils",
3
- "version": "20250725.154.46",
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.15",
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",
@@ -1,12 +0,0 @@
1
- interface GenerateRandomStringOptions {
2
- length?: number;
3
- type?: 'alphanumeric' | 'numeric';
4
- }
5
- /**
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.
9
- * @returns A random string of the specified length.
10
- */
11
- export declare function generateRandomString({ length, type }?: GenerateRandomStringOptions): string;
12
- export {};
@@ -1 +0,0 @@
1
- export declare function generateRandomToken(): string;
@@ -1,6 +0,0 @@
1
- /* * */
2
- import { v4 as uuid } from 'uuid';
3
- /* * */
4
- export function generateRandomToken() {
5
- return Buffer.from(uuid()).toString('base64');
6
- }