small fixes

This commit is contained in:
ilyes-ced
2024-03-24 18:48:57 +00:00
parent 3072604070
commit 29ec8cbd0a

View File

@@ -64,28 +64,28 @@ function parseStyles(styles: string[]): StylesObject {
const stylesObject: StylesObject = {}; const stylesObject: StylesObject = {};
for (const style of styles) { for (const style of styles) {
const [key, value] = style.trim().split(/\s*:\s*/); const [key, value] = style.trim().split(/\s*:\s*/);
if (key == 'radius') { if (key === 'radius') {
if (validateNumber(value)) { if (validateNumber(value)) {
throw new InvalidStyleError(key, value, 'number'); throw new InvalidStyleError(key, value, 'number');
} }
stylesObject.radius = parseInt(value); stylesObject.radius = parseInt(value);
} else if (key == 'color') { } else if (key === 'color') {
if (validateHexCode(value)) { if (validateHexCode(value)) {
throw new InvalidStyleError(key, value, 'hex code'); throw new InvalidStyleError(key, value, 'hex code');
} }
stylesObject.color = value; stylesObject.color = value;
} else if (key == 'stroke-color') { } else if (key === 'stroke-color') {
if (validateHexCode(value)) { if (validateHexCode(value)) {
throw new InvalidStyleError(key, value, 'hex code'); throw new InvalidStyleError(key, value, 'hex code');
} }
stylesObject.strokeColor = value; stylesObject.strokeColor = value;
} else if (key == 'stroke-width') { } else if (key === 'stroke-width') {
if (validateSizeInPixels(value)) { if (validateSizeInPixels(value)) {
throw new InvalidStyleError(key, value, 'number of pixels (eg. 10px)'); throw new InvalidStyleError(key, value, 'number of pixels (eg. 10px)');
} }
stylesObject.strokeWidth = value; stylesObject.strokeWidth = value;
} else { } else {
throw new Error(`style named ${key} is unacceptable`); throw new Error(`style named ${key} is not supported.`);
} }
} }
return stylesObject; return stylesObject;