Socket
Socket
Sign inDemoInstall

css-in-js-utils

Package Overview
Dependencies
1
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 3.0.2

56

lib/__tests__/assignStyle-test.js

@@ -69,2 +69,3 @@ 'use strict';

});
expect(ob1).toEqual(newOb);

@@ -80,12 +81,24 @@

it('should overwrite previous values when both values are array', function () {
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 () {
var ob1 = { fontSize: ['10px', '10rem'] };
var ob2 = { fontSize: ['10px', '20vw'] };
var ob2 = { fontSize: 20 };
var newOb = (0, _assignStyle2.default)({}, ob1, ob2);
expect(newOb).toEqual({ fontSize: ['10px', '20vw'] });
expect(newOb).toEqual({ fontSize: ['10px', '10rem', 20] });
});
it('should overwrite previous values when only the last value is an array', function () {
it('should merge array values (single-array)', function () {
var ob1 = { fontSize: 10 };

@@ -96,14 +109,41 @@ var ob2 = { fontSize: ['10px', '20vw'] };

expect(newOb).toEqual({ fontSize: ['10px', '20vw'] });
expect(newOb).toEqual({ fontSize: [10, '10px', '20vw'] });
});
it('should overwrite previous values when only the first value is an array', function () {
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 () {
var ob1 = { fontSize: ['10px', '10rem'] };
var ob2 = { fontSize: 20 };
var ob2 = { fontSize: '10px' };
var newOb = (0, _assignStyle2.default)({}, ob1, ob2);
expect(newOb).toEqual({ fontSize: 20 });
expect(newOb).toEqual({ fontSize: ['10rem', '10px'] });
});
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 () {

@@ -110,0 +150,0 @@ var ob1 = { fontSize: 10 };

31

lib/assignStyle.js

@@ -6,10 +6,15 @@ 'use strict';

});
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; };
exports.default = assignStyle;
var _isobject = require('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); } }
var _isobject2 = _interopRequireDefault(_isobject);
function filterUniqueArray(arr) {
return arr.filter(function (val, index) {
return arr.lastIndexOf(val) === index;
});
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function assignStyle(base) {

@@ -27,5 +32,17 @@ for (var _len = arguments.length, extendingStyles = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {

if ((0, _isobject2.default)(value)) {
base[property] = assignStyle({}, baseValue, value);
continue;
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;
}
}

@@ -32,0 +49,0 @@

@@ -38,3 +38,3 @@ 'use strict';

var prefixedUnitlessProperties = ['animationIterationCount', 'boxFlex', 'boxFlexGroup', 'boxOrdinalGroup', 'columnCount', 'flex', 'flexGrow', 'flexPositive', 'flexShrink', 'flexNegative', 'flexOrder', 'gridRow', 'gridColumn', 'order', 'lineClamp'];
var prefixedUnitlessProperties = ['animationIterationCount', 'boxFlex', 'boxFlexGroup', 'boxOrdinalGroup', 'columnCount', 'flex', 'flexGrow', 'flexPositive', 'flexShrink', 'flexNegative', 'flexOrder', 'gridColumn', 'gridColumnEnd', 'gridColumnStart', 'gridRow', 'gridRowEnd', 'gridRowStart', 'lineClamp', 'order'];

@@ -41,0 +41,0 @@ var prefixes = ['Webkit', 'ms', 'Moz', 'O'];

{
"name": "css-in-js-utils",
"version": "3.0.1",
"version": "3.0.2",
"description": "Useful utility functions for CSS in JS solutions",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc