Skip to content

Commit 7a650cd

Browse files
committed
reduce objectifier.js
1 parent 02abb61 commit 7a650cd

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

objectifier.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ let UNITLESS = {
2424
}
2525

2626
function atRule(node) {
27-
if (typeof node.nodes === 'undefined') {
28-
return true
29-
} else {
30-
return process(node)
31-
}
27+
return node.nodes === undefined ? true : process(node)
3228
}
3329

3430
// From https://github.com/hyperz111/fast-camelcase-css
@@ -62,7 +58,6 @@ function camelcase(property) {
6258
function process(node, options = {}) {
6359
let name
6460
let result = {}
65-
let { stringifyImportant } = options
6661

6762
node.each(child => {
6863
if (child.type === 'atrule') {
@@ -81,13 +76,11 @@ function process(node, options = {}) {
8176
for (let i in body) {
8277
let object = result[child.selector]
8378
if (
84-
stringifyImportant &&
79+
options.stringifyImportant &&
8580
typeof object[i] === 'string' &&
8681
object[i].endsWith('!important')
8782
) {
88-
if (typeof body[i] === 'string' && body[i].endsWith('!important')) {
89-
object[i] = body[i]
90-
}
83+
if (typeof body[i] === 'string' && body[i].endsWith('!important')) object[i] = body[i]
9184
} else {
9285
object[i] = body[i]
9386
}
@@ -96,17 +89,15 @@ function process(node, options = {}) {
9689
result[child.selector] = body
9790
}
9891
} else if (child.type === 'decl') {
99-
if (child.prop[0] === '-' && child.prop[1] === '-') {
92+
if (child.startsWith('--')) {
10093
name = child.prop
10194
} else if (child.parent && child.parent.selector === ':export') {
10295
name = child.prop
10396
} else {
10497
name = camelcase(child.prop)
10598
}
10699
let value = child.value
107-
if (!isNaN(child.value) && UNITLESS[name]) {
108-
value = parseFloat(child.value)
109-
}
100+
if (!isNaN(child.value) && UNITLESS[name]) value = parseFloat(child.value)
110101
if (child.important) value += ' !important'
111102
if (typeof result[name] === 'undefined') {
112103
result[name] = value

0 commit comments

Comments
 (0)