utils.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. return props.navigation && typeof props.navigation.nextEl === 'undefined' && typeof props.navigation.prevEl === 'undefined';
  16. }
  17. function needsPagination(props = {}) {
  18. return props.pagination && typeof props.pagination.el === 'undefined';
  19. }
  20. function needsScrollbar(props = {}) {
  21. return props.scrollbar && typeof props.scrollbar.el === 'undefined';
  22. }
  23. function uniqueClasses(classNames = '') {
  24. const classes = classNames.split(' ').map(c => c.trim()).filter(c => !!c);
  25. const unique = [];
  26. classes.forEach(c => {
  27. if (unique.indexOf(c) < 0) unique.push(c);
  28. });
  29. return unique.join(' ');
  30. }
  31. export { isObject, extend, needsNavigation, needsPagination, needsScrollbar, uniqueClasses };