UNPKG

@zohodesk/utils

Version:

Unified Component Library - Utils

29 lines (24 loc) 1.11 kB
import dataTypes, { isDataTypeOf } from "./dataTypes"; import { hasOwnProperty } from "./objectUtils"; const collectClassNames = function (processedClassNameList) { for (let index = 0; index < (arguments.length <= 1 ? 0 : arguments.length - 1); index++) { let classInfo = index + 1 < 1 || arguments.length <= index + 1 ? undefined : arguments[index + 1]; if (!classInfo) { continue; } else if (isDataTypeOf(classInfo, dataTypes.object)) { for (let property in classInfo) { if (hasOwnProperty.call(classInfo, property) && property !== 'undefined' && property !== 'null' && classInfo[property] && !processedClassNameList.includes(property)) { processedClassNameList.push(property); } } } } }; export default function compileClassNames() { let resultClassNameList = []; for (var _len = arguments.length, classinfoList = new Array(_len), _key = 0; _key < _len; _key++) { classinfoList[_key] = arguments[_key]; } collectClassNames(resultClassNameList, ...classinfoList); return resultClassNameList.filter(a => a !== '').join(' '); }