@schukai/monster 3.35.0 → 3.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.35.0",
3
+ "version": "3.35.1",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -70,11 +70,19 @@ function getDeviceDPI() {
70
70
  * @copyright schukai GmbH
71
71
  * @throws {Error} Unsupported unit
72
72
  * @memberOf Monster.DOM
73
+ * @throws {Error} Invalid value format
73
74
  */
74
75
 
75
76
  function convertToPixels(value, parentElement = document.documentElement, fontSizeElement = document.documentElement) {
76
77
  const regex = /^([\d.]+)(.*)$/;
77
- const [, num, unit] = value.match(regex);
78
+ const matchResult = value.match(regex);
79
+
80
+ if (!matchResult) {
81
+ throw new Error(`Invalid value format: ${value}`);
82
+ }
83
+
84
+ const [, num, unit] = matchResult;
85
+
78
86
  const number = parseFloat(num);
79
87
  const dpi = getDeviceDPI();
80
88
 
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.35.0");
145
+ monsterVersion = new Version("3.35.1");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -61,6 +61,16 @@ describe('dimension', () => {
61
61
  expect(result).to.equal(100);
62
62
  });
63
63
 
64
+ it("should throw an error when the input value has an invalid format", () => {
65
+ const invalidValue = "invalid_value";
66
+
67
+ const errorFn = () => {
68
+ convertToPixels(invalidValue);
69
+ };
70
+
71
+ expect(errorFn).to.throw(Error, `Invalid value format: ${invalidValue}`);
72
+ });
73
+
64
74
  it('should correctly convert em values', () => {
65
75
  const testElement = document.createElement('div');
66
76
  testElement.style.fontSize = '16px';
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.35.0")
10
+ monsterVersion = new Version("3.35.1")
11
11
 
12
12
  let m = getMonsterVersion();
13
13