跳到主要内容

hyphenate style name

一、作用

二、连字符样式名称

/**
* Hyphenates a camelcased CSS property name, for example:
* 将驼峰式 CSS 属性名称用连字符连接,例如:
*
* > hyphenateStyleName('backgroundColor')
* < "background-color"
* > hyphenateStyleName('MozTransition')
* < "-moz-transition"
* > hyphenateStyleName('msTransition')
* < "-ms-transition"
*
* As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix
* is converted to `-ms-`.
*
* 正如 Modernizr 所建议的 (http://modernizr.com/docs/#prefixed),`ms` 前缀
* 会被转换为 `-ms-`。
*/
export default function hyphenateStyleName(name: string): string {
return name
.replace(uppercasePattern, '-$1')
.toLowerCase()
.replace(msPattern, '-ms-');
}

常量

1. 大写模式

const uppercasePattern = /([A-Z])/g;

2. ms 模式

ms 模式是 Internet Explorer ,Trident 引擎的前缀。

const msPattern = /^ms-/;