@uxf/core 11.85.0 → 11.88.0

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.
Files changed (38) hide show
  1. package/README.md +139 -0
  2. package/package.json +1 -1
  3. package/types/index.d.ts +1 -0
  4. package/utils/filter-aria-and-data-attrs.d.ts +3 -0
  5. package/utils/filter-aria-and-data-attrs.js +6 -0
  6. package/utils/filter-aria-and-data-attrs.test.d.ts +1 -0
  7. package/utils/filter-aria-and-data-attrs.test.js +95 -0
  8. package/utils/filter-nullish-object-values.d.ts +3 -0
  9. package/utils/filter-nullish-object-values.js +7 -0
  10. package/utils/filter-nullish-object-values.test.d.ts +1 -0
  11. package/utils/filter-nullish-object-values.test.js +18 -0
  12. package/utils/filter-nullish.d.ts +2 -1
  13. package/utils/is-even.d.ts +1 -0
  14. package/utils/is-even.js +6 -0
  15. package/utils/is-even.test.d.ts +1 -0
  16. package/utils/is-even.test.js +7 -0
  17. package/utils/is-odd.d.ts +1 -0
  18. package/utils/is-odd.js +7 -0
  19. package/utils/is-odd.test.d.ts +1 -0
  20. package/utils/is-odd.test.js +7 -0
  21. package/utils/non-empty-array-or-null.d.ts +2 -0
  22. package/utils/non-empty-array-or-null.js +8 -0
  23. package/utils/non-empty-array-or-null.test.d.ts +1 -0
  24. package/utils/non-empty-array-or-null.test.js +14 -0
  25. package/utils/non-empty-string-or-null.d.ts +2 -0
  26. package/utils/non-empty-string-or-null.js +6 -0
  27. package/utils/non-empty-string-or-null.test.d.ts +1 -0
  28. package/utils/non-empty-string-or-null.test.js +11 -0
  29. package/utils/nullish-to-empty-string.d.ts +2 -0
  30. package/utils/nullish-to-empty-string.js +6 -0
  31. package/utils/nullish-to-empty-string.test.d.ts +1 -0
  32. package/utils/nullish-to-empty-string.test.js +10 -0
  33. package/utils/number-or-null.d.ts +2 -0
  34. package/utils/number-or-null.js +7 -0
  35. package/utils/number-or-null.test.d.ts +1 -0
  36. package/utils/number-or-null.test.js +18 -0
  37. package/utils/resizer.js +5 -1
  38. package/utils/resizer.test.js +2 -2
package/README.md CHANGED
@@ -285,6 +285,56 @@ import { filterNullish } from "@uxf/core/utils/filter-nullish";
285
285
  filterNullish([0, "text", null, undefined, [], {}]); /* returns [0, "text", [], {}] */
286
286
  ```
287
287
 
288
+ ## filterNullishObjectValues
289
+
290
+ Filters out all properties with `null` or `undefined` values from an object, returning a new object with only non-nullish values.
291
+
292
+ ```tsx
293
+ import { filterNullishObjectValues } from "@uxf/core/utils/filter-nullish-object-values";
294
+
295
+ filterNullishObjectValues({ a: 1, b: null, c: "test", d: undefined });
296
+ /* returns { a: 1, c: "test" } */
297
+
298
+ filterNullishObjectValues({ a: 0, b: "", c: false });
299
+ /* returns { a: 0, b: "", c: false } - keeps falsy values that are not nullish */
300
+ ```
301
+
302
+ ## filterAriaAndDataAttrs
303
+
304
+ Filters an object to return only properties that start with `aria-` or `data-` prefixes. This utility is useful when you need to pass accessibility and data attributes to HTML elements while excluding other props like event handlers or component-specific props.
305
+
306
+ ```tsx
307
+ import { filterAriaAndDataAttrs } from "@uxf/core/utils/filter-aria-and-data-attrs";
308
+
309
+ // Filter accessibility and data attributes from component props
310
+ const props = {
311
+ "aria-label": "Close button",
312
+ "data-testid": "close-btn",
313
+ className: "button",
314
+ onClick: handleClick,
315
+ };
316
+
317
+ const htmlAttrs = filterAriaAndDataAttrs(props);
318
+ // Result: { "aria-label": "Close button", "data-testid": "close-btn" }
319
+
320
+ <button {...htmlAttrs}>Close</button>
321
+ ```
322
+
323
+ ```tsx
324
+ // Use case: Passing only safe attributes to a native element
325
+ function CustomInput({ label, onChange, ...restProps }) {
326
+ const accessibilityAttrs = filterAriaAndDataAttrs(restProps);
327
+
328
+ return <input {...accessibilityAttrs} onChange={onChange} />;
329
+ }
330
+
331
+ <CustomInput
332
+ aria-describedby="helper-text"
333
+ data-analytics="email-input"
334
+ customProp="ignored"
335
+ />
336
+ ```
337
+
288
338
  ### formatBytes
289
339
 
290
340
  Appends suitable unit to the byte value of data size.
@@ -304,6 +354,36 @@ isEmpty(["1"]); /* returns false */
304
354
  isEmpty([]); /* returns true */
305
355
  ```
306
356
 
357
+ ## isEven
358
+
359
+ Checks if a number is even.
360
+
361
+ ```tsx
362
+ import { isEven } from "@uxf/core/utils/is-even";
363
+
364
+ isEven(2); /* returns true */
365
+ isEven(4); /* returns true */
366
+ isEven(1); /* returns false */
367
+ isEven(3); /* returns false */
368
+ isEven(0); /* returns true */
369
+ isEven(-2); /* returns true */
370
+ ```
371
+
372
+ ## isOdd
373
+
374
+ Checks if a number is odd.
375
+
376
+ ```tsx
377
+ import { isOdd } from "@uxf/core/utils/is-odd";
378
+
379
+ isOdd(1); /* returns true */
380
+ isOdd(3); /* returns true */
381
+ isOdd(2); /* returns false */
382
+ isOdd(4); /* returns false */
383
+ isOdd(0); /* returns false */
384
+ isOdd(-1); /* returns true */
385
+ ```
386
+
307
387
  ## isBrowser / isServer
308
388
 
309
389
  ```tsx
@@ -342,6 +422,8 @@ isNotNil([]); /* returns true */
342
422
  isNotNil("string"); /* returns true */
343
423
  ```
344
424
 
425
+ ## last
426
+
345
427
  ```tsx
346
428
  import { last } from "@uxf/core/utils/last";
347
429
 
@@ -349,6 +431,63 @@ last([1, 2]); /* returns 2 */
349
431
  last([]); /* returns undefined */
350
432
  ```
351
433
 
