Moved applet-core functionalities to individual libs, Updated UUID and IBAN generators
Update iban-generator.mjs, uuid-generator.mjs, and 4 more files...
This commit is contained in:
18
static/resources/NibblePoker/libs/download-helper.mjs
Normal file
18
static/resources/NibblePoker/libs/download-helper.mjs
Normal file
@@ -0,0 +1,18 @@
|
||||
// NibblePoker - Download Helpers
|
||||
// Author: Herwin Bozet (@NibblePoker)
|
||||
// License: Public Domain (This code, except for the data)
|
||||
|
||||
export function downloadStringAsFile(content, filename, contentType) {
|
||||
const blob = new Blob([content], { type: contentType });
|
||||
const link = document.createElement('a');
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
36
static/resources/NibblePoker/libs/input-utils.mjs
Normal file
36
static/resources/NibblePoker/libs/input-utils.mjs
Normal file
@@ -0,0 +1,36 @@
|
||||
// NibblePoker - HTML Input Utils
|
||||
// Author: Herwin Bozet (@NibblePoker)
|
||||
// License: Public Domain (This code)
|
||||
|
||||
/**
|
||||
* Retrieves the number from an `HTMLInputElement`
|
||||
* @param eInput {HTMLInputElement} The `HTMLInputElement` from which the value will be retrieved.
|
||||
* @param min {number|null} If given, sets a minimum the value can have when returned.
|
||||
* @param max {number|null} If given, sets a maximum the value can have when returned.
|
||||
* @returns {number} The value from the given `HTMLInputElement`, or `1` if no valid one was given.
|
||||
*/
|
||||
export function getInputCount(eInput, min = null, max = null) {
|
||||
let desiredCount = null;
|
||||
try {
|
||||
desiredCount = parseInt(eInput.value);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
if (desiredCount === null) {
|
||||
desiredCount = 1;
|
||||
}
|
||||
|
||||
if (typeof min === 'number') {
|
||||
if (desiredCount < min) {
|
||||
desiredCount = min;
|
||||
}
|
||||
}
|
||||
if (typeof max === 'number') {
|
||||
if (desiredCount > max) {
|
||||
desiredCount = max;
|
||||
}
|
||||
}
|
||||
|
||||
return desiredCount;
|
||||
}
|
||||
14
static/resources/NibblePoker/libs/uuid.mjs
Normal file
14
static/resources/NibblePoker/libs/uuid.mjs
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Generates a random UUID4 and returns its string representation
|
||||
* @returns {`${string}-${string}-${string}-${string}-${string}`}
|
||||
*/
|
||||
export function generateUUID4(addHyphens, addGuidBrackets) {
|
||||
let uuid4 = crypto.randomUUID();
|
||||
if(!addHyphens) {
|
||||
uuid4 = uuid4.replace(/-/g, "");
|
||||
}
|
||||
if(addGuidBrackets) {
|
||||
uuid4 = "{" + uuid4 + "}";
|
||||
}
|
||||
return uuid4;
|
||||
}
|
||||
Reference in New Issue
Block a user