Skip to content

Commit

Permalink
Replace ms- to -ms- regex with logic
Browse files Browse the repository at this point in the history
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
lencioni committed Mar 6, 2017
1 parent b353ca4 commit f907752
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export const flattenDeep = (list /* : any[] */) /* : any[] */ =>

const UPPERCASE_RE = /([A-Z])/g;
const UPPERCASE_RE_TO_KEBAB = (match /* : string */) /* : string */ => `-${match.toLowerCase()}`;
const MS_RE = /^ms-/;

export const kebabifyStyleName = (string /* : string */) /* : string */ => (
string
.replace(UPPERCASE_RE, UPPERCASE_RE_TO_KEBAB)
.replace(MS_RE, '-ms-')
);
export const kebabifyStyleName = (string /* : string */) /* : string */ => {
const result = string.replace(UPPERCASE_RE, UPPERCASE_RE_TO_KEBAB);
if (result[0] === 'm' && result[1] === 's' && result[2] === '-') {
return `-${result}`;
}
return result;
};

const isNotObject = (
x/* : ObjectMap | any */
Expand Down

0 comments on commit f907752

Please sign in to comment.