@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/data/algorithm.ts
3
+ // src/data/algorithm/index.ts
4
4
  function binarySearch(array, target, compareFn) {
5
5
  let left = 0;
6
6
  let right = array.length - 1;
@@ -139,5 +139,3 @@ exports.gcd = gcd;
139
139
  exports.lcm = lcm;
140
140
  exports.mergeSort = mergeSort;
141
141
  exports.quickSort = quickSort;
142
- //# sourceMappingURL=chunk-O3O67R4I.js.map
143
- //# sourceMappingURL=chunk-O3O67R4I.js.map
package/dist/algorithm.js CHANGED
@@ -1,45 +1,131 @@
1
- 'use strict';
1
+ // src/data/algorithm/index.ts
2
+ function binarySearch(array, target, compareFn) {
3
+ let left = 0;
4
+ let right = array.length - 1;
5
+ const compare = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
6
+ while (left <= right) {
7
+ const mid = Math.floor((left + right) / 2);
8
+ const comparison = compare(array[mid], target);
9
+ if (comparison === 0) {
10
+ return mid;
11
+ } else if (comparison < 0) {
12
+ left = mid + 1;
13
+ } else {
14
+ right = mid - 1;
15
+ }
16
+ }
17
+ return -1;
18
+ }
19
+ function quickSort(array, compareFn) {
20
+ if (array.length <= 1) {
21
+ return [...array];
22
+ }
23
+ const compare = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
24
+ const pivot = array[Math.floor(array.length / 2)];
25
+ const left = [];
26
+ const right = [];
27
+ const equal = [];
28
+ for (const item of array) {
29
+ const comparison = compare(item, pivot);
30
+ if (comparison < 0) {
31
+ left.push(item);
32
+ } else if (comparison > 0) {
33
+ right.push(item);
34
+ } else {
35
+ equal.push(item);
36
+ }
37
+ }
38
+ return [...quickSort(left, compareFn), ...equal, ...quickSort(right, compareFn)];
39
+ }
40
+ function mergeSort(array, compareFn) {
41
+ if (array.length <= 1) {
42
+ return [...array];
43
+ }
44
+ const compare = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
45
+ const mid = Math.floor(array.length / 2);
46
+ const left = mergeSort(array.slice(0, mid), compareFn);
47
+ const right = mergeSort(array.slice(mid), compareFn);
48
+ return merge(left, right, compare);
49
+ }
50
+ function merge(left, right, compareFn) {
51
+ const result = [];
52
+ let i = 0;
53
+ let j = 0;
54
+ while (i < left.length && j < right.length) {
55
+ if (compareFn(left[i], right[j]) <= 0) {
56
+ result.push(left[i]);
57
+ i++;
58
+ } else {
59
+ result.push(right[j]);
60
+ j++;
61
+ }
62
+ }
63
+ return result.concat(left.slice(i)).concat(right.slice(j));
64
+ }
65
+ function bubbleSort(array, compareFn) {
66
+ const result = [...array];
67
+ const compare = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
68
+ const n = result.length;
69
+ for (let i = 0; i < n - 1; i++) {
70
+ let swapped = false;
71
+ for (let j = 0; j < n - i - 1; j++) {
72
+ if (compare(result[j], result[j + 1]) > 0) {
73
+ [result[j], result[j + 1]] = [result[j + 1], result[j]];
74
+ swapped = true;
75
+ }
76
+ }
77
+ if (!swapped) {
78
+ break;
79
+ }
80
+ }
81
+ return result;
82
+ }
83
+ function fibonacci(n) {
84
+ if (n < 0) {
85
+ throw new Error("n must be non-negative");
86
+ }
87
+ if (n === 0) return 0;
88
+ if (n === 1) return 1;
89
+ let a = 0;
90
+ let b = 1;
91
+ for (let i = 2; i <= n; i++) {
92
+ [a, b] = [b, a + b];
93
+ }
94
+ return b;
95
+ }
96
+ function fibonacciSequence(n) {
97
+ if (n <= 0) return [];
98
+ if (n === 1) return [0];
99
+ if (n === 2) return [0, 1];
100
+ const sequence = [0, 1];
101
+ for (let i = 2; i < n; i++) {
102
+ sequence.push(sequence[i - 1] + sequence[i - 2]);
103
+ }
104
+ return sequence;
105
+ }
106
+ function factorial(n) {
107
+ if (n < 0) {
108
+ throw new Error("n must be non-negative");
109
+ }
110
+ if (n === 0 || n === 1) {
111
+ return 1;
112
+ }
113
+ let result = 1;
114
+ for (let i = 2; i <= n; i++) {
115
+ result *= i;
116
+ }
117
+ return result;
118
+ }
119
+ function gcd(a, b) {
120
+ a = Math.abs(a);
121
+ b = Math.abs(b);
122
+ while (b !== 0) {
123
+ [a, b] = [b, a % b];
124
+ }
125
+ return a;
126
+ }
127
+ function lcm(a, b) {
128
+ return Math.abs(a * b) / gcd(a, b);
129
+ }
2
130
 
3
- var chunkO3O67R4I_js = require('./chunk-O3O67R4I.js');
4
- require('./chunk-PR4QN5HX.js');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "binarySearch", {
9
- enumerable: true,
10
- get: function () { return chunkO3O67R4I_js.binarySearch; }
11
- });
12
- Object.defineProperty(exports, "bubbleSort", {
13
- enumerable: true,
14
- get: function () { return chunkO3O67R4I_js.bubbleSort; }
15
- });
16
- Object.defineProperty(exports, "factorial", {
17
- enumerable: true,
18
- get: function () { return chunkO3O67R4I_js.factorial; }
19
- });
20
- Object.defineProperty(exports, "fibonacci", {
21
- enumerable: true,
22
- get: function () { return chunkO3O67R4I_js.fibonacci; }
23
- });
24
- Object.defineProperty(exports, "fibonacciSequence", {
25
- enumerable: true,
26
- get: function () { return chunkO3O67R4I_js.fibonacciSequence; }
27
- });
28
- Object.defineProperty(exports, "gcd", {
29
- enumerable: true,
30
- get: function () { return chunkO3O67R4I_js.gcd; }
31
- });
32
- Object.defineProperty(exports, "lcm", {
33
- enumerable: true,
34
- get: function () { return chunkO3O67R4I_js.lcm; }
35
- });
36
- Object.defineProperty(exports, "mergeSort", {
37
- enumerable: true,
38
- get: function () { return chunkO3O67R4I_js.mergeSort; }
39
- });
40
- Object.defineProperty(exports, "quickSort", {
41
- enumerable: true,
42
- get: function () { return chunkO3O67R4I_js.quickSort; }
43
- });
44
- //# sourceMappingURL=algorithm.js.map
45
- //# sourceMappingURL=algorithm.js.map
131
+ export { binarySearch, bubbleSort, factorial, fibonacci, fibonacciSequence, gcd, lcm, mergeSort, quickSort };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // src/core/array.ts
3
+ // src/core/array/index.ts
4
4
  function unique(arr) {
5
5
  return Array.from(new Set(arr));
6
6
  }
