mixed.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2. /**
  3. * Converts any value to string.
  4. *
  5. * @param {*} value
  6. * @returns {String}
  7. */
  8. export function stringify(value) {
  9. var result = void 0;
  10. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  11. case 'string':
  12. case 'number':
  13. result = '' + value;
  14. break;
  15. case 'object':
  16. result = value === null ? '' : value.toString();
  17. break;
  18. case 'undefined':
  19. result = '';
  20. break;
  21. default:
  22. result = value.toString();
  23. break;
  24. }
  25. return result;
  26. }
  27. /**
  28. * Checks if given variable is defined.
  29. *
  30. * @param {*} variable Variable to check.
  31. * @returns {Boolean}
  32. */
  33. export function isDefined(variable) {
  34. return typeof variable !== 'undefined';
  35. }
  36. /**
  37. * Checks if given variable is undefined.
  38. *
  39. * @param {*} variable Variable to check.
  40. * @returns {Boolean}
  41. */
  42. export function isUndefined(variable) {
  43. return typeof variable === 'undefined';
  44. }
  45. /**
  46. * Check if given variable is null, empty string or undefined.
  47. *
  48. * @param {*} variable Variable to check.
  49. * @returns {Boolean}
  50. */
  51. export function isEmpty(variable) {
  52. return variable === null || variable === '' || isUndefined(variable);
  53. }
  54. /**
  55. * Check if given variable is a regular expression.
  56. *
  57. * @param {*} variable Variable to check.
  58. * @returns {Boolean}
  59. */
  60. export function isRegExp(variable) {
  61. return Object.prototype.toString.call(variable) === '[object RegExp]';
  62. }