@tmlmobilidade/utils 20250725.154.46 → 20250725.239.2
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 +1 -2
- package/dist/index.js +1 -2
- package/dist/src/random/generate-random-number.d.ts +8 -0
- package/dist/src/random/generate-random-number.js +14 -0
- package/dist/src/random/generate-random-string.d.ts +12 -0
- package/dist/src/{generate-random-string.js → random/generate-random-string.js} +5 -4
- package/dist/src/random/index.d.ts +3 -0
- package/dist/src/random/index.js +3 -0
- package/package.json +1 -1
- package/dist/src/generate-random-string.d.ts +0 -12
- /package/dist/src/{generate-random-token.d.ts → random/generate-random-token.d.ts} +0 -0
- /package/dist/src/{generate-random-token.js → random/generate-random-token.js} +0 -0
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 webcrypto 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
|
+
webcrypto.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.
|
|
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 }: 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
|
|
5
|
-
* @param type
|
|
5
|
+
* @param length The length of the string to generate.
|
|
6
|
+
* @param type The type of characters to include in the string.
|
|
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(
|
|
24
|
+
result += allowedCharacters.charAt(Math.floor(generateRandomNumber() * allowedCharacters.length));
|
|
24
25
|
}
|
|
25
26
|
return result;
|
|
26
27
|
//
|
package/package.json
CHANGED
|
@@ -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 {};
|
|
File without changes
|
|
File without changes
|