434
+ ## nonEmptyArrayOrNull
435
+
436
+ Converts empty arrays, `null`, or `undefined` values to `null`, leaving all non-empty arrays unchanged. Useful for normalizing form inputs or API data where empty arrays should be treated as `null`.
437
+
438
+ ```tsx
439
+ import { nonEmptyArrayOrNull } from "@uxf/core/utils/non-empty-array-or-null";
440
+
441
+ nonEmptyArrayOrNull([]); /* returns null */
442
+ nonEmptyArrayOrNull(null); /* returns null */
443
+ nonEmptyArrayOrNull(undefined); /* returns null */
444
+ nonEmptyArrayOrNull([1, 2, 3]); /* returns [1, 2, 3] */
445
+ nonEmptyArrayOrNull(["a", "b"]); /* returns ["a", "b"] */
446
+ ```
447
+
448
+ ## nonEmptyStringOrNull
449
+
450
+ Converts empty strings and `undefined` values to `null`, leaving all other strings unchanged. Useful for normalizing form inputs or API data where empty strings should be treated as `null`.
451
+
452
+ ```tsx
453
+ import { nonEmptyStringOrNull } from "@uxf/core/utils/non-empty-string-or-null";
454
+
455
+ nonEmptyStringOrNull(""); /* returns null */
456
+ nonEmptyStringOrNull(undefined); /* returns null */
457
+ nonEmptyStringOrNull(null); /* returns null */
458
+ nonEmptyStringOrNull("test"); /* returns "test" */
459
+ nonEmptyStringOrNull(" "); /* returns " " - non-empty string */
460
+ ```
461
+
462
+ ## nullishToEmptyString
463
+
464
+ Converts `null` or `undefined` values to an empty string, leaving all other strings unchanged. Useful for safely displaying nullable string values in UI components.
465
+
466
+ ```tsx
467
+ import { nullishToEmptyString } from "@uxf/core/utils/nullish-to-empty-string";
468
+
469
+ nullishToEmptyString(null); /* returns "" */
470
+ nullishToEmptyString(undefined); /* returns "" */
471
+ nullishToEmptyString(""); /* returns "" */
472
+ nullishToEmptyString("hello world"); /* returns "hello world" */
473
+ ```
474
+
475
+ ## numberOrNull
476
+
477
+ Converts `NaN`, `null`, or `undefined` values to `null`, leaving all valid numbers unchanged. Useful for normalizing numeric inputs or API data where invalid numbers should be treated as `null`.
478
+
479
+ ```tsx
480
+ import { numberOrNull } from "@uxf/core/utils/number-or-null";
481
+
482
+ numberOrNull(0); /* returns 0 */
483
+ numberOrNull(42); /* returns 42 */
484
+ numberOrNull(-1); /* returns -1 */
485
+ numberOrNull(3.14); /* returns 3.14 */
486
+ numberOrNull(NaN); /* returns null */
487
+ numberOrNull(null); /* returns null */
488
+ numberOrNull(undefined); /* returns null */
489
+ ```
490
+
352
491
  ## slugify
353
492
 