@@ -154,5 +154,3 @@ exports.union = union;
154
154
  exports.unique = unique;
155
155
  exports.unzip = unzip;
156
156
  exports.zip = zip;
157
- //# sourceMappingURL=chunk-LOAZSPGQ.js.map
158
- //# sourceMappingURL=chunk-LOAZSPGQ.js.map
package/dist/array.js CHANGED
@@ -1,85 +1,136 @@
1
- 'use strict';
1
+ // src/core/array/index.ts
2
+ function unique(arr) {
3
+ return Array.from(new Set(arr));
4
+ }
5
+ function groupBy(arr, keyFn) {
6
+ const getKey = typeof keyFn === "string" ? (item) => item[keyFn] : keyFn;
7
+ return arr.reduce(
8
+ (acc, item) => {
9
+ const key = getKey(item);
10
+ if (!acc[key]) {
11
+ acc[key] = [];
12
+ }
13
+ acc[key].push(item);
14
+ return acc;
15
+ },
16
+ {}
17
+ );
18
+ }
19
+ function chunk(arr, size) {
20
+ const chunks = [];
21
+ for (let i = 0; i < arr.length; i += size) {
22
+ chunks.push(arr.slice(i, i + size));
23
+ }
24
+ return chunks;
25
+ }
26
+ function flatten(arr, depth = 1) {
27
+ return depth > 0 ? arr.reduce(
28
+ (acc, val) => acc.concat(Array.isArray(val) ? flatten(val, depth - 1) : val),
29
+ []
30
+ ) : arr;
31
+ }
32
+ function shuffle(arr) {
33
+ const result = [...arr];
34
+ for (let i = result.length - 1; i > 0; i--) {
35
+ const j = Math.floor(Math.random() * (i + 1));
36
+ [result[i], result[j]] = [result[j], result[i]];
37
+ }
38
+ return result;
39
+ }
40
+ function sample(arr, count = 1) {
41
+ if (arr.length === 0) {
42
+ throw new Error("Cannot sample from empty array");
43
+ }
44
+ if (count === 1) {
45
+ const shuffled2 = shuffle(arr);
46
+ return shuffled2[0];
47
+ }
48
+ if (count >= arr.length) return [...arr];
49
+ const shuffled = shuffle(arr);
50
+ return shuffled.slice(0, count);
51
+ }
52
+ function difference(arr1, arr2) {
53
+ const set2 = new Set(arr2);
54
+ return arr1.filter((item) => !set2.has(item));
55
+ }
56
+ function intersection(arr1, arr2) {
57
+ const set2 = new Set(arr2);
58
+ return arr1.filter((item) => set2.has(item));
59
+ }
60
+ function union(arr1, arr2) {
61
+ return unique([...arr1, ...arr2]);
62
+ }
63
+ function sortBy(arr, keyFn, order = "asc") {
64
+ const getKey = typeof keyFn === "string" ? (item) => item[keyFn] : keyFn;
65
+ const result = [...arr];
66
+ result.sort((a, b) => {
67
+ const keyA = getKey(a);
68
+ const keyB = getKey(b);
69
+ if (keyA < keyB) return order === "asc" ? -1 : 1;
70
+ if (keyA > keyB) return order === "asc" ? 1 : -1;
71
+ return 0;
72
+ });
73
+ return result;
74
+ }
75
+ function findIndexBy(arr, predicate) {
76
+ return arr.findIndex(predicate);
77
+ }
78
+ function partition(arr, predicate) {
79
+ const truthy = [];
80
+ const falsy = [];
81
+ arr.forEach((item) => {
82
+ if (predicate(item)) {
83
+ truthy.push(item);
84
+ } else {
85
+ falsy.push(item);
86
+ }
87
+ });
88
+ return [truthy, falsy];
89
+ }
90
+ function zip(...arrays) {
91
+ const maxLength = Math.max(...arrays.map((arr) => arr.length));
92
+ const result = [];
93
+ for (let i = 0; i < maxLength; i++) {
94
+ result.push(
95
+ arrays.map((arr) => arr[i])
96
+ );
97
+ }
98
+ return result;
99
+ }
100
+ function unzip(array) {
101
+ if (array.length === 0) return [];
102
+ const length = array[0].length;
103
+ const result = Array.from({ length }, () => []);
104
+ array.forEach((item) => {
105
+ item.forEach((val, index) => {
106
+ result[index].push(val);
107
+ });
108
+ });
109
+ return result;
110
+ }
111
+ function compact(arr) {
112
+ return arr.filter((item) => Boolean(item));
113
+ }
114
+ function take(arr, n) {
115
+ return arr.slice(0, n);
116
+ }
117
+ function drop(arr, n) {
118
+ return arr.slice(n);
119
+ }
120
+ function takeWhile(arr, predicate) {
121
+ const result = [];
122
+ for (const item of arr) {
123
+ if (!predicate(item)) break;
124
+ result.push(item);
125
+ }
126
+ return result;
127
+ }
128
+ function dropWhile(arr, predicate) {
129
+ let index = 0;
130
+ while (index < arr.length && predicate(arr[index])) {
131
+ index++;
132
+ }
133
+ return arr.slice(index);
134
+ }
2
135
 
