No Description

toArray.js 733B

12345678910111213141516171819202122
  1. var isArray = require('./isArray.js');
  2. var _setup = require('./_setup.js');
  3. var isString = require('./isString.js');
  4. var _isArrayLike = require('./_isArrayLike.js');
  5. var map = require('./map.js');
  6. var identity = require('./identity.js');
  7. var values = require('./values.js');
  8. // Safely create a real, live array from anything iterable.
  9. var reStrSymbol = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
  10. function toArray(obj) {
  11. if (!obj) return [];
  12. if (isArray(obj)) return _setup.slice.call(obj);
  13. if (isString(obj)) {
  14. // Keep surrogate pair characters together.
  15. return obj.match(reStrSymbol);
  16. }
  17. if (_isArrayLike(obj)) return map(obj, identity);
  18. return values(obj);
  19. }
  20. module.exports = toArray;