css-in-js-utils
Advanced tools
Comparing version 3.0.0 to 3.0.1
# Changelog | ||
### 3.0.1 | ||
* added new unitless properties | ||
### 3.0.0 | ||
@@ -4,0 +7,0 @@ * `assignStyle` now correctly merges array values without duplicates where the last occurence always wins in order |
@@ -69,3 +69,2 @@ 'use strict'; | ||
}); | ||
expect(ob1).toEqual(newOb); | ||
@@ -81,24 +80,12 @@ | ||
it('should not recursively call assignStyle for null values', function () { | ||
var ob1 = { fontSize: 10 }; | ||
var ob2 = { margin: null }; | ||
var newOb = (0, _assignStyle2.default)({}, ob1, ob2); | ||
expect(newOb).toEqual({ | ||
fontSize: 10, | ||
margin: null | ||
}); | ||
}); | ||
it('should merge array values (array-single)', function () { | ||
it('should overwrite previous values when both values are array', function () { | ||
var ob1 = { fontSize: ['10px', '10rem'] }; | ||
var ob2 = { fontSize: 20 }; | ||
var ob2 = { fontSize: ['10px', '20vw'] }; | ||
var newOb = (0, _assignStyle2.default)({}, ob1, ob2); | ||
expect(newOb).toEqual({ fontSize: ['10px', '10rem', 20] }); | ||
expect(newOb).toEqual({ fontSize: ['10px', '20vw'] }); | ||
}); | ||
it('should merge array values (single-array)', function () { | ||
it('should overwrite previous values when only the last value is an array', function () { | ||
var ob1 = { fontSize: 10 }; | ||
@@ -109,41 +96,14 @@ var ob2 = { fontSize: ['10px', '20vw'] }; | ||
expect(newOb).toEqual({ fontSize: [10, '10px', '20vw'] }); | ||
expect(newOb).toEqual({ fontSize: ['10px', '20vw'] }); | ||
}); | ||
it('should merge array values (array-array)', function () { | ||
var ob1 = { fontSize: ['20pt', 10] }; | ||
var ob2 = { fontSize: ['10px', '20vw'] }; | ||
var newOb = (0, _assignStyle2.default)({}, ob1, ob2); | ||
expect(newOb).toEqual({ fontSize: ['20pt', 10, '10px', '20vw'] }); | ||
}); | ||
it('should merge array values without duplicates (array-single)', function () { | ||
it('should overwrite previous values when only the first value is an array', function () { | ||
var ob1 = { fontSize: ['10px', '10rem'] }; | ||
var ob2 = { fontSize: '10px' }; | ||
var ob2 = { fontSize: 20 }; | ||
var newOb = (0, _assignStyle2.default)({}, ob1, ob2); | ||
expect(newOb).toEqual({ fontSize: ['10rem', '10px'] }); | ||
expect(newOb).toEqual({ fontSize: 20 }); | ||
}); | ||
it('should merge array values without duplicates (array-array)', function () { | ||
var ob1 = { fontSize: ['20px', '10rem', '10px'] }; | ||
var ob2 = { fontSize: ['10px', 5, '10rem'] }; | ||
var newOb = (0, _assignStyle2.default)({}, ob1, ob2); | ||
expect(newOb).toEqual({ fontSize: ['20px', '10px', 5, '10rem'] }); | ||
}); | ||
it('should merge array values without duplicates (single-array)', function () { | ||
var ob1 = { fontSize: '10px' }; | ||
var ob2 = { fontSize: ['10rem', '10px'] }; | ||
var newOb = (0, _assignStyle2.default)({}, ob1, ob2); | ||
expect(newOb).toEqual({ fontSize: ['10rem', '10px'] }); | ||
}); | ||
it('should not recursively call assignStyle for null values', function () { | ||
@@ -150,0 +110,0 @@ var ob1 = { fontSize: 10 }; |
@@ -6,15 +6,10 @@ 'use strict'; | ||
}); | ||
exports.default = assignStyle; | ||
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; }; | ||
var _isobject = require('isobject'); | ||
exports.default = assignStyle; | ||
var _isobject2 = _interopRequireDefault(_isobject); | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function filterUniqueArray(arr) { | ||
return arr.filter(function (val, index) { | ||
return arr.lastIndexOf(val) === index; | ||
}); | ||
} | ||
function assignStyle(base) { | ||
@@ -32,17 +27,5 @@ for (var _len = arguments.length, extendingStyles = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
if (baseValue && value) { | ||
if (Array.isArray(baseValue)) { | ||
base[property] = filterUniqueArray(baseValue.concat(value)); | ||
continue; | ||
} | ||
if (Array.isArray(value)) { | ||
base[property] = filterUniqueArray([baseValue].concat(_toConsumableArray(value))); | ||
continue; | ||
} | ||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { | ||
base[property] = assignStyle({}, baseValue, value); | ||
continue; | ||
} | ||
if ((0, _isobject2.default)(value)) { | ||
base[property] = assignStyle({}, baseValue, value); | ||
continue; | ||
} | ||
@@ -49,0 +32,0 @@ |
{ | ||
"name": "css-in-js-utils", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Useful utility functions for CSS in JS solutions", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
31080
28
487