2023-05-22 00:12:14 +03:00
|
|
|
import UAParser from 'ua-parser-js';
|
|
|
|
|
2020-08-13 11:28:25 +03:00
|
|
|
export function pluralize(string, count) {
|
2020-06-18 20:24:54 +03:00
|
|
|
if (count === 1) {
|
|
|
|
return string;
|
|
|
|
}
|
2022-05-26 23:52:04 +03:00
|
|
|
return `${string}s`;
|
2020-06-18 20:24:54 +03:00
|
|
|
}
|
|
|
|
|
2021-06-20 20:49:16 +03:00
|
|
|
export function getDiffInDaysFromNow(timestamp) {
|
|
|
|
const time = typeof timestamp === 'string' ? new Date(timestamp) : timestamp;
|
|
|
|
return (new Date() - time) / (24 * 3600 * 1000);
|
|
|
|
}
|
|
|
|
|
2022-10-19 05:44:42 +03:00
|
|
|
// 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;
|
|
|
|
}, {});
|
|
|
|
}
|
2023-05-22 00:12:14 +03:00
|
|
|
|
|
|
|
export const isMobileSafariIos = () => {
|
|
|
|
try {
|
|
|
|
const ua = navigator.userAgent;
|
|
|
|
const uaParser = new UAParser(ua);
|
|
|
|
const browser = uaParser.getBrowser();
|
|
|
|
const device = uaParser.getDevice();
|
|
|
|
|
|
|
|
if (device.vendor !== 'Apple') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device.type !== 'mobile' && device.type !== 'tablet') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return browser.name === 'Mobile Safari' || browser.name === 'Safari';
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isMobileSafariHomeScreenApp = () => {
|
|
|
|
if (!isMobileSafariIos()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'standalone' in window.navigator && window.navigator.standalone;
|
|
|
|
};
|