新建项目
This commit is contained in:
30
utils/format.js
Normal file
30
utils/format.js
Normal file
@@ -0,0 +1,30 @@
|
||||
function pad(value) {
|
||||
return String(value).padStart(2, "0");
|
||||
}
|
||||
|
||||
function formatCountdown(totalSeconds) {
|
||||
const safe = Math.max(0, Math.floor(totalSeconds || 0));
|
||||
const minutes = Math.floor(safe / 60);
|
||||
const seconds = safe % 60;
|
||||
return `${pad(minutes)}:${pad(seconds)}`;
|
||||
}
|
||||
|
||||
function formatTime(timestamp) {
|
||||
const date = new Date(timestamp);
|
||||
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
||||
}
|
||||
|
||||
function randomCode() {
|
||||
return String(Math.floor(100000 + Math.random() * 900000));
|
||||
}
|
||||
|
||||
function clone(value) {
|
||||
return JSON.parse(JSON.stringify(value));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatCountdown,
|
||||
formatTime,
|
||||
randomCode,
|
||||
clone
|
||||
};
|
||||
Reference in New Issue
Block a user