fela-plugin-unit
Advanced tools
Comparing version 11.4.0 to 11.5.0-rc.0
@@ -6,7 +6,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function addUnitIfNeeded(property, value, propertyUnit) { | ||
function addUnitIfNeeded(value, propertyUnit) { | ||
var valueType = typeof value === 'undefined' ? 'undefined' : _typeof(value); | ||
/* eslint-disable eqeqeq */ | ||
if ((valueType === 'number' || valueType === 'string' && value == parseFloat(value)) && value != 0) { | ||
value += propertyUnit; | ||
return value + propertyUnit; | ||
} | ||
@@ -18,21 +18,19 @@ /* eslint-enable */ | ||
function addUnit(style, defaultUnit, propertyMap, isUnitlessProperty) { | ||
var _loop = function _loop(property) { | ||
for (var property in style) { | ||
if (!isUnitlessProperty(property)) { | ||
var cssValue = style[property]; | ||
var propertyUnit = propertyMap[property] || defaultUnit; | ||
(function () { | ||
var cssValue = style[property]; | ||
var propertyUnit = propertyMap[property] || defaultUnit; | ||
if (isPlainObject(cssValue)) { | ||
style[property] = addUnit(cssValue, defaultUnit, propertyMap, isUnitlessProperty); | ||
} else if (Array.isArray(cssValue)) { | ||
style[property] = cssValue.map(function (val) { | ||
return addUnitIfNeeded(property, val, propertyUnit); | ||
}); | ||
} else { | ||
style[property] = addUnitIfNeeded(property, cssValue, propertyUnit); | ||
} | ||
if (isPlainObject(cssValue)) { | ||
style[property] = addUnit(cssValue, defaultUnit, propertyMap, isUnitlessProperty); | ||
} else if (Array.isArray(cssValue)) { | ||
style[property] = cssValue.map(function (val) { | ||
return addUnitIfNeeded(val, propertyUnit); | ||
}); | ||
} else { | ||
style[property] = addUnitIfNeeded(cssValue, propertyUnit); | ||
} | ||
})(); | ||
} | ||
}; | ||
for (var property in style) { | ||
_loop(property); | ||
} | ||
@@ -43,2 +41,26 @@ | ||
function createOptimized(defaultUnit, propertyMap, isUnitlessProperty) { | ||
return function (props) { | ||
if (!isUnitlessProperty(props.property)) { | ||
var valueType = _typeof(props.value); | ||
/* eslint-disable eqeqeq */ | ||
if ((valueType === 'number' || valueType === 'string' && props.value == parseFloat(props.value)) && props.value != 0) { | ||
var _unit = propertyMap[props.property] || defaultUnit; | ||
props.value += _unit; | ||
} | ||
// handle arrays | ||
if (Array.isArray(props.value)) { | ||
var propertyUnit = propertyMap[props.property] || defaultUnit; | ||
props.value = props.value.map(function (value) { | ||
return addUnitIfNeeded(value, propertyUnit); | ||
}); | ||
} | ||
} | ||
return props; | ||
}; | ||
} | ||
export default function unit() { | ||
@@ -49,5 +71,9 @@ var defaultUnit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'px'; | ||
return function (style) { | ||
var plugin = function plugin(style) { | ||
return addUnit(style, defaultUnit, propertyMap, isUnitlessProperty); | ||
}; | ||
plugin.optimized = createOptimized(defaultUnit, propertyMap, isUnitlessProperty); | ||
return plugin; | ||
} |
@@ -21,7 +21,7 @@ 'use strict'; | ||
function addUnitIfNeeded(property, value, propertyUnit) { | ||
function addUnitIfNeeded(value, propertyUnit) { | ||
var valueType = typeof value === 'undefined' ? 'undefined' : _typeof(value); | ||
/* eslint-disable eqeqeq */ | ||
if ((valueType === 'number' || valueType === 'string' && value == parseFloat(value)) && value != 0) { | ||
value += propertyUnit; | ||
return value + propertyUnit; | ||
} | ||
@@ -33,21 +33,19 @@ /* eslint-enable */ | ||
function addUnit(style, defaultUnit, propertyMap, isUnitlessProperty) { | ||
var _loop = function _loop(property) { | ||
for (var property in style) { | ||
if (!isUnitlessProperty(property)) { | ||
var cssValue = style[property]; | ||
var propertyUnit = propertyMap[property] || defaultUnit; | ||
(function () { | ||
var cssValue = style[property]; | ||
var propertyUnit = propertyMap[property] || defaultUnit; | ||
if ((0, _isobject2.default)(cssValue)) { | ||
style[property] = addUnit(cssValue, defaultUnit, propertyMap, isUnitlessProperty); | ||
} else if (Array.isArray(cssValue)) { | ||
style[property] = cssValue.map(function (val) { | ||
return addUnitIfNeeded(property, val, propertyUnit); | ||
}); | ||
} else { | ||
style[property] = addUnitIfNeeded(property, cssValue, propertyUnit); | ||
} | ||
if ((0, _isobject2.default)(cssValue)) { | ||
style[property] = addUnit(cssValue, defaultUnit, propertyMap, isUnitlessProperty); | ||
} else if (Array.isArray(cssValue)) { | ||
style[property] = cssValue.map(function (val) { | ||
return addUnitIfNeeded(val, propertyUnit); | ||
}); | ||
} else { | ||
style[property] = addUnitIfNeeded(cssValue, propertyUnit); | ||
} | ||
})(); | ||
} | ||
}; | ||
for (var property in style) { | ||
_loop(property); | ||
} | ||
@@ -58,2 +56,26 @@ | ||
function createOptimized(defaultUnit, propertyMap, isUnitlessProperty) { | ||
return function (props) { | ||
if (!isUnitlessProperty(props.property)) { | ||
var valueType = _typeof(props.value); | ||
/* eslint-disable eqeqeq */ | ||
if ((valueType === 'number' || valueType === 'string' && props.value == parseFloat(props.value)) && props.value != 0) { | ||
var _unit = propertyMap[props.property] || defaultUnit; | ||
props.value += _unit; | ||
} | ||
// handle arrays | ||
if (Array.isArray(props.value)) { | ||
var propertyUnit = propertyMap[props.property] || defaultUnit; | ||
props.value = props.value.map(function (value) { | ||
return addUnitIfNeeded(value, propertyUnit); | ||
}); | ||
} | ||
} | ||
return props; | ||
}; | ||
} | ||
function unit() { | ||
@@ -64,5 +86,9 @@ var defaultUnit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'px'; | ||
return function (style) { | ||
var plugin = function plugin(style) { | ||
return addUnit(style, defaultUnit, propertyMap, isUnitlessProperty); | ||
}; | ||
plugin.optimized = createOptimized(defaultUnit, propertyMap, isUnitlessProperty); | ||
return plugin; | ||
} |
{ | ||
"name": "fela-plugin-unit", | ||
"version": "11.4.0", | ||
"version": "11.5.0-rc.0", | ||
"description": "Fela plugin to automatically add units if required", | ||
@@ -27,3 +27,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "94e23ad2fda221aea52ccb939d90f81eb400b5fb" | ||
"gitHead": "6d457d39e69e1471bddaea8591c50745f95070d9" | ||
} |
@@ -80,3 +80,3 @@ # fela-plugin-unit | ||
Fela is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br> | ||
Documentation is licensed under [Creative Common License](http://creativecommons.org/licenses/by/4.0/).<br> | ||
Documentation is licensed under [Creative Commons License](http://creativecommons.org/licenses/by/4.0/).<br> | ||
Created with ♥ by [@robinweser](http://weser.io) and all the great contributors. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9931
130
2