Skip to content

Instantly share code, notes, and snippets.

@malcolm-kee
Last active January 6, 2019 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malcolm-kee/30cd26b80c5f45e443ae44dd5a3b4f01 to your computer and use it in GitHub Desktop.
Save malcolm-kee/30cd26b80c5f45e443ae44dd5a3b4f01 to your computer and use it in GitHub Desktop.
A common utility to generate string
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