mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
30 lines
669 B
JavaScript
30 lines
669 B
JavaScript
const hasOwn = {}.hasOwnProperty;
|
|
|
|
export function classNames() {
|
|
const classes = [];
|
|
|
|
for (let i = 0; i < arguments.length; i++) {
|
|
const arg = arguments[i];
|
|
if (!arg) continue;
|
|
|
|
const argType = typeof arg;
|
|
|
|
if (argType === 'string' || argType === 'number') {
|
|
classes.push(arg);
|
|
} else if (Array.isArray(arg) && arg.length) {
|
|
const inner = classNames.apply(null, arg);
|
|
if (inner) {
|
|
classes.push(inner);
|
|
}
|
|
} else if (argType === 'object') {
|
|
for (const key in arg) {
|
|
if (hasOwn.call(arg, key) && arg[key]) {
|
|
classes.push(key);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return classes.join(' ');
|
|
};
|