Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

cssstyle

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cssstyle - npm Package Compare versions

Comparing version 0.2.14 to 0.2.15

8

lib/CSSStyleDeclaration.js

@@ -77,8 +77,10 @@ /*********************************************************************

}
var prevValue = this._values[name];
delete this._values[name];
var index = Array.prototype.indexOf.call(this, name);
if (index < 0) {
return "";
return prevValue;
}
var prevValue = this._values[name];
delete this._values[name];

@@ -85,0 +87,0 @@ // That's what WebKit and Opera do

@@ -465,5 +465,9 @@ /*********************************************************************

exports.shorthandParser = function parse(v, shorthand_for) {
var obj = {};
var type = exports.valueType(v);
if (type === exports.TYPES.NULL_OR_EMPTY_STR) {
return v;
Object.keys(shorthand_for).forEach(function (property) {
obj[property] = v;
});
return obj;
}

@@ -484,3 +488,2 @@

var valid = true;
var obj = {};
parts.forEach(function (part) {

@@ -508,2 +511,3 @@ var part_valid = false;

}
//console.log('shorthandSetter for:', property, 'obj:', obj);
Object.keys(obj).forEach(function (subprop) {

@@ -525,3 +529,11 @@ // in case subprop is an implicit property, this will clear

}, this);
this.setProperty(property, v);
// in case the value is something like 'none' that removes all values,
// check that the generated one is not empty, first remove the property
// if it already exists, then call the shorthandGetter, if it's an empty
// string, don't set the property
this.removeProperty(property);
var calculated = exports.shorthandGetter(property, shorthand_for).call(this);
if (calculated !== '') {
this.setProperty(property, v);
}
};

@@ -561,6 +573,8 @@ };

}
if (v.toLowerCase() === 'inherit') {
return this.setProperty(property_before + property_after, v);
var parts;
if (v.toLowerCase() === 'inherit' || v === '') {
parts = [v];
} else {
parts = getParts(v);
}
var parts = getParts(v);
if (parts.length < 1 || parts.length > 4) {

@@ -567,0 +581,0 @@ return undefined;

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

var shorthandGetter = require('../parsers').shorthandGetter;
var implicitSetter = require('../parsers').implicitSetter;

@@ -14,11 +15,32 @@ var shorthand_for = {

module.exports.isValid = function isValid(v) {
var isValid = function isValid(v) {
return shorthandParser(v, shorthand_for) !== undefined;
};
module.exports.isValid = isValid;
var parser = function (v) {
if (v.toLowerCase() === 'none') {
v = '';
}
if (isValid(v)) {
return v;
}
return undefined;
};
var myShorthandSetter = shorthandSetter('border', shorthand_for);
var myShorthandGetter = shorthandGetter('border', shorthand_for);
var myImplicitSetter = implicitSetter('border', '', isValid, parser);
module.exports.definition = {
set: shorthandSetter('border', shorthand_for),
get: shorthandGetter('border', shorthand_for),
set: function (v) {
if (v.toLowerCase() === 'none') {
v = '';
}
myImplicitSetter.call(this, v);
myShorthandSetter.call(this, v);
},
get: myShorthandGetter,
enumerable: true,
configurable: true
};
'use strict';
var shorthandSetter = require('../parsers').shorthandSetter;
var shorthandGetter = require('../parsers').shorthandGetter;
var shorthandParser = require('../parsers').shorthandParser;
var shorthand_for = {
borderBottomWidth: require('./borderBottomWidth'),
borderBottomStyle: require('./borderBottomStyle'),
borderBottomColor: require('./borderBottomColor')
'border-bottom-width': require('./borderBottomWidth'),
'border-bottom-style': require('./borderBottomStyle'),
'border-bottom-color': require('./borderBottomColor')
};
var isValid = module.exports.isValid = function isValid(v) {
var isValid = function isValid(v) {
return shorthandParser(v, shorthand_for) !== undefined;
};
module.exports.isValid = isValid;
module.exports.definition = {
set: function (v) {
var obj = shorthandParser(v, shorthand_for);
if (obj === undefined) {
return;
}
Object.keys(obj).forEach(function (property) {
this._values[property] = obj[property];
}, this);
this.setProperty('border-bottom', v);
},
get: function () {
return this.getPropertyValue('border-bottom');
},
set: shorthandSetter('border-bottom', shorthand_for),
get: shorthandGetter('border-bottom', shorthand_for),
enumerable: true,
configurable: true
};
'use strict';
var isValid = module.exports.isValid = require('./borderStyle').isValid;
var isValid = require('./borderStyle').isValid;
module.exports.isValid = isValid;

@@ -8,2 +9,6 @@ module.exports.definition = {

if (isValid(v)) {
if (v.toLowerCase() === 'none') {
v = '';
this.removeProperty('border-bottom-width');
}
this.setProperty('border-bottom-style', v);

@@ -10,0 +15,0 @@ }

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

}
return (v.toLowerCase() === 'transparent' || parsers.valueType(v) === parsers.TYPES.COLOR);
return (v === '' || v.toLowerCase() === 'transparent' || parsers.valueType(v) === parsers.TYPES.COLOR);
};

@@ -13,0 +13,0 @@ var isValid = module.exports.isValid;

'use strict';
var shorthandSetter = require('../parsers').shorthandSetter;
var shorthandGetter = require('../parsers').shorthandGetter;
var shorthandParser = require('../parsers').shorthandParser;
var shorthand_for = {
borderLeftWidth: require('./borderLeftWidth'),
borderLeftStyle: require('./borderLeftStyle'),
borderLeftColor: require('./borderLeftColor')
'border-left-width': require('./borderLeftWidth'),
'border-left-style': require('./borderLeftStyle'),
'border-left-color': require('./borderLeftColor')
};
var isValid = module.exports.isValid = function isValid(v) {
var isValid = function isValid(v) {
return shorthandParser(v, shorthand_for) !== undefined;
};
module.exports.isValid = isValid;
module.exports.definition = {
set: function (v) {
var obj = shorthandParser(v, shorthand_for);
if (obj === undefined) {
return;
}
Object.keys(obj).forEach(function (property) {
this._values[property] = obj[property];
}, this);
this.setProperty('border-left', v);
},
get: function () {
return this.getPropertyValue('border-left');
},
set: shorthandSetter('border-left', shorthand_for),
get: shorthandGetter('border-left', shorthand_for),
enumerable: true,
configurable: true
};
'use strict';
var isValid = module.exports.isValid = require('./borderStyle').isValid;
var isValid = require('./borderStyle').isValid;
module.exports.isValid = isValid;

@@ -8,2 +9,6 @@ module.exports.definition = {

if (isValid(v)) {
if (v.toLowerCase() === 'none') {
v = '';
this.removeProperty('border-left-width');
}
this.setProperty('border-left-style', v);

@@ -10,0 +15,0 @@ }

'use strict';
var shorthandSetter = require('../parsers').shorthandSetter;
var shorthandGetter = require('../parsers').shorthandGetter;
var shorthandParser = require('../parsers').shorthandParser;
var shorthand_for = {
borderRightWidth: require('./borderRightWidth'),
borderRightStyle: require('./borderRightStyle'),
borderRightColor: require('./borderRightColor')
'border-right-width': require('./borderRightWidth'),
'border-right-style': require('./borderRightStyle'),
'border-right-color': require('./borderRightColor')
};
var isValid = module.exports.isValid = function isValid(v) {
var isValid = function isValid(v) {
return shorthandParser(v, shorthand_for) !== undefined;
};
module.exports.isValid = isValid;
module.exports.definition = {
set: function (v) {
var obj = shorthandParser(v, shorthand_for);
if (obj === undefined) {
return;
}
Object.keys(obj).forEach(function (property) {
this._values[property] = obj[property];
}, this);
this.setProperty('border-right', v);
},
get: function () {
return this.getPropertyValue('border-right');
},
set: shorthandSetter('border-right', shorthand_for),
get: shorthandGetter('border-right', shorthand_for),
enumerable: true,
configurable: true
};
'use strict';
var isValid = module.exports.isValid = require('./borderStyle').isValid;
var isValid = require('./borderStyle').isValid;
module.exports.isValid = isValid;

@@ -8,2 +9,6 @@ module.exports.definition = {

if (isValid(v)) {
if (v.toLowerCase() === 'none') {
v = '';
this.removeProperty('border-right-width');
}
this.setProperty('border-right-style', v);

@@ -10,0 +15,0 @@ }

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

module.exports.isValid = function parse(v) {
return typeof v === 'string' && styles.indexOf(v) !== -1;
return typeof v === 'string' && (v === '' || styles.indexOf(v) !== -1);
};

@@ -12,0 +12,0 @@ var isValid = module.exports.isValid;

'use strict';
var shorthandSetter = require('../parsers').shorthandSetter;
var shorthandGetter = require('../parsers').shorthandGetter;
var shorthandParser = require('../parsers').shorthandParser;
var shorthand_for = {
borderTopWidth: require('./borderTopWidth'),
borderTopStyle: require('./borderTopStyle'),
borderTopColor: require('./borderTopColor')
'border-top-width': require('./borderTopWidth'),
'border-top-style': require('./borderTopStyle'),
'border-top-color': require('./borderTopColor')
};
var isValid = module.exports.isValid = function isValid(v) {
module.exports.isValid = function (v) {
return shorthandParser(v, shorthand_for) !== undefined;

@@ -16,17 +18,6 @@ };

module.exports.definition = {
set: function (v) {
var obj = shorthandParser(v, shorthand_for);
if (obj === undefined) {
return;
}
Object.keys(obj).forEach(function (property) {
this._values[property] = obj[property];
}, this);
this.setProperty('border-top', v);
},
get: function () {
return this.getPropertyValue('border-top');
},
set: shorthandSetter('border-top', shorthand_for),
get: shorthandGetter('border-top', shorthand_for),
enumerable: true,
configurable: true
};
'use strict';
var isValid = module.exports.isValid = require('./borderStyle').isValid;
var isValid = require('./borderStyle').isValid;
module.exports.isValid = isValid;

@@ -8,2 +9,6 @@ module.exports.definition = {

if (isValid(v)) {
if (v.toLowerCase() === 'none') {
v = '';
this.removeProperty('border-top-width');
}
this.setProperty('border-top-style', v);

@@ -10,0 +15,0 @@ }

'use strict';
var isValid = module.exports.isValid = require('./borderWidth').isValid;
var isValid = require('./borderWidth').isValid;
module.exports.isValid = isValid;

@@ -5,0 +6,0 @@ module.exports.definition = {

@@ -18,2 +18,5 @@ 'use strict';

}
if (v === '') {
return true;
}
v = v.toLowerCase();

@@ -20,0 +23,0 @@ if (widths.indexOf(v) === -1) {

@@ -5,3 +5,3 @@ {

"keywords": ["CSS", "CSSStyleDeclaration", "StyleSheet"],
"version": "0.2.14",
"version": "0.2.15",
"homepage": "https://github.com/chad3814/CSSStyleDeclaration",

@@ -8,0 +8,0 @@ "maintainers": [{

@@ -197,3 +197,56 @@ "use strict";

test.done();
},
'Setting shorthand properties to an empty string should clear all dependent properties': function (test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.borderWidth = '1px';
test.ok('border-width: 1px;' === style.cssText, 'cssText is not "border-width: 1px;": ' + style.cssText);
style.border = '';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
test.done();
},
'Setting implicit properties to an empty string should clear all dependent properties': function (test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.borderTopWidth = '1px';
test.ok('border-top-width: 1px;' === style.cssText, 'cssText is not "border-top-width: 1px;": ' + style.cssText);
style.borderWidth = '';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
test.done();
},
'Setting a shorthand property, whose shorthands are implicit properties, to an empty string shoudl clear all dependent properties': function (test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(4);
style.borderTopWidth = '1px';
test.ok('border-top-width: 1px;' === style.cssText, 'cssText is not "border-top-width: 1px;": ' + style.cssText);
style.border = '';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
style.borderTop = '1px solid black';
test.ok('border-top: 1px solid black;' === style.cssText, 'cssText is not "border-top: 1px solid black;": ' + style.cssText);
style.border = '';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
test.done();
},
'Setting border values to "none" should clear dependent values': function (test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(8);
style.borderTopWidth = '1px';
test.ok('border-top-width: 1px;' === style.cssText, 'cssText is not "border-top-width: 1px;": ' + style.cssText);
style.border = 'none';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
style.borderTopWidth = '1px';
test.ok('border-top-width: 1px;' === style.cssText, 'cssText is not "border-top-width: 1px;": ' + style.cssText);
style.borderTopStyle = 'none';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
style.borderTopWidth = '1px';
test.ok('border-top-width: 1px;' === style.cssText, 'cssText is not "border-top-width: 1px;": ' + style.cssText);
style.borderTop = 'none';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
style.borderTopWidth = '1px';
style.borderLeftWidth = '1px';
test.ok('border-top-width: 1px; border-left-width: 1px;' === style.cssText, 'cssText is not "border-top-width: 1px; border-left-width: 1px;": ' + style.cssText);
style.borderTop = 'none';
test.ok('border-left-width: 1px;' === style.cssText, 'cssText is not "border-left-width: 1px;": ' + style.cssText);
test.done();
}
};
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc