-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefix.ts
42 lines (41 loc) · 1.04 KB
/
prefix.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Prefixes a CSS property based on the current browser.
* @param prop - The unprefixed property name.
* @returns The prefixed property name.
* @example
* ```typescript
* prefix('appearance');
* // 'appearance' on a supported browser, otherwise 'webkitAppearance', 'mozAppearance', 'msAppearance' or 'oAppearance'
* ```
* @alpha
* @category DOM
* @since 0.1.5
*/
const prefix = (
prop: Exclude<
keyof CSSStyleDeclaration,
| "length"
| "parentRule"
| "getPropertyPriority"
| "getPropertyValue"
| "item"
| "removeProperty"
| "setProperty"
| number
| typeof Symbol.iterator
>
) => {
const capitalizedProp: string = prop.charAt(0).toUpperCase() + prop.slice(1);
const prefixes = ["", "webkit", "moz", "ms", "o"];
const i = prefixes.findIndex(
(item: string) =>
// @ts-ignore
typeof document.body.style[item ? item + capitalizedProp : prop] !==
"undefined"
);
if (i !== -1) {
return i === 0 ? prop : prefixes[i] + capitalizedProp;
}
return null;
};
export default prefix;