@alibarbar/common 1.0.9 → 1.1.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 (185) hide show
  1. package/dist/{chunk-O3O67R4I.js → algorithm.cjs} +1 -3
  2. package/dist/algorithm.js +130 -44
  3. package/dist/{chunk-LOAZSPGQ.js → array.cjs} +1 -3
  4. package/dist/array.js +135 -84
  5. package/dist/{chunk-Y364QIQH.js → color.cjs} +1 -3
  6. package/dist/color.js +127 -40
  7. package/dist/{chunk-DYBSRI7V.js → crypto.cjs} +109 -3
  8. package/dist/crypto.d.mts +48 -1
  9. package/dist/crypto.d.ts +48 -1
  10. package/dist/crypto.js +274 -60
  11. package/dist/{chunk-BHCRFURU.js → data-structure.cjs} +1 -3
  12. package/dist/data-structure.js +481 -32
  13. package/dist/{chunk-I3L42475.js → date.cjs} +1 -3
  14. package/dist/date.js +125 -72
  15. package/dist/{chunk-JK2SE3I2.js → dom.cjs} +1 -3
  16. package/dist/dom.js +84 -56
  17. package/dist/{chunk-7V5UQXIO.js → file.cjs} +1 -3
  18. package/dist/file.js +79 -32
  19. package/dist/{chunk-OX5PLOWB.js → i18n.cjs} +1 -3
  20. package/dist/i18n.js +78 -40
  21. package/dist/index.cjs +4543 -0
  22. package/dist/index.d.mts +6 -162
  23. package/dist/index.d.ts +6 -162
  24. package/dist/index.js +3712 -17374
  25. package/dist/{chunk-4RGXV4SJ.js → network.cjs} +1 -3
  26. package/dist/network.js +97 -28
  27. package/dist/{chunk-3FRYJPHG.js → number.cjs} +1 -3
  28. package/dist/number.js +77 -56
  29. package/dist/{chunk-27UDDVLZ.js → object.cjs} +1 -3
  30. package/dist/object.js +237 -80
  31. package/dist/{chunk-JQZBPAPO.js → performance.cjs} +1 -3
  32. package/dist/performance.js +145 -40
  33. package/dist/services.cjs +291 -0
  34. package/dist/services.d.mts +161 -0
  35. package/dist/services.d.ts +161 -0
  36. package/dist/services.js +281 -0
  37. package/dist/storage.cjs +943 -0
  38. package/dist/storage.d.mts +46 -1
  39. package/dist/storage.d.ts +46 -1
  40. package/dist/storage.js +930 -32
  41. package/dist/{chunk-D7CS5EKF.js → string.cjs} +1 -3
  42. package/dist/string.js +91 -68
  43. package/dist/{chunk-56W6YECK.js → tracking.cjs} +1 -3
  44. package/dist/tracking.js +359 -52
  45. package/dist/{chunk-ZDMFMUDR.js → transform.cjs} +1 -3
  46. package/dist/transform.js +299 -32
  47. package/dist/{chunk-NJARVI6X.mjs → upload.cjs} +42 -15
  48. package/dist/upload.d.mts +1 -1
  49. package/dist/upload.d.ts +1 -1
  50. package/dist/upload.js +402 -20
  51. package/dist/{chunk-KGFTD255.js → url.cjs} +1 -3
  52. package/dist/url.js +91 -44
  53. package/dist/{chunk-TQN37HIN.js → validation.cjs} +1 -3
  54. package/dist/validation.js +77 -60
  55. package/package.json +7 -2
  56. package/dist/algorithm.js.map +0 -1
  57. package/dist/algorithm.mjs +0 -4
  58. package/dist/algorithm.mjs.map +0 -1
  59. package/dist/array.js.map +0 -1
  60. package/dist/array.mjs +0 -4
  61. package/dist/array.mjs.map +0 -1
  62. package/dist/chunk-27UDDVLZ.js.map +0 -1
  63. package/dist/chunk-2R2QWFJC.mjs +0 -138
  64. package/dist/chunk-2R2QWFJC.mjs.map +0 -1
  65. package/dist/chunk-3FRYJPHG.js.map +0 -1
  66. package/dist/chunk-4RGXV4SJ.js.map +0 -1
  67. package/dist/chunk-56W6YECK.js.map +0 -1
  68. package/dist/chunk-5BGSUGTI.mjs +0 -128
  69. package/dist/chunk-5BGSUGTI.mjs.map +0 -1
  70. package/dist/chunk-7E6GELHJ.mjs +0 -302
  71. package/dist/chunk-7E6GELHJ.mjs.map +0 -1
  72. package/dist/chunk-7V5UQXIO.js.map +0 -1
  73. package/dist/chunk-A4SWQXX7.mjs +0 -484
  74. package/dist/chunk-A4SWQXX7.mjs.map +0 -1
  75. package/dist/chunk-BHCRFURU.js.map +0 -1
  76. package/dist/chunk-CDSGEAOK.mjs +0 -80
  77. package/dist/chunk-CDSGEAOK.mjs.map +0 -1
  78. package/dist/chunk-D7CS5EKF.js.map +0 -1
  79. package/dist/chunk-DYBSRI7V.js.map +0 -1
  80. package/dist/chunk-FEBKPX5A.js +0 -386
  81. package/dist/chunk-FEBKPX5A.js.map +0 -1
  82. package/dist/chunk-FJ6ZGZIA.mjs +0 -39
  83. package/dist/chunk-FJ6ZGZIA.mjs.map +0 -1
  84. package/dist/chunk-HLDFI7R2.mjs +0 -175
  85. package/dist/chunk-HLDFI7R2.mjs.map +0 -1
  86. package/dist/chunk-I3L42475.js.map +0 -1
  87. package/dist/chunk-JBLX27WD.mjs +0 -240
  88. package/dist/chunk-JBLX27WD.mjs.map +0 -1
  89. package/dist/chunk-JHZ7M2MR.mjs +0 -133
  90. package/dist/chunk-JHZ7M2MR.mjs.map +0 -1
  91. package/dist/chunk-JK2SE3I2.js.map +0 -1
  92. package/dist/chunk-JQZBPAPO.js.map +0 -1
  93. package/dist/chunk-JXYGC2C5.mjs +0 -100
  94. package/dist/chunk-JXYGC2C5.mjs.map +0 -1
  95. package/dist/chunk-KGFTD255.js.map +0 -1
  96. package/dist/chunk-LBHBNPNJ.mjs +0 -148
  97. package/dist/chunk-LBHBNPNJ.mjs.map +0 -1
  98. package/dist/chunk-LF4CILQS.mjs +0 -87
  99. package/dist/chunk-LF4CILQS.mjs.map +0 -1
  100. package/dist/chunk-LOAZSPGQ.js.map +0 -1
  101. package/dist/chunk-NJARVI6X.mjs.map +0 -1
  102. package/dist/chunk-NSSDYX2U.mjs +0 -80
  103. package/dist/chunk-NSSDYX2U.mjs.map +0 -1
  104. package/dist/chunk-O3O67R4I.js.map +0 -1
  105. package/dist/chunk-OIXQ3E6W.mjs +0 -354
  106. package/dist/chunk-OIXQ3E6W.mjs.map +0 -1
  107. package/dist/chunk-OX5PLOWB.js.map +0 -1
  108. package/dist/chunk-PJ7UCTX4.mjs +0 -362
  109. package/dist/chunk-PJ7UCTX4.mjs.map +0 -1
  110. package/dist/chunk-PR4QN5HX.js +0 -44
  111. package/dist/chunk-PR4QN5HX.js.map +0 -1
  112. package/dist/chunk-QIBE7GVN.mjs +0 -81
  113. package/dist/chunk-QIBE7GVN.mjs.map +0 -1
  114. package/dist/chunk-QIOC54LQ.mjs +0 -130
  115. package/dist/chunk-QIOC54LQ.mjs.map +0 -1
  116. package/dist/chunk-TQN37HIN.js.map +0 -1
  117. package/dist/chunk-WZDOPUJW.js +0 -361
  118. package/dist/chunk-WZDOPUJW.js.map +0 -1
  119. package/dist/chunk-XJTZDXSR.mjs +0 -94
  120. package/dist/chunk-XJTZDXSR.mjs.map +0 -1
  121. package/dist/chunk-Y364QIQH.js.map +0 -1
  122. package/dist/chunk-YXM6Q4JS.mjs +0 -94
  123. package/dist/chunk-YXM6Q4JS.mjs.map +0 -1
  124. package/dist/chunk-ZDMFMUDR.js.map +0 -1
  125. package/dist/chunk-ZVJ6NQUM.mjs +0 -82
  126. package/dist/chunk-ZVJ6NQUM.mjs.map +0 -1
  127. package/dist/color.js.map +0 -1
  128. package/dist/color.mjs +0 -4
  129. package/dist/color.mjs.map +0 -1
  130. package/dist/crypto.js.map +0 -1
  131. package/dist/crypto.mjs +0 -4
  132. package/dist/crypto.mjs.map +0 -1
  133. package/dist/data-structure.js.map +0 -1
  134. package/dist/data-structure.mjs +0 -4
  135. package/dist/data-structure.mjs.map +0 -1
  136. package/dist/date.js.map +0 -1
  137. package/dist/date.mjs +0 -4
  138. package/dist/date.mjs.map +0 -1
  139. package/dist/dom.js.map +0 -1
  140. package/dist/dom.mjs +0 -4
  141. package/dist/dom.mjs.map +0 -1
  142. package/dist/file.js.map +0 -1
  143. package/dist/file.mjs +0 -4
  144. package/dist/file.mjs.map +0 -1
  145. package/dist/i18n.js.map +0 -1
  146. package/dist/i18n.mjs +0 -4
  147. package/dist/i18n.mjs.map +0 -1
  148. package/dist/index.js.map +0 -1
  149. package/dist/index.mjs +0 -17155
  150. package/dist/index.mjs.map +0 -1
  151. package/dist/network.js.map +0 -1
  152. package/dist/network.mjs +0 -4
  153. package/dist/network.mjs.map +0 -1
  154. package/dist/number.js.map +0 -1
  155. package/dist/number.mjs +0 -4
  156. package/dist/number.mjs.map +0 -1
  157. package/dist/object.js.map +0 -1
  158. package/dist/object.mjs +0 -4
  159. package/dist/object.mjs.map +0 -1
  160. package/dist/performance.js.map +0 -1
  161. package/dist/performance.mjs +0 -4
  162. package/dist/performance.mjs.map +0 -1
  163. package/dist/storage.js.map +0 -1
  164. package/dist/storage.mjs +0 -5
  165. package/dist/storage.mjs.map +0 -1
  166. package/dist/string.js.map +0 -1
  167. package/dist/string.mjs +0 -4
  168. package/dist/string.mjs.map +0 -1
  169. package/dist/tracking.js.map +0 -1
  170. package/dist/tracking.mjs +0 -4
  171. package/dist/tracking.mjs.map +0 -1
  172. package/dist/transform.js.map +0 -1
  173. package/dist/transform.mjs +0 -4
  174. package/dist/transform.mjs.map +0 -1
  175. package/dist/upload.js.map +0 -1
  176. package/dist/upload.mjs +0 -5
  177. package/dist/upload.mjs.map +0 -1
  178. package/dist/url.js.map +0 -1
  179. package/dist/url.mjs +0 -4
  180. package/dist/url.mjs.map +0 -1
  181. package/dist/validation.js.map +0 -1
  182. package/dist/validation.mjs +0 -4
  183. package/dist/validation.mjs.map +0 -1
  184. /package/dist/{upload-DchqyDBQ.d.mts → index-DchqyDBQ.d.mts} +0 -0
  185. /package/dist/{upload-DchqyDBQ.d.ts → index-DchqyDBQ.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // src/browser/dom.ts
3
+ // src/browser/dom/index.ts
4
4
  function $(selector, context = document) {
5
5
  return context.querySelector(selector);
6
6
  }
@@ -96,5 +96,3 @@ exports.removeClass = removeClass;
96
96
  exports.scrollTo = scrollTo;
97
97
  exports.setStyle = setStyle;
98
98
  exports.toggleClass = toggleClass;
99
- //# sourceMappingURL=chunk-JK2SE3I2.js.map
100
- //# sourceMappingURL=chunk-JK2SE3I2.js.map
package/dist/dom.js CHANGED
@@ -1,57 +1,85 @@
1
- 'use strict';
1
+ // src/browser/dom/index.ts
2
+ function $(selector, context = document) {
3
+ return context.querySelector(selector);
4
+ }
5
+ function $$(selector, context = document) {
6
+ return Array.from(context.querySelectorAll(selector));
7
+ }
8
+ function addClass(element, className) {
9
+ element.classList.add(className);
10
+ }
11
+ function removeClass(element, className) {
12
+ element.classList.remove(className);
13
+ }
14
+ function toggleClass(element, className) {
15
+ return element.classList.toggle(className);
16
+ }
17
+ function getStyle(element, property) {
18
+ return window.getComputedStyle(element).getPropertyValue(property);
19
+ }
20
+ function setStyle(element, property, value) {
21
+ if (typeof property === "string" && value !== void 0) {
22
+ element.style.setProperty(property, value);
23
+ } else if (typeof property === "object") {
24
+ Object.keys(property).forEach((key) => {
25
+ element.style.setProperty(key, property[key]);
26
+ });
27
+ }
28
+ }
29
+ function scrollTo(target, options = {}) {
30
+ if (typeof window === "undefined") return;
31
+ const { behavior = "smooth", block = "start", inline = "nearest" } = options;
32
+ if (typeof target === "number") {
33
+ window.scrollTo({ top: target, behavior });
34
+ return;
35
+ }
36
+ const element = typeof target === "string" ? $(target) : target;
37
+ if (element) {
38
+ element.scrollIntoView({ behavior, block, inline });
39
+ }
40
+ }
41
+ function getScrollPosition() {
42
+ if (typeof window === "undefined") return { x: 0, y: 0 };
43
+ return {
44
+ x: window.pageXOffset || document.documentElement.scrollLeft || 0,
45
+ y: window.pageYOffset || document.documentElement.scrollTop || 0
46
+ };
47
+ }
48
+ function isInViewport(element, threshold = 0) {
49
+ if (typeof window === "undefined") return false;
50
+ const rect = element.getBoundingClientRect();
51
+ const windowHeight = window.innerHeight || document.documentElement.clientHeight;
52
+ const windowWidth = window.innerWidth || document.documentElement.clientWidth;
53
+ return rect.top >= -threshold * rect.height && rect.left >= -threshold * rect.width && rect.bottom <= windowHeight + threshold * rect.height && rect.right <= windowWidth + threshold * rect.width;
54
+ }
55
+ function getElementOffset(element) {
56
+ const rect = element.getBoundingClientRect();
57
+ return {
58
+ top: rect.top + (window.pageYOffset || document.documentElement.scrollTop),
59
+ left: rect.left + (window.pageXOffset || document.documentElement.scrollLeft)
60
+ };
61
+ }
62
+ async function copyToClipboard(text) {
63
+ if (typeof navigator === "undefined" || !navigator.clipboard) {
64
+ const textArea = document.createElement("textarea");
65
+ textArea.value = text;
66
+ textArea.style.position = "fixed";
67
+ textArea.style.opacity = "0";
68
+ document.body.appendChild(textArea);
69
+ textArea.select();
70
+ try {
71
+ document.execCommand("copy");
72
+ } catch (error) {
73
+ throw new Error("Failed to copy text");
74
+ }
75
+ document.body.removeChild(textArea);
76
+ return;
77
+ }
78
+ try {
79
+ await navigator.clipboard.writeText(text);
80
+ } catch (error) {
81
+ throw new Error("Failed to copy text");
82
+ }
83
+ }
2
84
 
3
- var chunkJK2SE3I2_js = require('./chunk-JK2SE3I2.js');
4
- require('./chunk-PR4QN5HX.js');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "$", {
9
- enumerable: true,
10
- get: function () { return chunkJK2SE3I2_js.$; }
11
- });
12
- Object.defineProperty(exports, "$$", {
13
- enumerable: true,
14
- get: function () { return chunkJK2SE3I2_js.$$; }
15
- });
16
- Object.defineProperty(exports, "addClass", {
17
- enumerable: true,
18
- get: function () { return chunkJK2SE3I2_js.addClass; }
19
- });
20
- Object.defineProperty(exports, "copyToClipboard", {
21
- enumerable: true,
22
- get: function () { return chunkJK2SE3I2_js.copyToClipboard; }
23
- });
24
- Object.defineProperty(exports, "getElementOffset", {
25
- enumerable: true,
26
- get: function () { return chunkJK2SE3I2_js.getElementOffset; }
27
- });
28
- Object.defineProperty(exports, "getScrollPosition", {
29
- enumerable: true,
30
- get: function () { return chunkJK2SE3I2_js.getScrollPosition; }
31
- });
32
- Object.defineProperty(exports, "getStyle", {
33
- enumerable: true,
34
- get: function () { return chunkJK2SE3I2_js.getStyle; }
35
- });
36
- Object.defineProperty(exports, "isInViewport", {
37
- enumerable: true,
38
- get: function () { return chunkJK2SE3I2_js.isInViewport; }
39
- });
40
- Object.defineProperty(exports, "removeClass", {
41
- enumerable: true,
42
- get: function () { return chunkJK2SE3I2_js.removeClass; }
43
- });
44
- Object.defineProperty(exports, "scrollTo", {
45
- enumerable: true,
46
- get: function () { return chunkJK2SE3I2_js.scrollTo; }
47
- });
48
- Object.defineProperty(exports, "setStyle", {
49
- enumerable: true,
50
- get: function () { return chunkJK2SE3I2_js.setStyle; }
51
- });
52
- Object.defineProperty(exports, "toggleClass", {
53
- enumerable: true,
54
- get: function () { return chunkJK2SE3I2_js.toggleClass; }
55
- });
56
- //# sourceMappingURL=dom.js.map
57
- //# sourceMappingURL=dom.js.map
85
+ export { $, $$, addClass, copyToClipboard, getElementOffset, getScrollPosition, getStyle, isInViewport, removeClass, scrollTo, setStyle, toggleClass };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // src/browser/file.ts
3
+ // src/browser/file/index.ts
4
4
  async function calculateFileMD5(file) {
5
5
  return new Promise((resolve, reject) => {
6
6
  if (typeof FileReader === "undefined") {
@@ -85,5 +85,3 @@ exports.formatFileSize = formatFileSize;
85
85
  exports.getFileExtension = getFileExtension;
86
86
  exports.getFileNameWithoutExtension = getFileNameWithoutExtension;
87
87
  exports.splitFileIntoChunks = splitFileIntoChunks;
88
- //# sourceMappingURL=chunk-7V5UQXIO.js.map
89
- //# sourceMappingURL=chunk-7V5UQXIO.js.map
package/dist/file.js CHANGED
@@ -1,33 +1,80 @@
1
- 'use strict';
1
+ // src/browser/file/index.ts
2
+ async function calculateFileMD5(file) {
3
+ return new Promise((resolve, reject) => {
4
+ if (typeof FileReader === "undefined") {
5
+ reject(new Error("FileReader is not supported in this environment"));
6
+ return;
7
+ }
8
+ const reader = new FileReader();
9
+ reader.onload = async (e) => {
10
+ try {
11
+ const arrayBuffer = e.target?.result;
12
+ if (!arrayBuffer) {
13
+ reject(new Error("Failed to read file"));
14
+ return;
15
+ }
16
+ const hashBuffer = await crypto.subtle.digest("SHA-256", arrayBuffer);
17
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
18
+ const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
19
+ resolve(hashHex);
20
+ } catch (error) {
21
+ reject(error);
22
+ }
23
+ };
24
+ reader.onerror = reject;
25
+ reader.readAsArrayBuffer(file);
26
+ });
27
+ }
28
+ async function calculateBlobMD5(blob) {
29
+ return new Promise((resolve, reject) => {
30
+ if (typeof FileReader === "undefined") {
31
+ reject(new Error("FileReader is not supported in this environment"));
32
+ return;
33
+ }
34
+ const reader = new FileReader();
35
+ reader.onload = async (e) => {
36
+ try {
37
+ const arrayBuffer = e.target?.result;
38
+ if (!arrayBuffer) {
39
+ reject(new Error("Failed to read blob"));
40
+ return;
41
+ }
42
+ const hashBuffer = await crypto.subtle.digest("SHA-256", arrayBuffer);
43
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
44
+ const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
45
+ resolve(hashHex);
46
+ } catch (error) {
47
+ reject(error);
48
+ }
49
+ };
50
+ reader.onerror = reject;
51
+ reader.readAsArrayBuffer(blob);
52
+ });
53
+ }
54
+ function splitFileIntoChunks(file, chunkSize) {
55
+ const chunks = [];
56
+ let start = 0;
57
+ while (start < file.size) {
58
+ const end = Math.min(start + chunkSize, file.size);
59
+ chunks.push(file.slice(start, end));
60
+ start = end;
61
+ }
62
+ return chunks;
63
+ }
64
+ function formatFileSize(bytes) {
65
+ if (bytes === 0) return "0 B";
66
+ const k = 1024;
67
+ const sizes = ["B", "KB", "MB", "GB", "TB"];
68
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
69
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
70
+ }
71
+ function getFileExtension(fileName) {
72
+ const lastDot = fileName.lastIndexOf(".");
73
+ return lastDot > 0 ? fileName.slice(lastDot + 1) : "";
74
+ }
75
+ function getFileNameWithoutExtension(fileName) {
76
+ const lastDot = fileName.lastIndexOf(".");
77
+ return lastDot > 0 ? fileName.slice(0, lastDot) : fileName;
78
+ }
2
79
 
3
- var chunk7V5UQXIO_js = require('./chunk-7V5UQXIO.js');
4
- require('./chunk-PR4QN5HX.js');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "calculateBlobMD5", {
9
- enumerable: true,
10
- get: function () { return chunk7V5UQXIO_js.calculateBlobMD5; }
11
- });
12
- Object.defineProperty(exports, "calculateFileMD5", {
13
- enumerable: true,
14
- get: function () { return chunk7V5UQXIO_js.calculateFileMD5; }
15
- });
16
- Object.defineProperty(exports, "formatFileSize", {
17
- enumerable: true,
18
- get: function () { return chunk7V5UQXIO_js.formatFileSize; }
19
- });
20
- Object.defineProperty(exports, "getFileExtension", {
21
- enumerable: true,
22
- get: function () { return chunk7V5UQXIO_js.getFileExtension; }
23
- });
24
- Object.defineProperty(exports, "getFileNameWithoutExtension", {
25
- enumerable: true,
26
- get: function () { return chunk7V5UQXIO_js.getFileNameWithoutExtension; }
27
- });
28
- Object.defineProperty(exports, "splitFileIntoChunks", {
29
- enumerable: true,
30
- get: function () { return chunk7V5UQXIO_js.splitFileIntoChunks; }
31
- });
32
- //# sourceMappingURL=file.js.map
33
- //# sourceMappingURL=file.js.map
80
+ export { calculateBlobMD5, calculateFileMD5, formatFileSize, getFileExtension, getFileNameWithoutExtension, splitFileIntoChunks };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // src/format/i18n.ts
3
+ // src/format/i18n/index.ts
4
4
  function getLocale() {
5
5
  if (typeof navigator !== "undefined" && navigator.language) {
6
6
  return navigator.language;
@@ -86,5 +86,3 @@ exports.formatRelativeTime = formatRelativeTime;
86
86
  exports.getLocale = getLocale;
87
87
  exports.pluralize = pluralize;
88
88
  exports.translate = translate;
89
- //# sourceMappingURL=chunk-OX5PLOWB.js.map
90
- //# sourceMappingURL=chunk-OX5PLOWB.js.map
package/dist/i18n.js CHANGED
@@ -1,41 +1,79 @@
1
- 'use strict';
1
+ // src/format/i18n/index.ts
2
+ function getLocale() {
3
+ if (typeof navigator !== "undefined" && navigator.language) {
4
+ return navigator.language;
5
+ }
6
+ return "en-US";
7
+ }
8
+ function formatNumberI18n(value, locale, options) {
9
+ const loc = locale || getLocale();
10
+ return new Intl.NumberFormat(loc, options).format(value);
11
+ }
12
+ function formatDateI18n(date, locale, options) {
13
+ const loc = locale || getLocale();
14
+ const dateObj = typeof date === "number" ? new Date(date) : date;
15
+ return new Intl.DateTimeFormat(loc, options).format(dateObj);
16
+ }
17
+ function formatCurrencyI18n(value, currency, locale, options) {
18
+ const loc = locale || getLocale();
19
+ return new Intl.NumberFormat(loc, {
20
+ style: "currency",
21
+ currency,
22
+ ...options
23
+ }).format(value);
24
+ }
25
+ function translate(key, dictionary, defaultValue) {
26
+ const keys = key.split(".");
27
+ let current = dictionary;
28
+ for (const k of keys) {
29
+ if (typeof current === "object" && current !== null && k in current) {
30
+ current = current[k];
31
+ } else {
32
+ return defaultValue || key;
33
+ }
34
+ }
35
+ if (typeof current === "string") {
36
+ return current;
37
+ }
38
+ return defaultValue || key;
39
+ }
40
+ function createTranslator(dictionary) {
41
+ return (key, defaultValue) => {
42
+ return translate(key, dictionary, defaultValue);
43
+ };
44
+ }
45
+ function formatRelativeTime(date, locale) {
46
+ const loc = locale || getLocale();
47
+ const dateObj = typeof date === "number" ? new Date(date) : date;
48
+ const now = /* @__PURE__ */ new Date();
49
+ const diffInSeconds = Math.floor((now.getTime() - dateObj.getTime()) / 1e3);
50
+ const rtf = new Intl.RelativeTimeFormat(loc, { numeric: "auto" });
51
+ const intervals = [
52
+ { unit: "year", seconds: 31536e3 },
53
+ { unit: "month", seconds: 2592e3 },
54
+ { unit: "week", seconds: 604800 },
55
+ { unit: "day", seconds: 86400 },
56
+ { unit: "hour", seconds: 3600 },
57
+ { unit: "minute", seconds: 60 },
58
+ { unit: "second", seconds: 1 }
59
+ ];
60
+ for (const interval of intervals) {
61
+ const count = Math.floor(Math.abs(diffInSeconds) / interval.seconds);
62
+ if (count >= 1) {
63
+ return rtf.format(diffInSeconds < 0 ? count : -count, interval.unit);
64
+ }
65
+ }
66
+ return rtf.format(0, "second");
67
+ }
68
+ function pluralize(count, singular, plural, locale) {
69
+ const loc = locale || getLocale();
70
+ const pluralForm = plural || `${singular}s`;
71
+ const pluralRules = new Intl.PluralRules(loc);
72
+ const rule = pluralRules.select(count);
73
+ if (rule === "one" || count === 1) {
74
+ return `${count} ${singular}`;
75
+ }
76
+ return `${count} ${pluralForm}`;
77
+ }
2
78
 
3
- var chunkOX5PLOWB_js = require('./chunk-OX5PLOWB.js');
4
- require('./chunk-PR4QN5HX.js');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "createTranslator", {
9
- enumerable: true,
10
- get: function () { return chunkOX5PLOWB_js.createTranslator; }
11
- });
12
- Object.defineProperty(exports, "formatCurrencyI18n", {
13
- enumerable: true,
14
- get: function () { return chunkOX5PLOWB_js.formatCurrencyI18n; }
15
- });
16
- Object.defineProperty(exports, "formatDateI18n", {
17
- enumerable: true,
18
- get: function () { return chunkOX5PLOWB_js.formatDateI18n; }
19
- });
20
- Object.defineProperty(exports, "formatNumberI18n", {
21
- enumerable: true,
22
- get: function () { return chunkOX5PLOWB_js.formatNumberI18n; }
23
- });
24
- Object.defineProperty(exports, "formatRelativeTime", {
25
- enumerable: true,
26
- get: function () { return chunkOX5PLOWB_js.formatRelativeTime; }
27
- });
28
- Object.defineProperty(exports, "getLocale", {
29
- enumerable: true,
30
- get: function () { return chunkOX5PLOWB_js.getLocale; }
31
- });
32
- Object.defineProperty(exports, "pluralize", {
33
- enumerable: true,
34
- get: function () { return chunkOX5PLOWB_js.pluralize; }
35
- });
36
- Object.defineProperty(exports, "translate", {
37
- enumerable: true,
38
- get: function () { return chunkOX5PLOWB_js.translate; }
39
- });
40
- //# sourceMappingURL=i18n.js.map
41
- //# sourceMappingURL=i18n.js.map
79
+ export { createTranslator, formatCurrencyI18n, formatDateI18n, formatNumberI18n, formatRelativeTime, getLocale, pluralize, translate };