/**
* MultiScannerElement Utils
*
* Utility Functions
*/
/**
* Converts a snake case (or hyphenated) string to camel case.
*
* @param str
*/
function snakeToCamel(str) {
if (!/[_-]/.test(str)) return str;
return str
.toLowerCase()
.replace(/([-_])([a-z])/g, (_match, _p1, p2) => p2.toUpperCase());
}
/**
* Joins a camel case string with a provided char.
*
* @param str
* @param char
*/
function camelJoin(str, char = '-') {
const result = str.replace(/([A-Z])/g, ' $1');
return result.split(' ').join(char).toLowerCase();
}
// Begin UTILITY method /getOS/
/**
* Gets the Current operating system.
*
* @memberof sg.util
* @protected
* @function
* @returns {string} - Type of OS.
*/
function getOS() {
const userAgent = window.navigator.userAgent;
const platform = window.navigator.platform;
const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'];
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
const iosPlatforms = ['iPhone', 'iPad', 'iPod'];
let os = null;
if (macosPlatforms.indexOf(platform) !== -1) {
os = 'Mac OS';
} else if (iosPlatforms.indexOf(platform) !== -1) {
os = 'iOS';
} else if (windowsPlatforms.indexOf(platform) !== -1) {
os = 'Windows';
} else if (/Android/.test(userAgent)) {
os = 'Android';
} else if (!os && /Linux/.test(platform)) {
os = 'Linux';
}
return os;
}
// END-- UTILITY method /getOS/
export { snakeToCamel, camelJoin };