This commit is contained in:
Harvey Zack committed 2018-10-22 10:54:19 +08:00
1 parent 1d1bf15f0d
commit 8b6258c4e5
11 files changed
+331 -169

No files matched your search

+24 -2
View File
@@ -1,7 +1,8 @@
import ArtPlayerError from './ArtPlayerError';
export function errorHandle(condition, msg) {
if (!condition) {
const isFun = typeof condition === 'function';
if (isFun ? !isFun() : !condition) {
throw new ArtPlayerError(msg);
}
}
@@ -43,9 +44,30 @@ export function setStyle(element, styles) {
}
export function secondToTime(second) {
const add0 = num => num < 10 ? `0${num}` : String(num);
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 deepMerge(...sources) {
const isObject = value => value !== null && typeof value === 'object';
let returnValue = {};
for (const source of sources) {
if (Array.isArray(source)) {
if (!Array.isArray(returnValue)) {
returnValue = [];
}
returnValue = [...returnValue, ...source];
} else if (isObject(source)) {
for (let [key, value] of Object.entries(source)) {
if (isObject(value) && Reflect.has(returnValue, key)) {
value = deepMerge(returnValue[key], value);
}
returnValue = { ...returnValue, [key]: value };
}
}
}
return returnValue;
}