Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Optimize kebabify By passing a function to replace, we can do the uppercase to lowercase conversion at the same time. This is pretty much the exact example that MDN gives, with the only difference being that we aren't checking against the offset here to avoid adding "-" at the beginning of the string: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Using_an_inline_function_that_modifies_the_matched_characters In my profiling, this seems to make kebabify 50% faster (50ms -> 25ms). * Collapse kebabify into kebabifyStyleName Now that we've simplified kebabify, there really isn't much value in having it be in its own function like this. Moving it into kebabifyStyleName to simplify and optimize. * Add tests for kebabifyStyleName My refactoring caused test coverage to drop, so I decided to add some unit tests here. They pass before and after my refactoring. * Replace ms- to -ms- regex with logic This avoids an often-unnecessary regex run, which makes this function run a little faster. I first went with str.slice, but benchmarking showed that to be 18% slower than bracket access.
- Loading branch information