owncast/web/utils/helpers.js

23 lines
558 B
JavaScript
Raw Normal View History

export function pluralize(string, count) {
2020-06-18 20:24:54 +03:00
if (count === 1) {
return string;
}
return `${string}s`;
2020-06-18 20:24:54 +03:00
}
export function getDiffInDaysFromNow(timestamp) {
const time = typeof timestamp === 'string' ? new Date(timestamp) : timestamp;
return (new Date() - time) / (24 * 3600 * 1000);
}
// Take a nested object of state metadata and merge it into
// a single flattened node.
export function mergeMeta(meta) {
return Object.keys(meta).reduce((acc, key) => {
const value = meta[key];
Object.assign(acc, value);
return acc;
}, {});
}