@uxf/core 11.45.0 → 11.47.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 (48) hide show
  1. package/cookie/cookie.test.d.ts +1 -0
  2. package/cookie/cookie.test.js +68 -0
  3. package/money/currencies.d.ts +503 -0
  4. package/money/currencies.js +172 -0
  5. package/money/get-currency-symbol.d.ts +2 -0
  6. package/money/get-currency-symbol.js +6 -0
  7. package/money/get-currency-symbol.test.d.ts +1 -0
  8. package/money/get-currency-symbol.test.js +11 -0
  9. package/money/index.d.ts +6 -0
  10. package/money/index.js +2 -0
  11. package/next/query-param.test.d.ts +1 -0
  12. package/next/query-param.test.js +35 -0
  13. package/package.json +1 -1
  14. package/utils/assert-not-nil.test.d.ts +1 -0
  15. package/utils/assert-not-nil.test.js +8 -0
  16. package/utils/copy-to-clipboard.test.d.ts +1 -0
  17. package/utils/copy-to-clipboard.test.js +30 -0
  18. package/utils/file.test.d.ts +1 -0
  19. package/utils/file.test.js +35 -0
  20. package/utils/filter-nullish.test.d.ts +1 -0
  21. package/utils/filter-nullish.test.js +15 -0
  22. package/utils/is-empty.d.ts +3 -1
  23. package/utils/is-empty.js +3 -0
  24. package/utils/is-empty.test.js +5 -4
  25. package/utils/is-nil.test.d.ts +1 -0
  26. package/utils/is-nil.test.js +7 -0
  27. package/utils/is-not-empty.d.ts +3 -1
  28. package/utils/is-not-empty.test.js +5 -4
  29. package/utils/is-not-nil.test.d.ts +1 -0
  30. package/utils/is-not-nil.test.js +7 -0
  31. package/utils/isBrowser.test.d.ts +1 -0
  32. package/utils/isBrowser.test.js +12 -0
  33. package/utils/isServer.test.d.ts +1 -0
  34. package/utils/isServer.test.js +12 -0
  35. package/utils/noop.test.d.ts +1 -0
  36. package/utils/noop.test.js +15 -0
  37. package/utils/resizer.d.ts +2 -2
  38. package/utils/resizer.js +7 -7
  39. package/utils/resizer.test.d.ts +1 -0
  40. package/utils/resizer.test.js +85 -0
  41. package/utils/slugify.test.js +5 -3
  42. package/utils/sort-object-keys.test.d.ts +1 -0
  43. package/utils/sort-object-keys.test.js +65 -0
  44. package/utils/throw-error.test.d.ts +1 -0
  45. package/utils/throw-error.test.js +14 -0
  46. package/utils/trim-trailing-zeros.test.d.ts +1 -0
  47. package/utils/trim-trailing-zeros.test.js +10 -0
  48. package/utils/trimTrailingZeros.js +1 -1
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.currencies = void 0;
4
+ exports.currencies = {
5
+ AED: { symbol: "د.إ" },
6
+ AFN: { symbol: "؋" },
7
+ ALL: { symbol: "" },
8
+ AMD: { symbol: "֏" },
9
+ ANG: { symbol: "ƒ" },
10
+ AOA: { symbol: "" },
11
+ ARS: { symbol: "$" },
12
+ AUD: { symbol: "$" },
13
+ AWG: { symbol: "ƒ" },
14
+ AZN: { symbol: "₼" },
15
+ BAM: { symbol: "" },
16
+ BBD: { symbol: "" },
17
+ BDT: { symbol: "৳" },
18
+ BGN: { symbol: "лв" },
19
+ BHD: { symbol: ".د.ب" },
20
+ BIF: { symbol: "FBu" },
21
+ BMD: { symbol: "" },
22
+ BND: { symbol: "" },
23
+ BOB: { symbol: "" },
24
+ BOV: { symbol: "" },
25
+ BRL: { symbol: "R$" },
26
+ BSD: { symbol: "" },
27
+ BTN: { symbol: "Nu." },
28
+ BWP: { symbol: "" },
29
+ BYN: { symbol: "Br" },
30
+ BZD: { symbol: "" },
31
+ CAD: { symbol: "$" },
32
+ CDF: { symbol: "" },
33
+ CHE: { symbol: "" },
34
+ CHF: { symbol: "CHF" },
35
+ CHW: { symbol: "" },
36
+ CLF: { symbol: "" },
37
+ CLP: { symbol: "$" },
38
+ CNY: { symbol: "¥" },
39
+ COP: { symbol: "$" },
40
+ COU: { symbol: "" },
41
+ CRC: { symbol: "₡" },
42
+ CUC: { symbol: "" },
43
+ CUP: { symbol: "₱" },
44
+ CVE: { symbol: "$" },
45
+ CZK: { symbol: "Kč" },
46
+ DJF: { symbol: "Fdj" },
47
+ DKK: { symbol: "kr" },
48
+ DOP: { symbol: "" },
49
+ DZD: { symbol: "" },
50
+ EGP: { symbol: "£" },
51
+ ERN: { symbol: "Nfk" },
52
+ ETB: { symbol: "" },
53
+ EUR: { symbol: "€" },
54
+ FJD: { symbol: "$" },
55
+ FKP: { symbol: "" },
56
+ GBP: { symbol: "£" },
57
+ GEL: { symbol: "₾" },
58
+ GHS: { symbol: "" },
59
+ GIP: { symbol: "" },
60
+ GMD: { symbol: "D" },
61
+ GNF: { symbol: "FG" },
62
+ GTQ: { symbol: "" },
63
+ GYD: { symbol: "" },
64
+ HKD: { symbol: "$" },
65
+ HNL: { symbol: "" },
66
+ HTG: { symbol: "G" },
67
+ HUF: { symbol: "Ft" },
68
+ IDR: { symbol: "Rp" },
69
+ ILS: { symbol: "" },
70
+ INR: { symbol: "₹" },
71
+ IQD: { symbol: "ع.د" },
72
+ IRR: { symbol: "" },
73
+ ISK: { symbol: "kr" },
74
+ JMD: { symbol: "" },
75
+ JOD: { symbol: "" },
76
+ JPY: { symbol: "¥" },
77
+ KES: { symbol: "" },
78
+ KGS: { symbol: "с" },
79
+ KHR: { symbol: "៛" },
80
+ KMF: { symbol: "CF" },
81
+ KPW: { symbol: "" },
82
+ KRW: { symbol: "₩" },
83
+ KWD: { symbol: "د.ك" },
84
+ KYD: { symbol: "" },
85
+ KZT: { symbol: "₸" },
86
+ LAK: { symbol: "" },
87
+ LBP: { symbol: "" },
88
+ LKR: { symbol: "₨" },
89
+ LRD: { symbol: "$" },
90
+ LSL: { symbol: "L" },
91
+ LYD: { symbol: "" },
92
+ MAD: { symbol: "" },
93
+ MDL: { symbol: "L" },
94
+ MGA: { symbol: "" },
95
+ MKD: { symbol: "" },
96
+ MMK: { symbol: "K" },
97
+ MNT: { symbol: "₮" },
98
+ MOP: { symbol: "" },
99
+ MRU: { symbol: "" },
100
+ MUR: { symbol: "" },
101
+ MVR: { symbol: "" },
102
+ MWK: { symbol: "MK" },
103
+ MXN: { symbol: "$" },
104
+ MXV: { symbol: "" },
105
+ MYR: { symbol: "RM" },
106
+ MZN: { symbol: "MT" },
107
+ NAD: { symbol: "" },
108
+ NGN: { symbol: "₦" },
109
+ NIO: { symbol: "" },
110
+ NOK: { symbol: "kr" },
111
+ NPR: { symbol: "₨" },
112
+ NZD: { symbol: "$" },
113
+ OMR: { symbol: "" },
114
+ PAB: { symbol: "" },
115
+ PEN: { symbol: "S/" },
116
+ PGK: { symbol: "K" },
117
+ PHP: { symbol: "₱" },
118
+ PKR: { symbol: "₨" },
119
+ PLN: { symbol: "zł" },
120
+ PYG: { symbol: "₲" },
121
+ QAR: { symbol: "" },
122
+ RON: { symbol: "lei" },
123
+ RSD: { symbol: "дин." },
124
+ RUB: { symbol: "₽" },
125
+ RWF: { symbol: "" },
126
+ SAR: { symbol: "" },
127
+ SBD: { symbol: "$" },
128
+ SCR: { symbol: "" },
129
+ SDG: { symbol: "ج.س." },
130
+ SEK: { symbol: "kr" },
131
+ SGD: { symbol: "$" },
132
+ SHP: { symbol: "" },
133
+ SLE: { symbol: "" },
134
+ SLL: { symbol: "Le" },
135
+ SOS: { symbol: "" },
136
+ SRD: { symbol: "$" },
137
+ SSP: { symbol: "" },
138
+ STN: { symbol: "" },
139
+ SVC: { symbol: "" },
140
+ SYP: { symbol: "£" },
141
+ SZL: { symbol: "E" },
142
+ THB: { symbol: "฿" },
143
+ TJS: { symbol: "ЅМ" },
144
+ TMT: { symbol: "m" },
145
+ TND: { symbol: "" },
146
+ TOP: { symbol: "" },
147
+ TRY: { symbol: "₺" },
148
+ TTD: { symbol: "" },
149
+ TWD: { symbol: "" },
150
+ TZS: { symbol: "Sh" },
151
+ UAH: { symbol: "" },
152
+ UGX: { symbol: "USh" },
153
+ USD: { symbol: "$" },
154
+ USN: { symbol: "" },
155
+ UYI: { symbol: "" },
156
+ UYU: { symbol: "$" },
157
+ UYW: { symbol: "" },
158
+ UZS: { symbol: "soʻm" },
159
+ VED: { symbol: "" },
160
+ VES: { symbol: "Bs" },
161
+ VND: { symbol: "₫" },
162
+ VUV: { symbol: "VT" },
163
+ WST: { symbol: "T" },
164
+ XAF: { symbol: "" },
165
+ XCD: { symbol: "" },
166
+ XOF: { symbol: "CFA" },
167
+ XPF: { symbol: "₣" },
168
+ YER: { symbol: "﷼" },
169
+ ZAR: { symbol: "R" },
170
+ ZMW: { symbol: "ZK" },
171
+ ZWL: { symbol: "" },
172
+ };
@@ -0,0 +1,2 @@
1
+ import { Currency } from "@uxf/localize/src/types";
2
+ export declare const getCurrencySymbol: (currency: Currency) => "" | "د.إ" | "؋" | "֏" | "ƒ" | "$" | "₼" | "৳" | "лв" | ".د.ب" | "FBu" | "R$" | "Nu." | "Br" | "CHF" | "¥" | "₡" | "₱" | "Kč" | "Fdj" | "kr" | "£" | "Nfk" | "€" | "₾" | "D" | "FG" | "G" | "Ft" | "Rp" | "₹" | "ع.د" | "с" | "៛" | "CF" | "₩" | "د.ك" | "₸" | "₨" | "L" | "K" | "₮" | "MK" | "RM" | "MT" | "₦" | "S/" | "zł" | "₲" | "lei" | "дин." | "₽" | "ج.س." | "Le" | "E" | "฿" | "ЅМ" | "m" | "₺" | "Sh" | "USh" | "soʻm" | "Bs" | "₫" | "VT" | "T" | "CFA" | "₣" | "﷼" | "R" | "ZK";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCurrencySymbol = void 0;
4
+ const currencies_1 = require("./currencies");
5
+ const getCurrencySymbol = (currency) => currencies_1.currencies[currency].symbol;
6
+ exports.getCurrencySymbol = getCurrencySymbol;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const currencies_1 = require("./currencies");
4
+ const get_currency_symbol_1 = require("./get-currency-symbol");
5
+ describe("getCurrencySymbol", () => {
6
+ it("should return the correct symbol for a given currency", () => {
7
+ const currency = "USD";
8
+ const result = (0, get_currency_symbol_1.getCurrencySymbol)(currency);
9
+ expect(result).toBe(currencies_1.currencies[currency].symbol);
10
+ });
11
+ });
@@ -0,0 +1,6 @@
1
+ import { currencies } from "./currencies";
2
+ export type Currency = keyof typeof currencies;
3
+ export type Money = {
4
+ amount: string;
5
+ currency: Currency;
6
+ };
package/money/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ describe("queryParamToString", () => {
5
+ it("should return the string when a string is passed", () => {
6
+ const result = (0, index_1.queryParamToString)("test");
7
+ expect(result).toBe("test");
8
+ });
9
+ it("should return an empty string when undefined is passed", () => {
10
+ const result = (0, index_1.queryParamToString)(undefined);
11
+ expect(result).toBe("");
12
+ });
13
+ it("should return an empty string when an array is passed", () => {
14
+ const result = (0, index_1.queryParamToString)(["test", "jest"]);
15
+ expect(result).toBe("");
16
+ });
17
+ });
18
+ describe("queryParamToNumber", () => {
19
+ it("should return the number when a valid string is passed", () => {
20
+ const result = (0, index_1.queryParamToNumber)("42");
21
+ expect(result).toBe(42);
22
+ });
23
+ it("should return 0 when undefined is passed", () => {
24
+ const result = (0, index_1.queryParamToNumber)(undefined);
25
+ expect(result).toBe(0);
26
+ });
27
+ it("should return 0 when an array is passed", () => {
28
+ const result = (0, index_1.queryParamToNumber)(["42", "8"]);
29
+ expect(result).toBe(0);
30
+ });
31
+ it("should return NaN when an invalid number string is passed", () => {
32
+ const result = (0, index_1.queryParamToNumber)("not a number");
33
+ expect(result).toBe(NaN);
34
+ });
35
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "11.45.0",
3
+ "version": "11.47.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const assert_not_nil_1 = require("./assert-not-nil");
4
+ test("assert-not-nil", () => {
5
+ expect(() => (0, assert_not_nil_1.assertNotNil)(null)).toThrow("Value is nil.");
6
+ expect(() => (0, assert_not_nil_1.assertNotNil)(undefined, "Test")).toThrow("Test");
7
+ ["", true, false, NaN, 0, [], {}].map((value) => expect(() => (0, assert_not_nil_1.assertNotNil)(value)).not.toThrow("Value is nil."));
8
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const copy_to_clipboard_1 = require("./copy-to-clipboard");
4
+ describe("Clipboard Functions", () => {
5
+ beforeEach(() => {
6
+ document.execCommand = jest.fn();
7
+ Object.defineProperty(navigator, "clipboard", {
8
+ value: {
9
+ writeText: jest.fn(),
10
+ },
11
+ writable: true,
12
+ });
13
+ });
14
+ it("should copy text using navigator.clipboard when supported", async () => {
15
+ const text = "Hello, World!";
16
+ const result = await (0, copy_to_clipboard_1.copyToClipboard)(text);
17
+ expect(navigator.clipboard.writeText).toHaveBeenCalledWith(text);
18
+ expect(result).toBe(true);
19
+ });
20
+ it("should return false when clipboard.writeText throws an error during fallback", async () => {
21
+ navigator.clipboard.writeText = jest.fn().mockRejectedValue(new Error("Clipboard API not supported"));
22
+ document.execCommand = jest.fn().mockImplementation(() => {
23
+ throw new Error("Copy failed");
24
+ });
25
+ const consoleErrorMock = jest.spyOn(console, "error").mockImplementation(() => ({}));
26
+ const result = await (0, copy_to_clipboard_1.copyToClipboard)("Hello, World!");
27
+ expect(result).toBe(false);
28
+ consoleErrorMock.mockRestore();
29
+ });
30
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const file_1 = require("./file");
4
+ test("file", () => {
5
+ expect((0, file_1.getFileUrl)({
6
+ uuid: "",
7
+ namespace: undefined,
8
+ extension: "",
9
+ })).toBe("/upload///.");
10
+ expect((0, file_1.getFileUrl)({
11
+ uuid: "",
12
+ namespace: undefined,
13
+ extension: "extension",
14
+ })).toBe("/upload///.extension");
15
+ expect((0, file_1.getFileUrl)({
16
+ uuid: "",
17
+ namespace: "namespace",
18
+ extension: "extension",
19
+ })).toBe("/upload/namespace///.extension");
20
+ expect((0, file_1.getFileUrl)({
21
+ uuid: "uuid",
22
+ namespace: null,
23
+ extension: "extension",
24
+ })).toBe("/upload/u/u/uuid.extension");
25
+ expect((0, file_1.getFileUrl)({
26
+ uuid: "u",
27
+ namespace: undefined,
28
+ extension: "",
29
+ })).toBe("/upload/u//u.");
30
+ expect((0, file_1.getFileUrl)({
31
+ uuid: "uuid",
32
+ namespace: "namespace",
33
+ extension: "extension",
34
+ })).toBe("/upload/namespace/u/u/uuid.extension");
35
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const filter_nullish_1 = require("./filter-nullish");
4
+ test("filter-nullish", () => {
5
+ expect((0, filter_nullish_1.filterNullish)([undefined, null, 0, NaN, "", true, false, [], {}])).toStrictEqual([
6
+ 0,
7
+ NaN,
8
+ "",
9
+ true,
10
+ false,
11
+ [],
12
+ {},
13
+ ]);
14
+ expect((0, filter_nullish_1.filterNullish)([])).toStrictEqual([]);
15
+ });
@@ -1 +1,3 @@
1
- export declare function isEmpty(value: any[] | string): boolean;
1
+ export declare function isEmpty(value: any[] | {
2
+ [key: string]: any;
3
+ } | string): boolean;
package/utils/is-empty.js CHANGED
@@ -5,5 +5,8 @@ function isEmpty(value) {
5
5
  if (Array.isArray(value)) {
6
6
  return value.length === 0;
7
7
  }
8
+ else if (value && typeof value === "object") {
9
+ return Object.keys(value).length === 0;
10
+ }
8
11
  return value === "";
9
12
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition,@typescript-eslint/ban-ts-comment */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  const is_empty_1 = require("./is-empty");
4
5
  test("is-empty", () => {
5
- expect((0, is_empty_1.isEmpty)(["1"])).toBeFalsy();
6
- expect((0, is_empty_1.isEmpty)([])).toBeTruthy();
7
- expect((0, is_empty_1.isEmpty)("not-empty")).toBeFalsy();
8
- expect((0, is_empty_1.isEmpty)("")).toBeTruthy();
6
+ [["1"], { not: "empty" }, "not-empty"].map((value) => expect((0, is_empty_1.isEmpty)(value)).toBeFalsy());
7
+ [[], {}, ""].map((value) => expect((0, is_empty_1.isEmpty)(value)).toBeTruthy());
8
+ // @ts-expect-error
9
+ [0, null, undefined, true, false].map((value) => expect((0, is_empty_1.isEmpty)(value)).toBeFalsy());
9
10
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_nil_1 = require("./is-nil");
4
+ test("is-nil", () => {
5
+ [null, undefined].map((value) => expect((0, is_nil_1.isNil)(value)).toBeTruthy());
6
+ ["", true, false, NaN, 0, [], {}].map((value) => expect((0, is_nil_1.isNil)(value)).toBeFalsy());
7
+ });
@@ -1 +1,3 @@
1
- export declare function isNotEmpty(value: any[] | string): boolean;
1
+ export declare function isNotEmpty(value: any[] | {
2
+ [key: string]: any;
3
+ } | string): boolean;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition,@typescript-eslint/ban-ts-comment */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  const is_not_empty_1 = require("./is-not-empty");
4
5
  test("is-not-empty", () => {
5
- expect((0, is_not_empty_1.isNotEmpty)(["1"])).toBeTruthy();
6
- expect((0, is_not_empty_1.isNotEmpty)([])).toBeFalsy();
7
- expect((0, is_not_empty_1.isNotEmpty)("not-empty")).toBeTruthy();
8
- expect((0, is_not_empty_1.isNotEmpty)("")).toBeFalsy();
6
+ [["1"], { not: "empty" }, "not-empty"].map((value) => expect((0, is_not_empty_1.isNotEmpty)(value)).toBeTruthy());
7
+ [[], {}, ""].map((value) => expect((0, is_not_empty_1.isNotEmpty)(value)).toBeFalsy());
8
+ // @ts-expect-error
9
+ [0, null, undefined, true, false].map((value) => expect((0, is_not_empty_1.isNotEmpty)(value)).toBeTruthy());
9
10
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_not_nil_1 = require("./is-not-nil");
4
+ test("is-not-nil", () => {
5
+ ["", true, false, NaN, 0, [], {}].map((value) => expect((0, is_not_nil_1.isNotNil)(value)).toBeTruthy());
6
+ [null, undefined].map((value) => expect((0, is_not_nil_1.isNotNil)(value)).toBeFalsy());
7
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const isBrowser_1 = require("./isBrowser");
4
+ test("isBrowser", () => {
5
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
6
+ if (window === undefined) {
7
+ expect(isBrowser_1.isBrowser).toBeFalsy();
8
+ }
9
+ else {
10
+ expect(isBrowser_1.isBrowser).toBeTruthy();
11
+ }
12
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const isBrowser_1 = require("./isBrowser");
4
+ const isServer_1 = require("./isServer");
5
+ test("isServer", () => {
6
+ if (isBrowser_1.isBrowser) {
7
+ expect(isServer_1.isServer).toBeFalsy();
8
+ }
9
+ else {
10
+ expect(isServer_1.isServer).toBeTruthy();
11
+ }
12
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const noop_1 = require("./noop");
4
+ describe("noop function", () => {
5
+ it("should return undefined when called", () => {
6
+ const result = (0, noop_1.noop)();
7
+ expect(result).toBeUndefined();
8
+ });
9
+ it("should not call any other function", () => {
10
+ const spy = jest.fn();
11
+ spy();
12
+ expect(spy).toHaveBeenCalled();
13
+ expect((0, noop_1.noop)()).toBeUndefined();
14
+ });
15
+ });
@@ -12,14 +12,14 @@ export type StaticImageData = {
12
12
  blurDataURL?: string;
13
13
  };
14
14
  export type ImageSource = ImageResponse | StaticImageData | string;
15
- declare const fitMapper: {
15
+ export declare const fitMapper: {
16
16
  cover: string;
17
17
  fill: string;
18
18
  contain: string;
19
19
  inside: string;
20
20
  outside: string;
21
21
  };
22
- declare const positionMapper: {
22
+ export declare const positionMapper: {
23
23
  attention: string;
24
24
  bottom: string;
25
25
  centre: string;
package/utils/resizer.js CHANGED
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resizerImageUrl = void 0;
3
+ exports.resizerImageUrl = exports.positionMapper = exports.fitMapper = void 0;
4
4
  exports.resizerGetDefaultConfig = resizerGetDefaultConfig;
5
- const fitMapper = {
5
+ exports.fitMapper = {
6
6
  cover: "cv",
7
7
  fill: "f",
8
8
  contain: "cn",
9
9
  inside: "in",
10
10
  outside: "out",
11
11
  };
12
- const positionMapper = {
12
+ exports.positionMapper = {
13
13
  attention: "a",
14
14
  bottom: "b",
15
15
  centre: "c",
@@ -39,8 +39,8 @@ const resizerStaticImageUrl = (src, width = "auto", height = "auto", props = {},
39
39
  const directory = [
40
40
  width === "auto" ? "x" : width,
41
41
  height === "auto" ? "x" : height,
42
- fitMapper[fit],
43
- positionMapper[position],
42
+ exports.fitMapper[fit],
43
+ exports.positionMapper[position],
44
44
  background === "transparent" ? backgroundMapper[background] : background,
45
45
  trim === "not-trim" ? trimMapper[trim] : trim,
46
46
  (_a = props.quality) !== null && _a !== void 0 ? _a : "x",
@@ -60,8 +60,8 @@ const resizerImageUrl = (source, width = "auto", height = "auto", props = {}, ve
60
60
  source.uuid,
61
61
  width === "auto" ? "x" : width,
62
62
  height === "auto" ? "x" : height,
63
- fitMapper[fit],
64
- positionMapper[position],
63
+ exports.fitMapper[fit],
64
+ exports.positionMapper[position],
65
65
  background === "transparent" ? backgroundMapper[background] : background,
66
66
  trim === "not-trim" ? trimMapper[trim] : trim,
67
67
  (_b = props.quality) !== null && _b !== void 0 ? _b : "x",
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const resizer_1 = require("./resizer");
4
+ describe("resizerGetDefaultConfig", () => {
5
+ it("should return a valid URL for a StaticImageData source", () => {
6
+ const staticImage = {
7
+ src: "http://example.com/image.jpg",
8
+ height: 800,
9
+ width: 600,
10
+ };
11
+ const url = (0, resizer_1.resizerImageUrl)(staticImage, undefined, undefined, {
12
+ fit: "cover",
13
+ position: "bottom",
14
+ background: "transparent",
15
+ trim: "not-trim",
16
+ toFormat: "avif",
17
+ quality: 1,
18
+ });
19
+ expect(url).toBe("/generated/static/x_x_cv_b_t_nt_1/1http://example.com/image.jpg.avif");
20
+ });
21
+ it("should return a valid URL for an ImageResponse source", () => {
22
+ const imageResponse = {
23
+ uuid: "12345678",
24
+ namespace: "images",
25
+ extension: "jpg",
26
+ };
27
+ const url = (0, resizer_1.resizerImageUrl)(imageResponse, 400, 300, { fit: "contain", quality: 80 });
28
+ expect(url).toBe("/generated/images/1/2/12345678_400_300_cn_c_FFF_nt_80_jpg.jpg");
29
+ });
30
+ it("should return a valid URL for a string source", () => {
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");
33
+ });
34
+ it("should return undefined for null or undefined source", () => {
35
+ expect((0, resizer_1.resizerImageUrl)(null)).toBeUndefined();
36
+ expect((0, resizer_1.resizerImageUrl)(undefined)).toBeUndefined();
37
+ expect((0, resizer_1.resizerImageUrl)("")).toBeUndefined();
38
+ });
39
+ it("should use default values for missing props", () => {
40
+ const imageResponse = {
41
+ uuid: "abcdef12",
42
+ extension: "png",
43
+ };
44
+ const url = (0, resizer_1.resizerImageUrl)(imageResponse);
45
+ expect(url).toBe("/generated/undefined/a/b/abcdef12_x_x_cv_c_FFF_nt_x_png.png");
46
+ });
47
+ it("should map fit values correctly", () => {
48
+ const imageResponse = {
49
+ uuid: "fit-test",
50
+ namespace: "images",
51
+ extension: "jpg",
52
+ };
53
+ Object.entries(resizer_1.fitMapper).forEach(([key, value]) => {
54
+ const url = (0, resizer_1.resizerImageUrl)(imageResponse, 300, 200, { fit: key });
55
+ expect(url).toContain(`_${value}`);
56
+ });
57
+ });
58
+ it("should map position values correctly", () => {
59
+ const imageResponse = {
60
+ uuid: "position-test",
61
+ namespace: "images",
62
+ extension: "jpg",
63
+ };
64
+ Object.entries(resizer_1.positionMapper).forEach(([key, value]) => {
65
+ const url = (0, resizer_1.resizerImageUrl)(imageResponse, 300, 200, { position: key });
66
+ expect(url).toContain(`_${value}`);
67
+ });
68
+ });
69
+ it("should return the default configuration based on generatedFilesUrl and staticFilesUrl", () => {
70
+ const generatedFilesUrl = "http://example.com/generated";
71
+ const staticFilesUrl = "http://example.com/static";
72
+ const expectedConfig = [
73
+ {
74
+ route: "/generated/static/:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d+|x)/:version/:filename(*).:extension.:toFormat",
75
+ source: `${staticFilesUrl}/:filename+.:extension`,
76
+ },
77
+ {
78
+ route: "/generated/:namespace/:p1/:p2/:filename([a-f0-9\\-]+)_:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d+|x)_:extension.:toFormat",
79
+ source: `${generatedFilesUrl}/upload/:namespace/:p1/:p2/:filename.:extension`,
80
+ },
81
+ ];
82
+ const result = (0, resizer_1.resizerGetDefaultConfig)(generatedFilesUrl, staticFilesUrl);
83
+ expect(result).toEqual(expectedConfig);
84
+ });
85
+ });