Skip to content

Commit de52666

Browse files
author
Robin Frischmann
committed
embed unitless property
1 parent a333a33 commit de52666

File tree

6 files changed

+79
-9
lines changed

6 files changed

+79
-9
lines changed

modules/camelCaseProperty.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/* @flow */
2+
const dashRegex = /-([a-z])/g
3+
const msRegex = /^Ms/g
4+
25
export default function camelCaseProperty(property: string): string {
3-
return property.replace(/-([a-z])/g, match => match[1].toUpperCase()).replace(/^Ms/g, 'ms')
6+
return property.replace(dashRegex, match => match[1].toUpperCase()).replace(msRegex, 'ms')
47
}

modules/cssifyObject.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export default function cssifyObject(style: Object): string {
55
let css: string = ''
66

77
for (const property in style) {
8-
if (typeof style[property] !== 'string' && typeof style[property] !== 'number') {
8+
const value = style[property]
9+
if (typeof value !== 'string' && typeof value !== 'number') {
910
continue
1011
}
1112

@@ -15,7 +16,7 @@ export default function cssifyObject(style: Object): string {
1516
css += ';'
1617
}
1718

18-
css += cssifyDeclaration(property, style[property])
19+
css += cssifyDeclaration(property, value)
1920
}
2021

2122
return css

modules/isUnitlessProperty.js

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,69 @@
11
/* @flow */
2-
import isUnitlessCSSProperty from 'unitless-css-property'
2+
import hyphenateProperty from './hyphenateProperty'
3+
4+
const unitlessProperties = {
5+
borderImageOutset: true,
6+
borderImageSlice: true,
7+
borderImageWidth: true,
8+
fontWeight: true,
9+
lineHeight: true,
10+
opacity: true,
11+
orphans: true,
12+
tabSize: true,
13+
widows: true,
14+
zIndex: true,
15+
zoom: true,
16+
17+
// SVG-related properties
18+
fillOpacity: true,
19+
floodOpacity: true,
20+
stopOpacity: true,
21+
strokeDasharray: true,
22+
strokeDashoffset: true,
23+
strokeMiterlimit: true,
24+
strokeOpacity: true,
25+
strokeWidth: true
26+
}
27+
28+
const prefixedUnitlessProperties = [
29+
'animationIterationCount',
30+
'boxFlex',
31+
'boxFlexGroup',
32+
'boxOrdinalGroup',
33+
'columnCount',
34+
'flex',
35+
'flexGrow',
36+
'flexPositive',
37+
'flexShrink',
38+
'flexNegative',
39+
'flexOrder',
40+
'gridRow',
41+
'gridColumn',
42+
'order',
43+
'lineClamp'
44+
]
45+
46+
const prefixes = ['Webkit', 'ms', 'Moz', 'O']
47+
48+
function getPrefixedProperty(prefix, property) {
49+
return prefix + property.charAt(0).toUpperCase() + property.slice(1)
50+
}
51+
52+
// add all prefixed properties to the unitless properties
53+
for (let i = 0, len = prefixedUnitlessProperties.length; i < len; ++i) {
54+
unitlessProperties[property] = true
55+
56+
for (let j = 0, jLen = prefixes.length; j < jLen; ++i) {
57+
unitlessProperties[getPrefixedProperty(prefix, property)] = true
58+
}
59+
}
60+
61+
62+
// add all hypenated properties as well
63+
for (const property in unitlessProperties) {
64+
unitlessProperties[hyphenateStyleName(property)] = true
65+
}
366

467
export default function isUnitlessProperty(property: string): boolean {
5-
return isUnitlessCSSProperty(property)
68+
return unitlessProperties.hasOwnProperty(property)
669
}

modules/unprefixProperty.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* @flow */
2+
const prefixRegex = /^(ms|Webkit|Moz|O)/
3+
24
export default function unprefixProperty(property: string): string {
3-
const propertyWithoutPrefix = property.replace(/^(ms|Webkit|Moz|O)/, '')
5+
const propertyWithoutPrefix = property.replace(prefixRegex, '')
46
return propertyWithoutPrefix.charAt(0).toLowerCase() + propertyWithoutPrefix.slice(1)
57
}

modules/unprefixValue.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/* @flow */
2+
const prefixRegex = /(-ms-|-webkit-|-moz-|-o-)/g
3+
24
export default function unprefixValue(value: any): any {
35
if (typeof value === 'string') {
4-
return value.replace(/(-ms-|-webkit-|-moz-|-o-)/g, '')
6+
return value.replace(prefixRegex, '')
57
}
68

79
return value

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"rootDir": "modules"
3131
},
3232
"dependencies": {
33-
"hyphenate-style-name": "^1.0.2",
34-
"unitless-css-property": "^1.0.2"
33+
"hyphenate-style-name": "^1.0.2"
3534
},
3635
"devDependencies": {
3736
"babel-core": "^6.22.1",

0 commit comments

Comments
 (0)