mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-16 09:36:16 -08:00
41 lines
753 B
JavaScript
41 lines
753 B
JavaScript
import ArtPlayerError from './ArtPlayerError';
|
|
|
|
export function errorHandle(condition, msg) {
|
|
if (!condition) {
|
|
throw new ArtPlayerError(msg);
|
|
}
|
|
}
|
|
|
|
export function clamp(num, a, b) {
|
|
return Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
|
|
}
|
|
|
|
export function getExt(url) {
|
|
if (url.includes('?')) {
|
|
return getExt(url.split('?')[0]);
|
|
}
|
|
|
|
return url
|
|
.trim()
|
|
.toLowerCase()
|
|
.split('.')
|
|
.pop();
|
|
}
|
|
|
|
|
|
export function append(parent, child) {
|
|
if (child instanceof Element) {
|
|
parent.appendChild(child);
|
|
} else {
|
|
parent.innerHTML = child;
|
|
}
|
|
return parent;
|
|
}
|
|
|
|
export function setStyle(element, styles) {
|
|
Object.keys(styles).forEach(key => {
|
|
element.style[key] = styles[key];
|
|
});
|
|
return element;
|
|
}
|