You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

detectDevices.js 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Returns true if user agent is run on Android.
  3. *
  4. * @returns {boolean}
  5. */
  6. export function detectAndroid() {
  7. return Boolean(navigator.userAgent.match(/Android/i));
  8. }
  9. /**
  10. * Returns true if user agent is run on iOS.
  11. *
  12. * @returns {boolean}
  13. */
  14. export function detectIOS() {
  15. if (navigator.userAgent.match(/iPhone/i)
  16. || navigator.userAgent.match(/iPad/i)
  17. || navigator.userAgent.match(/iPod/i)) {
  18. return true;
  19. }
  20. return false;
  21. }
  22. /**
  23. * Transforms hash map with parameters to query string.
  24. *
  25. * @param {Object} params - Hash map to be processed into query string.
  26. * @returns {string}
  27. */
  28. export function serializeQuery(params) {
  29. return Object.keys(params).reduce((str, key, index) => {
  30. const encodedKey = encodeURIComponent(key);
  31. const encodedValue = encodeURIComponent(params[key]);
  32. let separator = '&';
  33. if (index === 0) {
  34. separator = '?';
  35. }
  36. return `${str}${separator}${encodedKey}=${encodedValue}`;
  37. }, '');
  38. }