utils.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function isObject(o) {
  2. return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) === 'Object';
  3. }
  4. function extend(target, src) {
  5. const noExtend = ['__proto__', 'constructor', 'prototype'];
  6. Object.keys(src).filter(key => noExtend.indexOf(key) < 0).forEach(key => {
  7. if (typeof target[key] === 'undefined') target[key] = src[key];else if (isObject(src[key]) && isObject(target[key]) && Object.keys(src[key]).length > 0) {
  8. if (src[key].__swiper__) target[key] = src[key];else extend(target[key], src[key]);
  9. } else {
  10. target[key] = src[key];
  11. }
  12. });
  13. }
  14. function needsNavigation(props) {
  15. if (props === void 0) {
  16. props = {};
  17. }
  18. return props.navigation && typeof props.navigation.nextEl === 'undefined' && typeof props.navigation.prevEl === 'undefined';
  19. }
  20. function needsPagination(props) {
  21. if (props === void 0) {
  22. props = {};
  23. }
  24. return props.pagination && typeof props.pagination.el === 'undefined';
  25. }
  26. function needsScrollbar(props) {
  27. if (props === void 0) {
  28. props = {};
  29. }
  30. return props.scrollbar && typeof props.scrollbar.el === 'undefined';
  31. }
  32. function uniqueClasses(classNames) {
  33. if (classNames === void 0) {
  34. classNames = '';
  35. }
  36. const classes = classNames.split(' ').map(c => c.trim()).filter(c => !!c);
  37. const unique = [];
  38. classes.forEach(c => {
  39. if (unique.indexOf(c) < 0) unique.push(c);
  40. });
  41. return unique.join(' ');
  42. }
  43. export { isObject, extend, needsNavigation, needsPagination, needsScrollbar, uniqueClasses };