3
- var chunkLOAZSPGQ_js = require('./chunk-LOAZSPGQ.js');
4
- require('./chunk-PR4QN5HX.js');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "chunk", {
9
- enumerable: true,
10
- get: function () { return chunkLOAZSPGQ_js.chunk; }
11
- });
12
- Object.defineProperty(exports, "compact", {
13
- enumerable: true,
14
- get: function () { return chunkLOAZSPGQ_js.compact; }
15
- });
16
- Object.defineProperty(exports, "difference", {
17
- enumerable: true,
18
- get: function () { return chunkLOAZSPGQ_js.difference; }
19
- });
20
- Object.defineProperty(exports, "drop", {
21
- enumerable: true,
22
- get: function () { return chunkLOAZSPGQ_js.drop; }
23
- });
24
- Object.defineProperty(exports, "dropWhile", {
25
- enumerable: true,
26
- get: function () { return chunkLOAZSPGQ_js.dropWhile; }
27
- });
28
- Object.defineProperty(exports, "findIndexBy", {
29
- enumerable: true,
30
- get: function () { return chunkLOAZSPGQ_js.findIndexBy; }
31
- });
32
- Object.defineProperty(exports, "flatten", {
33
- enumerable: true,
34
- get: function () { return chunkLOAZSPGQ_js.flatten; }
35
- });
36
- Object.defineProperty(exports, "groupBy", {
37
- enumerable: true,
38
- get: function () { return chunkLOAZSPGQ_js.groupBy; }
39
- });
40
- Object.defineProperty(exports, "intersection", {
41
- enumerable: true,
42
- get: function () { return chunkLOAZSPGQ_js.intersection; }
43
- });
44
- Object.defineProperty(exports, "partition", {
45
- enumerable: true,
46
- get: function () { return chunkLOAZSPGQ_js.partition; }
47
- });
48
- Object.defineProperty(exports, "sample", {
49
- enumerable: true,
50
- get: function () { return chunkLOAZSPGQ_js.sample; }
51
- });
52
- Object.defineProperty(exports, "shuffle", {
53
- enumerable: true,
54
- get: function () { return chunkLOAZSPGQ_js.shuffle; }
55
- });
56
- Object.defineProperty(exports, "sortBy", {
57
- enumerable: true,
58
- get: function () { return chunkLOAZSPGQ_js.sortBy; }
59
- });
60
- Object.defineProperty(exports, "take", {
61
- enumerable: true,
62
- get: function () { return chunkLOAZSPGQ_js.take; }
63
- });
64
- Object.defineProperty(exports, "takeWhile", {
65
- enumerable: true,
66
- get: function () { return chunkLOAZSPGQ_js.takeWhile; }
67
- });
68
- Object.defineProperty(exports, "union", {
69
- enumerable: true,
70
- get: function () { return chunkLOAZSPGQ_js.union; }
71
- });
72
- Object.defineProperty(exports, "unique", {
73
- enumerable: true,
74
- get: function () { return chunkLOAZSPGQ_js.unique; }
75
- });
76
- Object.defineProperty(exports, "unzip", {
77
- enumerable: true,
78
- get: function () { return chunkLOAZSPGQ_js.unzip; }
79
- });
80
- Object.defineProperty(exports, "zip", {
81
- enumerable: true,
82
- get: function () { return chunkLOAZSPGQ_js.zip; }
83
- });
84
- //# sourceMappingURL=array.js.map
85
- //# sourceMappingURL=array.js.map
136
+ export { chunk, compact, difference, drop, dropWhile, findIndexBy, flatten, groupBy, intersection, partition, sample, shuffle, sortBy, take, takeWhile, union, unique, unzip, zip };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // src/format/color.ts
3
+ // src/format/color/index.ts
4
4
  function hexToRgb(hex) {
5
5
  const cleanHex = hex.replace("#", "");
6
6
  if (!/^[0-9A-Fa-f]{6}$/.test(cleanHex)) {
@@ -135,5 +135,3 @@ exports.lighten = lighten;
135
135
  exports.mix = mix;
136
136
  exports.rgbToHex = rgbToHex;
137
137
  exports.rgbToHsl = rgbToHsl;
138
- //# sourceMappingURL=chunk-Y364QIQH.js.map
139
- //# sourceMappingURL=chunk-Y364QIQH.js.map
package/dist/color.js CHANGED
@@ -1,41 +1,128 @@
1
- 'use strict';
1
+ // src/format/color/index.ts
2
+ function hexToRgb(hex) {
3
+ const cleanHex = hex.replace("#", "");
4
+ if (!/^[0-9A-Fa-f]{6}$/.test(cleanHex)) {
5
+ throw new Error("Invalid hex color format");
6
+ }
7
+ return {
8
+ r: parseInt(cleanHex.substring(0, 2), 16),
9
+ g: parseInt(cleanHex.substring(2, 4), 16),
10
+ b: parseInt(cleanHex.substring(4, 6), 16)
11
+ };
12
+ }
13
+ function rgbToHex(rgb) {
14
+ let r;
15
+ let g;
16
+ let b;
17
+ if (typeof rgb === "string") {
18
+ const match = rgb.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
19
+ if (!match) {
20
+ throw new Error("Invalid RGB string format");
21
+ }
22
+ r = parseInt(match[1], 10);
23
+ g = parseInt(match[2], 10);
24
+ b = parseInt(match[3], 10);
25
+ } else {
26
+ r = rgb.r;
27
+ g = rgb.g;
28
+ b = rgb.b;
29
+ }
30
+ r = Math.max(0, Math.min(255, Math.round(r)));
31
+ g = Math.max(0, Math.min(255, Math.round(g)));
32
+ b = Math.max(0, Math.min(255, Math.round(b)));
33
+ return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`.toUpperCase();
34
+ }
35
+ function rgbToHsl(rgb) {
36
+ const r = rgb.r / 255;
37
+ const g = rgb.g / 255;
38
+ const b = rgb.b / 255;
39
+ const max = Math.max(r, g, b);
40
+ const min = Math.min(r, g, b);
41
+ const delta = max - min;
42
+ let h = 0;
43
+ let s = 0;
44
+ const l = (max + min) / 2;
45
+ if (delta !== 0) {
46
+ s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min);
47
+ if (max === r) {
48
+ h = ((g - b) / delta + (g < b ? 6 : 0)) / 6;
49
+ } else if (max === g) {
50
+ h = ((b - r) / delta + 2) / 6;
51
+ } else {
52
+ h = ((r - g) / delta + 4) / 6;
53
+ }
54
+ }
55
+ return {
56
+ h: Math.round(h * 360),
57
+ s: Math.round(s * 100),
58
+ l: Math.round(l * 100)
59
+ };
60
+ }
61
+ function hslToRgb(hsl) {
62
+ const h = hsl.h / 360;
63
+ const s = hsl.s / 100;
64
+ const l = hsl.l / 100;
65
+ let r;
66
+ let g;
67
+ let b;
68
+ if (s === 0) {
69
+ r = g = b = l;
70
+ } else {
71
+ const hue2rgb = (p2, q2, t) => {
72
+ if (t < 0) t += 1;
73
+ if (t > 1) t -= 1;
74
+ if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
75
+ if (t < 1 / 2) return q2;
76
+ if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
77
+ return p2;
78
+ };
79
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
80
+ const p = 2 * l - q;
81
+ r = hue2rgb(p, q, h + 1 / 3);
82
+ g = hue2rgb(p, q, h);
83
+ b = hue2rgb(p, q, h - 1 / 3);
84
+ }
85
+ return {
86
+ r: Math.round(r * 255),
87
+ g: Math.round(g * 255),
88
+ b: Math.round(b * 255)
89
+ };
90
+ }
91
+ function lighten(color, amount) {
92
+ const rgb = typeof color === "string" ? hexToRgb(color) : color;
93
+ const hsl = rgbToHsl(rgb);
94
+ hsl.l = Math.min(100, hsl.l + amount);
95
+ return rgbToHex(hslToRgb(hsl));
96
+ }
97
+ function darken(color, amount) {
98
+ const rgb = typeof color === "string" ? hexToRgb(color) : color;
99
+ const hsl = rgbToHsl(rgb);
100
+ hsl.l = Math.max(0, hsl.l - amount);
101
+ return rgbToHex(hslToRgb(hsl));
102
+ }
103
+ function mix(color1, color2, ratio) {
104
+ const rgb1 = hexToRgb(color1);
105
+ const rgb2 = hexToRgb(color2);
106
+ const r = Math.round(rgb1.r * (1 - ratio) + rgb2.r * ratio);
107
+ const g = Math.round(rgb1.g * (1 - ratio) + rgb2.g * ratio);
108
+ const b = Math.round(rgb1.b * (1 - ratio) + rgb2.b * ratio);
109
+ return rgbToHex({ r, g, b });
110
+ }
111
+ function contrast(color1, color2) {
112
+ const rgb1 = hexToRgb(color1);
113
+ const rgb2 = hexToRgb(color2);
114
+ const getLuminance = (rgb) => {
115
+ const normalize = (value) => {
116
+ value = value / 255;
117
+ return value <= 0.03928 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
118
+ };
119
+ return 0.2126 * normalize(rgb.r) + 0.7152 * normalize(rgb.g) + 0.0722 * normalize(rgb.b);
120
+ };
121
+ const lum1 = getLuminance(rgb1);
122
+ const lum2 = getLuminance(rgb2);
123
+ const lighter = Math.max(lum1, lum2);
124
+ const darker = Math.min(lum1, lum2);
125
+ return (lighter + 0.05) / (darker + 0.05);
126
+ }
2
127
 
3
- var chunkY364QIQH_js = require('./chunk-Y364QIQH.js');
4
- require('./chunk-PR4QN5HX.js');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "contrast", {
9
- enumerable: true,
10
- get: function () { return chunkY364QIQH_js.contrast; }
11
- });
12
- Object.defineProperty(exports, "darken", {
13
- enumerable: true,
14
- get: function () { return chunkY364QIQH_js.darken; }
15
- });
16
- Object.defineProperty(exports, "hexToRgb", {
17
- enumerable: true,
18
- get: function () { return chunkY364QIQH_js.hexToRgb; }
19
- });
20
- Object.defineProperty(exports, "hslToRgb", {
21
- enumerable: true,
22
- get: function () { return chunkY364QIQH_js.hslToRgb; }
23
- });
24
- Object.defineProperty(exports, "lighten", {
25
- enumerable: true,
26
- get: function () { return chunkY364QIQH_js.lighten; }
27
- });
28
- Object.defineProperty(exports, "mix", {
29
- enumerable: true,
30
- get: function () { return chunkY364QIQH_js.mix; }
31
- });
32
- Object.defineProperty(exports, "rgbToHex", {
33
- enumerable: true,
34
- get: function () { return chunkY364QIQH_js.rgbToHex; }
35
- });
36
- Object.defineProperty(exports, "rgbToHsl", {
37
- enumerable: true,
38
- get: function () { return chunkY364QIQH_js.rgbToHsl; }
39
- });
40
- //# sourceMappingURL=color.js.map
41
- //# sourceMappingURL=color.js.map
128
+ export { contrast, darken, hexToRgb, hslToRgb, lighten, mix, rgbToHex, rgbToHsl };