toArray.js 656 B

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