toString.js 751 B

123456789101112131415
  1. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  2. export default function toString(input) {
  3. if (_typeof(input) === 'object' && input !== null) {
  4. if (typeof input.toString === 'function') {
  5. input = input.toString();
  6. } else {
  7. input = '[object Object]';
  8. }
  9. } else if (input === null || typeof input === 'undefined' || isNaN(input) && !input.length) {
  10. input = '';
  11. }
  12. return String(input);
  13. }