mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-12 15:26:16 -08:00
34 lines
930 B
JavaScript
34 lines
930 B
JavaScript
export function clamp(num, a, b) {
|
|
return Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
|
|
}
|
|
|
|
export function capitalize(str) {
|
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
}
|
|
|
|
export function isStringOrNumber(val) {
|
|
return ['string', 'number'].includes(typeof val);
|
|
}
|
|
|
|
export function secondToTime(second) {
|
|
const add0 = (num) => (num < 10 ? `0${num}` : String(num));
|
|
const hour = Math.floor(second / 3600);
|
|
const min = Math.floor((second - hour * 3600) / 60);
|
|
const sec = Math.floor(second - hour * 3600 - min * 60);
|
|
return (hour > 0 ? [hour, min, sec] : [min, sec]).map(add0).join(':');
|
|
}
|
|
|
|
export function escape(str) {
|
|
return str.replace(
|
|
/[&<>'"]/g,
|
|
(tag) =>
|
|
({
|
|
'&': '&',
|
|
'<': '<',
|
|
'>': '>',
|
|
"'": ''',
|
|
'"': '"',
|
|
}[tag] || tag),
|
|
);
|
|
}
|