e1ec2ecd635af074a61c0b5d1a0321b2b2478c8a4caf8b41e0560d01754bd1377ced8aff955203c706670c21869f4bc77d774ca4e2c32f16d85792e6060333 1.8 KB

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