354
493
  ```tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "11.85.0",
3
+ "version": "11.88.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
package/types/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type Nullish = null | undefined;
2
2
  export type Noop = () => void;
3
+ export type AnyObject = Partial<Record<string, any>>;
3
4
  export interface FileResponse {
4
5
  id: number;
5
6
  name: string;
@@ -0,0 +1,3 @@
1
+ export declare function filterAriaAndDataAttrs<P extends Record<string, any>>(props: P): {
2
+ [k: string]: any;
3
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterAriaAndDataAttrs = filterAriaAndDataAttrs;
4
+ function filterAriaAndDataAttrs(props) {
5
+ return Object.fromEntries(Object.entries(props).filter((p) => { var _a, _b; return Boolean(((_a = p.at(0)) === null || _a === void 0 ? void 0 : _a.startsWith("aria-")) || ((_b = p.at(0)) === null || _b === void 0 ? void 0 : _b.startsWith("data-"))); }));
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const filter_aria_and_data_attrs_1 = require("./filter-aria-and-data-attrs");
4
+ describe("filterAriaAndDataAttrs", () => {
5
+ it("should filter only aria- attributes", () => {
6
+ const props = {
7
+ "aria-label": "test label",
8
+ "aria-hidden": true,
9
+ className: "test-class",
10
+ id: "test-id",
11
+ };
12
+ const result = (0, filter_aria_and_data_attrs_1.filterAriaAndDataAttrs)(props);
13
+ expect(result).toEqual({
14
+ "aria-label": "test label",
15
+ "aria-hidden": true,
16
+ });
17
+ });
18
+ it("should filter only data- attributes", () => {
19
+ const props = {
20
+ "data-testid": "test",
21
+ "data-value": 123,
22
+ className: "test-class",
23
+ onClick: jest.fn(),
24
+ };
25
+ const result = (0, filter_aria_and_data_attrs_1.filterAriaAndDataAttrs)(props);
26
+ expect(result).toEqual({
27
+ "data-testid": "test",
28
+ "data-value": 123,
29
+ });
30
+ });
31
+ it("should filter both aria- and data- attributes", () => {
32
+ const props = {
33
+ "aria-label": "label",
34
+ "data-testid": "test",
35
+ "aria-describedby": "desc",
36
+ "data-custom": "value",
37
+ className: "class",
38
+ style: { color: "red" },
39
+ };
40
+ const result = (0, filter_aria_and_data_attrs_1.filterAriaAndDataAttrs)(props);
41
+ expect(result).toEqual({
42
+ "aria-label": "label",
43
+ "data-testid": "test",
44
+ "aria-describedby": "desc",
45
+ "data-custom": "value",
46
+ });
47
+ });
48
+ it("should return empty object when no aria- or data- attributes present", () => {
49
+ const props = {
50
+ className: "test",
51
+ id: "id",
52
+ onClick: jest.fn(),
53
+ };
54
+ const result = (0, filter_aria_and_data_attrs_1.filterAriaAndDataAttrs)(props);
55
+ expect(result).toEqual({});
56
+ });
57
+ it("should return empty object for empty input", () => {
58
+ const props = {};
59
+ const result = (0, filter_aria_and_data_attrs_1.filterAriaAndDataAttrs)(props);
60
+ expect(result).toEqual({});
61
+ });
62
+ it("should handle attributes with various value types", () => {
63
+ const props = {
64
+ "aria-expanded": false,
65
+ "aria-level": 2,
66
+ "data-object": { nested: "value" },
67
+ "data-array": [1, 2, 3],
68
+ "data-null": null,
69
+ "data-undefined": undefined,
70
+ regularProp: "value",
71
+ };
72
+ const result = (0, filter_aria_and_data_attrs_1.filterAriaAndDataAttrs)(props);
73
+ expect(result).toEqual({
74
+ "aria-expanded": false,
75
+ "aria-level": 2,
76
+ "data-object": { nested: "value" },
77
+ "data-array": [1, 2, 3],
78
+ "data-null": null,
79
+ "data-undefined": undefined,
80
+ });
81
+ });
82
+ it("should not filter attributes that contain but don't start with aria- or data-", () => {
83
+ const props = {
84
+ "aria-label": "keep",
85
+ "data-id": "keep",
86
+ "my-aria-label": "remove",
87
+ "my-data-id": "remove",
88
+ };
89
+ const result = (0, filter_aria_and_data_attrs_1.filterAriaAndDataAttrs)(props);
90
+ expect(result).toEqual({
91
+ "aria-label": "keep",
92
+ "data-id": "keep",
93
+ });
94
+ });
95
+ });
@@ -0,0 +1,3 @@
1
+ export declare function filterNullishObjectValues(obj: Record<string, any>): {
2
+ [k: string]: any;
3
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterNullishObjectValues = filterNullishObjectValues;
4
+ const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
5
+ function filterNullishObjectValues(obj) {
6
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => (0, is_not_nil_1.isNotNil)(value)));
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const filter_nullish_object_values_1 = require("./filter-nullish-object-values");
4
+ test("filter-nullish-object-values", () => {
5
+ expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: 1, b: null, c: "test", d: undefined })).toStrictEqual({
6
+ a: 1,
7
+ c: "test",
8
+ });
9
+ expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: 0, b: "", c: false, d: NaN })).toStrictEqual({
10
+ a: 0,
11
+ b: "",
12
+ c: false,
13
+ d: NaN,
14
+ });
15
+ expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: [], b: {} })).toStrictEqual({ a: [], b: {} });
16
+ expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({})).toStrictEqual({});
17
+ expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: null, b: undefined })).toStrictEqual({});
18
+ });
@@ -1 +1,2 @@
1
- export declare function filterNullish<T>(val: Array<T | null | undefined>): T[];
1
+ import { Nullish } from "../types";
2
+ export declare function filterNullish<T>(val: Array<T | Nullish>): T[];
@@ -0,0 +1 @@
1
+ export declare function isEven(n: number): boolean;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEven = isEven;
4
+ function isEven(n) {
5
+ return n % 2 === 0;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_even_1 = require("./is-even");
4
+ test("is-even", () => {
5
+ [0, 2, 4, 10, 100, -2, -4].map((value) => expect((0, is_even_1.isEven)(value)).toBeTruthy());
6
+ [1, 3, 5, 11, 101, -1, -3].map((value) => expect((0, is_even_1.isEven)(value)).toBeFalsy());
7
+ });
@@ -0,0 +1 @@
1
+ export declare function isOdd(n: number): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOdd = isOdd;
4
+ const is_even_1 = require("./is-even");
5
+ function isOdd(n) {
6
+ return !(0, is_even_1.isEven)(n);
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_odd_1 = require("./is-odd");
4
+ test("is-odd", () => {
5
+ [1, 3, 5, 11, 101, -1, -3].map((value) => expect((0, is_odd_1.isOdd)(value)).toBeTruthy());
6
+ [0, 2, 4, 10, 100, -2, -4].map((value) => expect((0, is_odd_1.isOdd)(value)).toBeFalsy());
7
+ });
@@ -0,0 +1,2 @@
1
+ import { Nullish } from "@uxf/core/types";
2
+ export declare function nonEmptyArrayOrNull<T>(value: Nullish | T[]): T[] | null;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonEmptyArrayOrNull = nonEmptyArrayOrNull;
4
+ const is_empty_1 = require("@uxf/core/utils/is-empty");
5
+ const is_nil_1 = require("@uxf/core/utils/is-nil");
6
+ function nonEmptyArrayOrNull(value) {
7
+ return (0, is_nil_1.isNil)(value) || (0, is_empty_1.isEmpty)(value) ? null : value;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const non_empty_array_or_null_1 = require("./non-empty-array-or-null");
4
+ test("non-empty-array-or-null", () => {
5
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([])).toBe(null);
6
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)(undefined)).toBe(null);
7
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)(null)).toBe(null);
8
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([1, 2, 3])).toStrictEqual([1, 2, 3]);
9
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)(["a", "b"])).toStrictEqual(["a", "b"]);
10
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([0])).toStrictEqual([0]);
11
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([false])).toStrictEqual([false]);
12
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([null])).toStrictEqual([null]);
13
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([{}])).toStrictEqual([{}]);
14
+ });
@@ -0,0 +1,2 @@
1
+ import { Nullish } from "../types";
2
+ export declare function nonEmptyStringOrNull(value: string | Nullish): string | null;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonEmptyStringOrNull = nonEmptyStringOrNull;
4
+ function nonEmptyStringOrNull(value) {
5
+ return value === "" || value === undefined ? null : value;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const non_empty_string_or_null_1 = require("./non-empty-string-or-null");
4
+ test("nullish-empty-string-to-nullable", () => {
5
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)("")).toBe(null);
6
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)(undefined)).toBe(null);
7
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)(null)).toBe(null);
8
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)("test")).toBe("test");
9
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)("hello world")).toBe("hello world");
10
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)(" ")).toBe(" ");
11
+ });
@@ -0,0 +1,2 @@
1
+ import { Nullish } from "../types";
2
+ export declare function nullishToEmptyString(value: string | Nullish): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nullishToEmptyString = nullishToEmptyString;
4
+ function nullishToEmptyString(value) {
5
+ return value !== null && value !== void 0 ? value : "";
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const nullish_to_empty_string_1 = require("./nullish-to-empty-string");
4
+ test("nullish-to-empty-string", () => {
5
+ expect((0, nullish_to_empty_string_1.nullishToEmptyString)(null)).toBe("");
6
+ expect((0, nullish_to_empty_string_1.nullishToEmptyString)(undefined)).toBe("");
7
+ expect((0, nullish_to_empty_string_1.nullishToEmptyString)("")).toBe("");
8
+ expect((0, nullish_to_empty_string_1.nullishToEmptyString)("test")).toBe("test");
9
+ expect((0, nullish_to_empty_string_1.nullishToEmptyString)("hello world")).toBe("hello world");
10
+ });
@@ -0,0 +1,2 @@
1
+ import { Nullish } from "../types";
2
+ export declare function numberOrNull(value: number | Nullish): number | null;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.numberOrNull = numberOrNull;
4
+ const is_not_nil_1 = require("./is-not-nil");
5
+ function numberOrNull(value) {
6
+ return (0, is_not_nil_1.isNotNil)(value) && !isNaN(value) ? value : null;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const number_or_null_1 = require("./number-or-null");
4
+ test("number-or-null", () => {
5
+ // Valid numbers should return the number
6
+ expect((0, number_or_null_1.numberOrNull)(0)).toBe(0);
7
+ expect((0, number_or_null_1.numberOrNull)(1)).toBe(1);
8
+ expect((0, number_or_null_1.numberOrNull)(-1)).toBe(-1);
9
+ expect((0, number_or_null_1.numberOrNull)(42)).toBe(42);
10
+ expect((0, number_or_null_1.numberOrNull)(3.14)).toBe(3.14);
11
+ expect((0, number_or_null_1.numberOrNull)(-99.99)).toBe(-99.99);
12
+ // null should return null
13
+ expect((0, number_or_null_1.numberOrNull)(null)).toBe(null);
14
+ // undefined should return null
15
+ expect((0, number_or_null_1.numberOrNull)(undefined)).toBe(null);
16
+ // NaN should return null
17
+ expect((0, number_or_null_1.numberOrNull)(NaN)).toBe(null);
18
+ });
package/utils/resizer.js CHANGED
@@ -35,7 +35,11 @@ const BASE_PATH = (_b = process.env.NEXT_PUBLIC_BASE_PATH) !== null && _b !== vo
35
35
  const resizerStaticImageUrl = (src, width = "auto", height = "auto", props = {}, version = 1) => {
36
36
  var _a;
37
37
  const { fit = "cover", position = "center", toFormat = undefined, trim = "not-trim", background = "FFF" } = props;
38
- const filepath = typeof src === "string" ? src : src.src;
38
+ let filepath = typeof src === "string" ? src : src.src;
39
+ // fix absolute assetPrefix
40
+ if (!filepath.startsWith("/")) {
41
+ filepath = new URL(filepath).pathname;
42
+ }
39
43
  const dotIndex = filepath.lastIndexOf(".");
40
44
  const filename = filepath.slice(0, dotIndex);
41
45
  const extension = filepath.slice(dotIndex + 1);
@@ -16,7 +16,7 @@ describe("resizerGetDefaultConfig", () => {
16
16
  toFormat: "avif",
17
17
  quality: 1,
18
18
  });
19
- expect(url).toBe("/generated/static/x_x_cv_b_t_nt_1/1http://example.com/image.jpg.avif");
19
+ expect(url).toBe("/generated/static/x_x_cv_b_t_nt_1/1/image.jpg.avif");
20
20
  });
21
21
  it("should return a valid URL for an ImageResponse source", () => {
22
22
  const imageResponse = {
@@ -29,7 +29,7 @@ describe("resizerGetDefaultConfig", () => {
29
29
  });
30
30
  it("should return a valid URL for a string source", () => {
31
31
  const url = (0, resizer_1.resizerImageUrl)("http://example.com/image.png", 250, 250, { toFormat: "webp" });
32
- expect(url).toBe("/generated/static/250_250_cv_c_FFF_nt_x/1http://example.com/image.png.webp");
32
+ expect(url).toBe("/generated/static/250_250_cv_c_FFF_nt_x/1/image.png.webp");
33
33
  });
34
34
  it("should return undefined for null or undefined source", () => {
35
35
  expect((0, resizer_1.resizerImageUrl)(null)).toBeUndefined();