UNPKG

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