2020-03-20 13:33:12 +11:00
|
|
|
export function omit(obj, keys) {
|
|
|
|
|
let tmp = {};
|
|
|
|
|
for (let [key, value] of Object.entries(obj)) {
|
|
|
|
|
if (keys.includes(key)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
tmp[key] = value;
|
|
|
|
|
}
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
2020-04-07 12:48:10 +10:00
|
|
|
|
|
|
|
|
export function fromEntries(iterable) {
|
|
|
|
|
if (Object.fromEntries) {
|
|
|
|
|
return Object.fromEntries(iterable);
|
|
|
|
|
}
|
|
|
|
|
return [...iterable].reduce((obj, [key, val]) => {
|
|
|
|
|
obj[key] = val;
|
|
|
|
|
return obj;
|
|
|
|
|
}, {});
|
|
|
|
|
}
|
2020-04-08 19:56:14 +10:00
|
|
|
|
|
|
|
|
// Check to see if all tracks are muted
|
|
|
|
|
export function isStreamStopped(stream) {
|
|
|
|
|
return stream.getTracks().reduce((a, b) => a && b, { mute: true });
|
|
|
|
|
}
|
2020-04-20 15:17:56 +10:00
|
|
|
|
|
|
|
|
export function roundTo(x, to) {
|
|
|
|
|
return Math.round(x / to) * to;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 21:39:21 +10:00
|
|
|
export function toRadians(angle) {
|
|
|
|
|
return angle * (Math.PI / 180);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function toDegrees(angle) {
|
|
|
|
|
return angle * (180 / Math.PI);
|
|
|
|
|
}
|
2020-05-26 10:57:12 +10:00
|
|
|
|
|
|
|
|
export function lerp(a, b, alpha) {
|
|
|
|
|
return a * (1 - alpha) + b * alpha;
|
|
|
|
|
}
|
2020-05-31 15:35:03 +10:00
|
|
|
|
|
|
|
|
// Console log an image
|
|
|
|
|
export function logImage(url, width, height) {
|
|
|
|
|
const style = [
|
|
|
|
|
"font-size: 1px;",
|
|
|
|
|
`padding: ${height}px ${width}px;`,
|
|
|
|
|
`background: url(${url}) no-repeat;`,
|
|
|
|
|
"background-size: contain;",
|
|
|
|
|
].join(" ");
|
|
|
|
|
console.log("%c ", style);
|
|
|
|
|
}
|
2020-06-27 11:18:10 +10:00
|
|
|
|
|
|
|
|
export function isEmpty(obj) {
|
|
|
|
|
return Object.keys(obj).length === 0 && obj.constructor === Object;
|
|
|
|
|
}
|
2020-10-01 15:05:06 +10:00
|
|
|
|
|
|
|
|
export function keyBy(array, key) {
|
|
|
|
|
return array.reduce(
|
|
|
|
|
(prev, current) => ({ ...prev, [key ? current[key] : current]: current }),
|
|
|
|
|
{}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function groupBy(array, key) {
|
|
|
|
|
return array.reduce((prev, current) => {
|
|
|
|
|
const k = current[key];
|
|
|
|
|
(prev[k] || (prev[k] = [])).push(current);
|
|
|
|
|
return prev;
|
|
|
|
|
}, {});
|
|
|
|
|
}
|
2020-10-17 09:37:39 +11:00
|
|
|
|
|
|
|
|
export const isMacLike = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
|