Updates galore. Improved folder structure, componentized, and notifications upon completion.
This commit is contained in:
parent
b48784e2ad
commit
7e0502ca40
33 changed files with 3565 additions and 728 deletions
45
static/js/modules/utils.js
Normal file
45
static/js/modules/utils.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* utils.js
|
||||
* --------
|
||||
* Pure utility functions with no DOM or state dependencies.
|
||||
* Safe to import anywhere without side-effects.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Escape a string for safe insertion into HTML.
|
||||
* @param {*} str
|
||||
* @returns {string}
|
||||
*/
|
||||
export function esc(str) {
|
||||
if (!str) return '';
|
||||
return String(str)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a duration in seconds as M:SS or H:MM:SS.
|
||||
* @param {number} seconds
|
||||
* @returns {string}
|
||||
*/
|
||||
export function fmtTime(seconds) {
|
||||
const s = Math.floor(seconds);
|
||||
const h = Math.floor(s / 3600);
|
||||
const m = Math.floor((s % 3600) / 60);
|
||||
const sec = s % 60;
|
||||
return h > 0
|
||||
? `${h}:${pad(m)}:${pad(sec)}`
|
||||
: `${m}:${pad(sec)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zero-pad a number to at least 2 digits.
|
||||
* @param {number} n
|
||||
* @returns {string}
|
||||
*/
|
||||
export function pad(n) {
|
||||
return String(n).padStart(2, '0');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue