Last active
January 6, 2019 07:29
-
-
Save malcolm-kee/30cd26b80c5f45e443ae44dd5a3b4f01 to your computer and use it in GitHub Desktop.
A common utility to generate string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const joinString = (delimiter, ...params) => { | |
const results = []; | |
for (let param of params) { | |
if (!param) { | |
continue; | |
} | |
const paramType = typeof param; | |
if (paramType == 'string' || paramType == 'number') { | |
results.push(param); | |
continue; | |
} | |
if (Array.isArray(param) && param.length > 0) { | |
const innerResult = joinString(delimiter, ...param); | |
if (innerResult) { | |
results.push(innerResult); | |
} | |
} | |
} | |
return results.join(delimiter); | |
}; | |
export const classNames = joinString.bind(null, ' '); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment