@schukai/monster 3.35.1 → 3.35.4

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.35.1",
3
+ "version": "3.35.4",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import { getWindow } from "./util.mjs";
9
+ import { validateString } from "../types/validate.mjs";
9
10
 
10
11
  export { convertToPixels, getDeviceDPI };
11
12
 
@@ -74,7 +75,11 @@ function getDeviceDPI() {
74
75
  */
75
76
 
76
77
  function convertToPixels(value, parentElement = document.documentElement, fontSizeElement = document.documentElement) {
77
- const regex = /^([\d.]+)(.*)$/;
78
+
79
+ validateString(value);
80
+
81
+
82
+ const regex = /^(-?[\d.]+)(.*)$/;
78
83
  const matchResult = value.match(regex);
79
84
 
80
85
  if (!matchResult) {
@@ -82,7 +87,6 @@ function convertToPixels(value, parentElement = document.documentElement, fontSi
82
87
  }
83
88
 
84
89
  const [, num, unit] = matchResult;
85
-
86
90
  const number = parseFloat(num);
87
91
  const dpi = getDeviceDPI();
88
92
 
@@ -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.1");
145
+ monsterVersion = new Version("3.35.4");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -69,7 +69,16 @@ describe('dimension', () => {
69
69
  };
70
70
 
71
71
  expect(errorFn).to.throw(Error, `Invalid value format: ${invalidValue}`);
72
- });
72
+ });
73
+
74
+ it("should handle negative values correctly", () => {
75
+ const negativeValue = "-10px";
76
+ const expectedResult = -10;
77
+
78
+ const result = convertToPixels(negativeValue);
79
+
80
+ expect(result).to.equal(expectedResult);
81
+ });
73
82
 
74
83
  it('should correctly convert em values', () => {
75
84
  const testElement = document.createElement('div');
@@ -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.1")
10
+ monsterVersion = new Version("3.35.4")
11
11
 
12
12
  let m = getMonsterVersion();
13
13