kcommons 14.12.0 → 14.12.1
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/build/index.d.ts
CHANGED
|
@@ -105,6 +105,7 @@ export * from "./utils/convertDurationToreadableFormat.util";
|
|
|
105
105
|
export * from "./utils/extra-form/formatValidationSchema.util";
|
|
106
106
|
export * from "./utils/extra-form/getFormProps.util";
|
|
107
107
|
export * from "./utils/extra-form/getDefaultVAlues.util";
|
|
108
|
+
export * from "./utils/generateId.util";
|
|
108
109
|
export * from "./typings/verification_apis/pincode.typings";
|
|
109
110
|
export * from "./typings/verification_apis/gstVerification.typings";
|
|
110
111
|
export * from "./typings/verification_apis/udyamVerification.typings";
|
package/build/index.js
CHANGED
|
@@ -129,6 +129,7 @@ __exportStar(require("./utils/convertDurationToreadableFormat.util"), exports);
|
|
|
129
129
|
__exportStar(require("./utils/extra-form/formatValidationSchema.util"), exports);
|
|
130
130
|
__exportStar(require("./utils/extra-form/getFormProps.util"), exports);
|
|
131
131
|
__exportStar(require("./utils/extra-form/getDefaultVAlues.util"), exports);
|
|
132
|
+
__exportStar(require("./utils/generateId.util"), exports);
|
|
132
133
|
// Templates
|
|
133
134
|
// Verification APIs
|
|
134
135
|
__exportStar(require("./typings/verification_apis/pincode.typings"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const VALID_CODE_CHARACTERS: string[];
|
|
2
|
+
/**
|
|
3
|
+
* Generates a secure random code of a given length
|
|
4
|
+
* using the provided character set.
|
|
5
|
+
*
|
|
6
|
+
* @param length - Desired length of the generated code
|
|
7
|
+
* @param characters - Array of allowed characters
|
|
8
|
+
* @returns Randomly generated code
|
|
9
|
+
*
|
|
10
|
+
* @throws Error if inputs are invalid
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateID(length: number): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VALID_CODE_CHARACTERS = void 0;
|
|
4
|
+
exports.generateID = generateID;
|
|
5
|
+
exports.VALID_CODE_CHARACTERS = [
|
|
6
|
+
..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
7
|
+
..."1234567890",
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* Generates a secure random code of a given length
|
|
11
|
+
* using the provided character set.
|
|
12
|
+
*
|
|
13
|
+
* @param length - Desired length of the generated code
|
|
14
|
+
* @param characters - Array of allowed characters
|
|
15
|
+
* @returns Randomly generated code
|
|
16
|
+
*
|
|
17
|
+
* @throws Error if inputs are invalid
|
|
18
|
+
*/
|
|
19
|
+
function generateID(length) {
|
|
20
|
+
if (!Number.isInteger(length) || length <= 0) {
|
|
21
|
+
throw new Error("Length must be a positive integer");
|
|
22
|
+
}
|
|
23
|
+
const charsetLength = exports.VALID_CODE_CHARACTERS.length;
|
|
24
|
+
const randomValues = new Uint32Array(length);
|
|
25
|
+
// Browser & Node.js compatible crypto
|
|
26
|
+
if (typeof crypto === "undefined" || !crypto.getRandomValues) {
|
|
27
|
+
throw new Error("Secure crypto API not available");
|
|
28
|
+
}
|
|
29
|
+
crypto.getRandomValues(randomValues);
|
|
30
|
+
let result = "";
|
|
31
|
+
for (let i = 0; i < length; i++) {
|
|
32
|
+
result += exports.VALID_CODE_CHARACTERS[randomValues[i] % charsetLength];
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|