should-util.js 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  2. var _propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
  3. function hasOwnProperty(obj, key) {
  4. return _hasOwnProperty.call(obj, key);
  5. }
  6. function propertyIsEnumerable(obj, key) {
  7. return _propertyIsEnumerable.call(obj, key);
  8. }
  9. function merge(a, b) {
  10. if (a && b) {
  11. for (var key in b) {
  12. a[key] = b[key];
  13. }
  14. }
  15. return a;
  16. }
  17. function isIterator(obj) {
  18. if (!obj) {
  19. return false;
  20. }
  21. if (obj.__shouldIterator__) {
  22. return true;
  23. }
  24. return typeof obj.next === 'function' &&
  25. typeof Symbol === 'function' &&
  26. typeof Symbol.iterator === 'symbol' &&
  27. typeof obj[Symbol.iterator] === 'function' &&
  28. obj[Symbol.iterator]() === obj;
  29. }
  30. //TODO find better way
  31. function isGeneratorFunction(f) {
  32. return typeof f === 'function' && /^function\s*\*\s*/.test(f.toString());
  33. }
  34. export { hasOwnProperty, propertyIsEnumerable, merge, isIterator, isGeneratorFunction };