Since you don't support objects as in e.g `classnames({ isActive })`, I guess you might improve performance a little by using `typeof arg === 'string'` instead of the more expensive `Array.isArray(arg)` call.
I tested many of case and it seems property check is cheaper than typeof check.
So I confirmed all of method of Array.
And it seems `pop` is shortest method name.
Now I check `pop` instead of isArray.
If you have any other idea, please notice me!
Thank you again :)
Yes you're right.
It seems Array.isArray compare with Array.prototype and that work is expensive!
Let me try several case and I'll try to find what is the best code.
Thank you :)
Would be better to use the DOM classList[1] API, which is already available on all major browsers for a couple generations now (limited support in IE).
I will say, if you're using React, this is a bit lighter than the classnames[2] module, which would be my own preference. However, knowledge of Array methods (map, reduce, etc) can accomplish the same without an external dependency, or the runtime wrapping likely to happen.
[1] https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
[2] https://www.npmjs.com/package/classnames
Note: not the one who downvoted.
I think this module's role is different with classList.
As you said, classList is a API of DOM.
But this module just generates a string.
So... I think this module is useful for framework or library user(React, Angular, Vue)
In VanillaJS, absolutely classList is good :)
And no worries, I'm not care about the downvote.
All of positive or negative opinions always welcome!
I'm sorry but I have absolutely no idea what this does or why I'd want to use it. Is it for css classnames or JS class names. Examples just show inputs and no outputs.