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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function snapPositionToGrid(position, gridSize) {
|
|
|
|
|
return {
|
|
|
|
|
x: roundTo(position.x, gridSize.x),
|
|
|
|
|
y: roundTo(position.y, gridSize.y),
|
|
|
|
|
};
|
|
|
|
|
}
|