@splendidlabz/utils 1.10.2 → 1.10.4

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 (209) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/dom/accessibility.cjs +0 -2
  3. package/dist/cjs/dom/actions/index.cjs +7 -391
  4. package/dist/cjs/dom/actions/masonry.cjs +6 -97
  5. package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +14 -58
  6. package/dist/cjs/dom/actions/sticky.cjs +6 -126
  7. package/dist/cjs/dom/bounding-box.cjs +0 -2
  8. package/dist/cjs/dom/clipboard.cjs +0 -2
  9. package/dist/cjs/dom/cookie.cjs +1 -3
  10. package/dist/cjs/dom/css-vars.cjs +3 -13
  11. package/dist/cjs/dom/events.cjs +0 -2
  12. package/dist/cjs/dom/focusable.cjs +0 -2
  13. package/dist/cjs/dom/font-size.cjs +3 -15
  14. package/dist/cjs/dom/get-element.cjs +1 -3
  15. package/dist/cjs/dom/hash.cjs +0 -2
  16. package/dist/cjs/dom/index.cjs +47 -1248
  17. package/dist/cjs/dom/keyboard.cjs +0 -2
  18. package/dist/cjs/dom/local-store.cjs +1 -3
  19. package/dist/cjs/dom/media.cjs +0 -2
  20. package/dist/cjs/dom/observers/index.cjs +9 -235
  21. package/dist/cjs/dom/observers/intersection-observer.cjs +6 -38
  22. package/dist/cjs/dom/observers/mutation-observer.cjs +6 -38
  23. package/dist/cjs/dom/observers/observer.cjs +2 -12
  24. package/dist/cjs/dom/observers/resize-observer.cjs +6 -38
  25. package/dist/cjs/dom/observers/scroll-observer.cjs +3 -62
  26. package/dist/cjs/dom/pkce.cjs +3 -13
  27. package/dist/cjs/dom/query-params.cjs +1 -3
  28. package/dist/cjs/dom/random-string.cjs +0 -2
  29. package/dist/cjs/dom/sanitize.cjs +3 -27
  30. package/dist/cjs/dom/session-store.cjs +1 -3
  31. package/dist/cjs/dom/spam-prevention.cjs +0 -2
  32. package/dist/cjs/dom/trap-focus.cjs +9 -131
  33. package/dist/cjs/dom/ui/aria-current.cjs +0 -2
  34. package/dist/cjs/dom/ui/inconsistent-button-fix.cjs +0 -2
  35. package/dist/cjs/dom/ui/index.cjs +9 -87
  36. package/dist/cjs/dom/ui/scroll-container.cjs +0 -2
  37. package/dist/cjs/dom/ui/traverse-and-scramble.cjs +0 -2
  38. package/dist/cjs/lib/arrays/index.cjs +13 -121
  39. package/dist/cjs/lib/arrays/item-position.cjs +0 -2
  40. package/dist/cjs/lib/arrays/join.cjs +2 -10
  41. package/dist/cjs/lib/arrays/shuffle.cjs +0 -2
  42. package/dist/cjs/lib/arrays/sort.cjs +3 -11
  43. package/dist/cjs/lib/arrays/split-array.cjs +0 -2
  44. package/dist/cjs/lib/arrays/unique.cjs +0 -2
  45. package/dist/cjs/lib/auth/index.cjs +3 -35
  46. package/dist/cjs/lib/auth/route-manager.cjs +0 -2
  47. package/dist/cjs/lib/checks.cjs +0 -2
  48. package/dist/cjs/lib/date/days.cjs +1 -3
  49. package/dist/cjs/lib/date/index.cjs +7 -190
  50. package/dist/cjs/lib/date/months.cjs +1 -3
  51. package/dist/cjs/lib/date/time.cjs +2 -14
  52. package/dist/cjs/lib/form/form-data.cjs +0 -2
  53. package/dist/cjs/lib/form/index.cjs +5 -104
  54. package/dist/cjs/lib/form/sanitize.cjs +0 -2
  55. package/dist/cjs/lib/functions/callback.cjs +0 -2
  56. package/dist/cjs/lib/functions/debounce.cjs +0 -2
  57. package/dist/cjs/lib/functions/env.cjs +0 -2
  58. package/dist/cjs/lib/functions/functional.cjs +0 -2
  59. package/dist/cjs/lib/functions/index.cjs +11 -124
  60. package/dist/cjs/lib/functions/throttle.cjs +0 -2
  61. package/dist/cjs/lib/functions/timeout.cjs +0 -2
  62. package/dist/cjs/lib/hash.cjs +0 -2
  63. package/dist/cjs/lib/index.cjs +29 -1155
  64. package/dist/cjs/lib/numbers/index.cjs +4 -17
  65. package/dist/cjs/lib/numbers/math.cjs +0 -2
  66. package/dist/cjs/lib/objects/camelcase-keys.cjs +4 -45
  67. package/dist/cjs/lib/objects/empty.cjs +0 -2
  68. package/dist/cjs/lib/objects/equal.cjs +0 -2
  69. package/dist/cjs/lib/objects/extend.cjs +6 -117
  70. package/dist/cjs/lib/objects/flatten.cjs +3 -11
  71. package/dist/cjs/lib/objects/index.cjs +27 -360
  72. package/dist/cjs/lib/objects/json.cjs +0 -2
  73. package/dist/cjs/lib/objects/loop.cjs +0 -2
  74. package/dist/cjs/lib/objects/mix/mix.cjs +3 -5
  75. package/dist/cjs/lib/objects/nested-property.cjs +0 -2
  76. package/dist/cjs/lib/objects/normalize-object.cjs +4 -78
  77. package/dist/cjs/lib/objects/omit-empty.cjs +0 -2
  78. package/dist/cjs/lib/objects/size.cjs +0 -2
  79. package/dist/cjs/lib/objects/split.cjs +0 -2
  80. package/dist/cjs/lib/promises/index.cjs +3 -51
  81. package/dist/cjs/lib/promises/reject.cjs +2 -19
  82. package/dist/cjs/lib/sse.cjs +4 -29
  83. package/dist/cjs/lib/strings/convert-case/convert-case.cjs +0 -2
  84. package/dist/cjs/lib/strings/index.cjs +11 -179
  85. package/dist/cjs/lib/strings/markdown.cjs +1 -3
  86. package/dist/cjs/lib/strings/name.cjs +0 -2
  87. package/dist/cjs/lib/strings/pluralize.cjs +1 -3
  88. package/dist/cjs/lib/strings/query-string.cjs +0 -2
  89. package/dist/cjs/lib/style/index.cjs +2 -31
  90. package/dist/cjs/lib/symbols/index.cjs +3 -22
  91. package/dist/cjs/lib/symbols/symbols.cjs +0 -2
  92. package/dist/cjs/node/dirname.cjs +2 -4
  93. package/dist/cjs/node/env.cjs +30 -0
  94. package/dist/cjs/node/file-cache.cjs +3 -45
  95. package/dist/cjs/node/file.cjs +2 -4
  96. package/dist/cjs/node/hash.cjs +1 -3
  97. package/dist/cjs/node/index.cjs +17 -272
  98. package/dist/cjs/node/pkce.cjs +5 -15
  99. package/dist/cjs/node/random-string.cjs +1 -3
  100. package/dist/cjs/node/sanitize.cjs +3 -27
  101. package/dist/cjs/node/{common.cjs → uuid.cjs} +3 -5
  102. package/dist/esm/dom/accessibility.js +0 -1
  103. package/dist/esm/dom/actions/index.js +3 -381
  104. package/dist/esm/dom/actions/masonry.js +3 -91
  105. package/dist/esm/dom/actions/prefer-horizontal-scroll.js +4 -45
  106. package/dist/esm/dom/actions/sticky.js +3 -120
  107. package/dist/esm/dom/bounding-box.js +0 -1
  108. package/dist/esm/dom/clipboard.js +0 -1
  109. package/dist/esm/dom/cookie.js +1 -2
  110. package/dist/esm/dom/css-vars.js +1 -8
  111. package/dist/esm/dom/events.js +0 -1
  112. package/dist/esm/dom/focusable.js +0 -1
  113. package/dist/esm/dom/font-size.js +1 -10
  114. package/dist/esm/dom/get-element.js +1 -2
  115. package/dist/esm/dom/hash.js +0 -1
  116. package/dist/esm/dom/index.js +23 -1168
  117. package/dist/esm/dom/keyboard.js +0 -1
  118. package/dist/esm/dom/local-store.js +1 -2
  119. package/dist/esm/dom/media.js +0 -1
  120. package/dist/esm/dom/observers/index.js +4 -224
  121. package/dist/esm/dom/observers/intersection-observer.js +2 -31
  122. package/dist/esm/dom/observers/mutation-observer.js +3 -32
  123. package/dist/esm/dom/observers/observer.js +1 -8
  124. package/dist/esm/dom/observers/resize-observer.js +2 -31
  125. package/dist/esm/dom/observers/scroll-observer.js +2 -58
  126. package/dist/esm/dom/pkce.js +1 -8
  127. package/dist/esm/dom/query-params.js +1 -2
  128. package/dist/esm/dom/random-string.js +0 -1
  129. package/dist/esm/dom/sanitize.js +3 -26
  130. package/dist/esm/dom/session-store.js +1 -2
  131. package/dist/esm/dom/spam-prevention.js +0 -1
  132. package/dist/esm/dom/trap-focus.js +2 -121
  133. package/dist/esm/dom/ui/aria-current.js +0 -1
  134. package/dist/esm/dom/ui/inconsistent-button-fix.js +0 -1
  135. package/dist/esm/dom/ui/index.js +4 -75
  136. package/dist/esm/dom/ui/scroll-container.js +0 -1
  137. package/dist/esm/dom/ui/traverse-and-scramble.js +0 -1
  138. package/dist/esm/lib/arrays/index.js +6 -106
  139. package/dist/esm/lib/arrays/item-position.js +0 -1
  140. package/dist/esm/lib/arrays/join.js +1 -6
  141. package/dist/esm/lib/arrays/shuffle.js +0 -1
  142. package/dist/esm/lib/arrays/sort.js +1 -6
  143. package/dist/esm/lib/arrays/split-array.js +0 -1
  144. package/dist/esm/lib/arrays/unique.js +0 -1
  145. package/dist/esm/lib/auth/index.js +1 -26
  146. package/dist/esm/lib/auth/route-manager.js +0 -1
  147. package/dist/esm/lib/checks.js +0 -1
  148. package/dist/esm/lib/date/days.js +1 -2
  149. package/dist/esm/lib/date/index.js +3 -173
  150. package/dist/esm/lib/date/months.js +1 -2
  151. package/dist/esm/lib/date/time.js +1 -10
  152. package/dist/esm/lib/form/form-data.js +0 -1
  153. package/dist/esm/lib/form/index.js +2 -92
  154. package/dist/esm/lib/form/sanitize.js +0 -1
  155. package/dist/esm/lib/functions/callback.js +0 -1
  156. package/dist/esm/lib/functions/debounce.js +0 -1
  157. package/dist/esm/lib/functions/env.js +0 -1
  158. package/dist/esm/lib/functions/functional.js +0 -1
  159. package/dist/esm/lib/functions/index.js +5 -105
  160. package/dist/esm/lib/functions/throttle.js +0 -1
  161. package/dist/esm/lib/functions/timeout.js +0 -1
  162. package/dist/esm/lib/hash.js +0 -1
  163. package/dist/esm/lib/index.js +14 -1052
  164. package/dist/esm/lib/numbers/index.js +2 -12
  165. package/dist/esm/lib/numbers/math.js +0 -1
  166. package/dist/esm/lib/objects/camelcase-keys.js +2 -40
  167. package/dist/esm/lib/objects/empty.js +0 -1
  168. package/dist/esm/lib/objects/equal.js +0 -1
  169. package/dist/esm/lib/objects/extend.js +3 -111
  170. package/dist/esm/lib/objects/flatten.js +1 -6
  171. package/dist/esm/lib/objects/index.js +13 -323
  172. package/dist/esm/lib/objects/json.js +0 -1
  173. package/dist/esm/lib/objects/loop.js +0 -1
  174. package/dist/esm/lib/objects/mix/mix.js +3 -4
  175. package/dist/esm/lib/objects/nested-property.js +0 -1
  176. package/dist/esm/lib/objects/normalize-object.js +3 -74
  177. package/dist/esm/lib/objects/omit-empty.js +0 -1
  178. package/dist/esm/lib/objects/size.js +0 -1
  179. package/dist/esm/lib/objects/split.js +0 -1
  180. package/dist/esm/lib/promises/index.js +1 -33
  181. package/dist/esm/lib/promises/reject.js +1 -17
  182. package/dist/esm/lib/sse.js +2 -24
  183. package/dist/esm/lib/strings/convert-case/convert-case.js +0 -1
  184. package/dist/esm/lib/strings/index.js +5 -147
  185. package/dist/esm/lib/strings/markdown.js +1 -2
  186. package/dist/esm/lib/strings/name.js +0 -1
  187. package/dist/esm/lib/strings/pluralize.js +1 -2
  188. package/dist/esm/lib/strings/query-string.js +0 -1
  189. package/dist/esm/lib/style/index.js +1 -27
  190. package/dist/esm/lib/symbols/index.js +1 -13
  191. package/dist/esm/lib/symbols/symbols.js +0 -1
  192. package/dist/esm/node/dirname.js +2 -3
  193. package/dist/esm/node/env.js +6 -0
  194. package/dist/esm/node/file-cache.js +2 -43
  195. package/dist/esm/node/file.js +2 -3
  196. package/dist/esm/node/hash.js +1 -2
  197. package/dist/esm/node/index.js +8 -243
  198. package/dist/esm/node/pkce.js +3 -12
  199. package/dist/esm/node/random-string.js +1 -2
  200. package/dist/esm/node/sanitize.js +3 -26
  201. package/dist/esm/node/{common.js → uuid.js} +0 -1
  202. package/dist/types/node/env.d.cts +3 -0
  203. package/dist/types/node/index.d.cts +2 -1
  204. package/package.json +2 -1
  205. package/src/node/env.js +3 -0
  206. package/src/node/index.js +2 -1
  207. package/tsup.config.mjs +2 -0
  208. /package/dist/types/node/{common.d.cts → uuid.d.cts} +0 -0
  209. /package/src/node/{common.js → uuid.js} +0 -0
@@ -1,12 +1,4 @@
1
- // src/lib/numbers/math.js
2
- function toDegrees(angle) {
3
- return angle * (180 / Math.PI);
4
- }
5
- function toRadians(angle) {
6
- return angle * (Math.PI / 180);
7
- }
8
-
9
- // src/lib/numbers/index.js
1
+ export * from "./math.js";
10
2
  function splitUnit(string) {
11
3
  if (typeof string === "number") return [string, null];
12
4
  const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
@@ -15,7 +7,5 @@ function splitUnit(string) {
15
7
  return [parseFloat(string), null];
16
8
  }
17
9
  export {
18
- splitUnit,
19
- toDegrees,
20
- toRadians
10
+ splitUnit
21
11
  };
@@ -1,4 +1,3 @@
1
- // src/lib/numbers/math.js
2
1
  function toDegrees(angle) {
3
2
  return angle * (180 / Math.PI);
4
3
  }
@@ -1,43 +1,5 @@
1
- // src/lib/objects/loop.js
2
- function objectForEach(object, callback) {
3
- Object.entries(object).forEach(([key, value]) => {
4
- callback({ key, value });
5
- });
6
- }
7
-
8
- // src/lib/strings/convert-case/convert-case.js
9
- function toKebab(string) {
10
- if (!string) return "";
11
- return string.split("").map((letter, index) => {
12
- const previousLetter = string[index - 1] || "";
13
- const currentLetter = letter;
14
- if (isDigit(currentLetter) && !isDigit(previousLetter)) {
15
- return `-${currentLetter}`;
16
- }
17
- if (!isCaps(currentLetter)) return currentLetter;
18
- if (previousLetter === "") {
19
- return `${currentLetter.toLowerCase()}`;
20
- }
21
- if (isCaps(previousLetter)) {
22
- return `${currentLetter.toLowerCase()}`;
23
- }
24
- return `-${currentLetter.toLowerCase()}`;
25
- }).join("").trim().replace(/[-_\s]+/g, "-");
26
- }
27
- function toCamel(string) {
28
- return toKebab(string).split("-").map((word, index) => {
29
- if (index === 0) return word;
30
- return word.slice(0, 1).toUpperCase() + word.slice(1).toLowerCase();
31
- }).join("");
32
- }
33
- function isCaps(char) {
34
- return /\p{Lu}/u.test(char);
35
- }
36
- function isDigit(char) {
37
- return /[0-9]/.test(char);
38
- }
39
-
40
- // src/lib/objects/camelcase-keys.js
1
+ import { objectForEach } from "./loop.js";
2
+ import { toCamel } from "../strings/convert-case/convert-case.js";
41
3
  function camelCaseKeys(obj) {
42
4
  if (typeof obj !== "object" || obj === null) {
43
5
  return obj;
@@ -1,4 +1,3 @@
1
- // src/lib/objects/empty.js
2
1
  function isEmpty(obj) {
3
2
  if (typeof obj === "undefined") return true;
4
3
  if (obj === null) return true;
@@ -1,4 +1,3 @@
1
- // src/lib/objects/equal.js
2
1
  import deepEqual from "deep-eql";
3
2
  function isEqual(a, b) {
4
3
  return deepEqual(a, b);
@@ -1,114 +1,6 @@
1
- // src/lib/objects/loop.js
2
- function objectForEach(object, callback) {
3
- Object.entries(object).forEach(([key, value]) => {
4
- callback({ key, value });
5
- });
6
- }
7
- function objectMap(object, callback) {
8
- return Object.entries(object).map(([key, value]) => {
9
- return callback({ key, value });
10
- });
11
- }
12
-
13
- // src/lib/functions/functional.js
14
- function curry(fn) {
15
- return function curried(...args) {
16
- if (args.length >= fn.length) {
17
- return fn.apply(this, args);
18
- } else {
19
- return function(...moreArgs) {
20
- return curried.apply(this, args.concat(moreArgs));
21
- };
22
- }
23
- };
24
- }
25
-
26
- // src/lib/objects/mix/mix.js
27
- var DEFAULT_OPTIONS = { array: "replace" };
28
- var mix = createMix();
29
- var concatMix = createMix({ array: "concat" });
30
- function createMix(userOptions = {}) {
31
- const options = { ...DEFAULT_OPTIONS, ...userOptions };
32
- function _mix(...sources) {
33
- const result = {};
34
- for (const source of sources) {
35
- if (source == null) continue;
36
- merge(result, source, options);
37
- }
38
- return result;
39
- }
40
- return _mix;
41
- }
42
- function merge(output, input, options) {
43
- const props = Object.keys(input);
44
- for (const prop of props) {
45
- if (prop === "__proto__") continue;
46
- const descriptor = Object.getOwnPropertyDescriptor(input, prop);
47
- const value = descriptor.value;
48
- if (value) descriptor.value = cloneDescriptorValue(value);
49
- if (!output[prop]) {
50
- Object.defineProperty(output, prop, descriptor);
51
- continue;
52
- }
53
- if (typeof output[prop] !== "object") {
54
- Object.defineProperty(output, prop, descriptor);
55
- continue;
56
- }
57
- if (descriptor.value == null || typeof descriptor.value !== "object") {
58
- Object.defineProperty(output, prop, descriptor);
59
- continue;
60
- }
61
- if (objectType(descriptor.value) === "[object Array]") {
62
- output[prop] = options.array === "replace" ? descriptor.value.slice() : output[prop].concat(descriptor.value);
63
- continue;
64
- }
65
- merge(output[prop], descriptor.value, options);
66
- }
67
- }
68
- function cloneDescriptorValue(value) {
69
- if (objectType(value) === "[object Array]") {
70
- const array = [];
71
- for (let v of value) {
72
- v = cloneDescriptorValue(v);
73
- array.push(v);
74
- }
75
- return array;
76
- }
77
- if (objectType(value) === "[object Object]") {
78
- const obj = {};
79
- const props = Object.keys(value);
80
- for (const prop of props) {
81
- const descriptor = Object.getOwnPropertyDescriptor(value, prop);
82
- if (descriptor.value)
83
- descriptor.value = cloneDescriptorValue(descriptor.value);
84
- Object.defineProperty(obj, prop, descriptor);
85
- }
86
- return obj;
87
- }
88
- if (objectType(value) === "[object Date]") {
89
- return new Date(value.getTime());
90
- }
91
- if (objectType(value) === "[object Map]") {
92
- const map = /* @__PURE__ */ new Map();
93
- for (const entry of value) {
94
- map.set(entry[0], cloneDescriptorValue(entry[1]));
95
- }
96
- return map;
97
- }
98
- if (objectType(value) === "[object Set]") {
99
- const set = /* @__PURE__ */ new Set();
100
- for (const entry of value.entries()) {
101
- set.add(cloneDescriptorValue(entry[0]));
102
- }
103
- return set;
104
- }
105
- return value;
106
- }
107
- function objectType(value) {
108
- return Object.prototype.toString.call(value);
109
- }
110
-
111
- // src/lib/objects/extend.js
1
+ import { objectForEach, objectMap } from "./loop.js";
2
+ import { curry } from "../functions/functional.js";
3
+ import { mix } from "./mix/mix.js";
112
4
  function extendObject(object) {
113
5
  const orig = object;
114
6
  const extended = mix({}, object);
@@ -1,9 +1,4 @@
1
- // src/lib/checks.js
2
- function isObject(x) {
3
- return typeof x === "object" && !Array.isArray(x) && x !== null;
4
- }
5
-
6
- // src/lib/objects/flatten.js
1
+ import { isObject } from "../checks.js";
7
2
  function flattenObject(obj, { separator, prefix = "" }) {
8
3
  return Object.entries(obj).reduce((acc, [key, value]) => {
9
4
  const newKey = prefix ? `${prefix}${separator}${key}` : key;
@@ -1,323 +1,13 @@
1
- // src/lib/objects/loop.js
2
- function objectForEach(object, callback) {
3
- Object.entries(object).forEach(([key, value]) => {
4
- callback({ key, value });
5
- });
6
- }
7
- function objectMap(object, callback) {
8
- return Object.entries(object).map(([key, value]) => {
9
- return callback({ key, value });
10
- });
11
- }
12
-
13
- // src/lib/strings/convert-case/convert-case.js
14
- function toKebab(string) {
15
- if (!string) return "";
16
- return string.split("").map((letter, index) => {
17
- const previousLetter = string[index - 1] || "";
18
- const currentLetter = letter;
19
- if (isDigit(currentLetter) && !isDigit(previousLetter)) {
20
- return `-${currentLetter}`;
21
- }
22
- if (!isCaps(currentLetter)) return currentLetter;
23
- if (previousLetter === "") {
24
- return `${currentLetter.toLowerCase()}`;
25
- }
26
- if (isCaps(previousLetter)) {
27
- return `${currentLetter.toLowerCase()}`;
28
- }
29
- return `-${currentLetter.toLowerCase()}`;
30
- }).join("").trim().replace(/[-_\s]+/g, "-");
31
- }
32
- function toCamel(string) {
33
- return toKebab(string).split("-").map((word, index) => {
34
- if (index === 0) return word;
35
- return word.slice(0, 1).toUpperCase() + word.slice(1).toLowerCase();
36
- }).join("");
37
- }
38
- function isCaps(char) {
39
- return /\p{Lu}/u.test(char);
40
- }
41
- function isDigit(char) {
42
- return /[0-9]/.test(char);
43
- }
44
-
45
- // src/lib/objects/camelcase-keys.js
46
- function camelCaseKeys(obj) {
47
- if (typeof obj !== "object" || obj === null) {
48
- return obj;
49
- }
50
- const result = {};
51
- objectForEach(obj, ({ key, value }) => {
52
- const camelCaseKey = toCamel(key);
53
- result[camelCaseKey] = camelCaseKeys(value);
54
- });
55
- return result;
56
- }
57
-
58
- // src/lib/objects/empty.js
59
- function isEmpty(obj) {
60
- if (typeof obj === "undefined") return true;
61
- if (obj === null) return true;
62
- if (Array.isArray(obj)) return obj.length === 0;
63
- return Object.keys(obj).length === 0;
64
- }
65
- function notEmpty(obj) {
66
- return !isEmpty(obj);
67
- }
68
-
69
- // src/lib/objects/equal.js
70
- import deepEqual from "deep-eql";
71
- function isEqual(a, b) {
72
- return deepEqual(a, b);
73
- }
74
- function notEqual(a, b) {
75
- return !isEqual(a, b);
76
- }
77
-
78
- // src/lib/functions/functional.js
79
- function curry(fn) {
80
- return function curried(...args) {
81
- if (args.length >= fn.length) {
82
- return fn.apply(this, args);
83
- } else {
84
- return function(...moreArgs) {
85
- return curried.apply(this, args.concat(moreArgs));
86
- };
87
- }
88
- };
89
- }
90
- function pipe(...fns) {
91
- return function(value) {
92
- return fns.reduce((acc, fn) => fn(acc), value);
93
- };
94
- }
95
-
96
- // src/lib/objects/mix/mix.js
97
- var DEFAULT_OPTIONS = { array: "replace" };
98
- var mix = createMix();
99
- var concatMix = createMix({ array: "concat" });
100
- function createMix(userOptions = {}) {
101
- const options = { ...DEFAULT_OPTIONS, ...userOptions };
102
- function _mix(...sources) {
103
- const result = {};
104
- for (const source of sources) {
105
- if (source == null) continue;
106
- merge(result, source, options);
107
- }
108
- return result;
109
- }
110
- return _mix;
111
- }
112
- function merge(output, input, options) {
113
- const props = Object.keys(input);
114
- for (const prop of props) {
115
- if (prop === "__proto__") continue;
116
- const descriptor = Object.getOwnPropertyDescriptor(input, prop);
117
- const value = descriptor.value;
118
- if (value) descriptor.value = cloneDescriptorValue(value);
119
- if (!output[prop]) {
120
- Object.defineProperty(output, prop, descriptor);
121
- continue;
122
- }
123
- if (typeof output[prop] !== "object") {
124
- Object.defineProperty(output, prop, descriptor);
125
- continue;
126
- }
127
- if (descriptor.value == null || typeof descriptor.value !== "object") {
128
- Object.defineProperty(output, prop, descriptor);
129
- continue;
130
- }
131
- if (objectType(descriptor.value) === "[object Array]") {
132
- output[prop] = options.array === "replace" ? descriptor.value.slice() : output[prop].concat(descriptor.value);
133
- continue;
134
- }
135
- merge(output[prop], descriptor.value, options);
136
- }
137
- }
138
- function cloneDescriptorValue(value) {
139
- if (objectType(value) === "[object Array]") {
140
- const array = [];
141
- for (let v of value) {
142
- v = cloneDescriptorValue(v);
143
- array.push(v);
144
- }
145
- return array;
146
- }
147
- if (objectType(value) === "[object Object]") {
148
- const obj = {};
149
- const props = Object.keys(value);
150
- for (const prop of props) {
151
- const descriptor = Object.getOwnPropertyDescriptor(value, prop);
152
- if (descriptor.value)
153
- descriptor.value = cloneDescriptorValue(descriptor.value);
154
- Object.defineProperty(obj, prop, descriptor);
155
- }
156
- return obj;
157
- }
158
- if (objectType(value) === "[object Date]") {
159
- return new Date(value.getTime());
160
- }
161
- if (objectType(value) === "[object Map]") {
162
- const map = /* @__PURE__ */ new Map();
163
- for (const entry of value) {
164
- map.set(entry[0], cloneDescriptorValue(entry[1]));
165
- }
166
- return map;
167
- }
168
- if (objectType(value) === "[object Set]") {
169
- const set = /* @__PURE__ */ new Set();
170
- for (const entry of value.entries()) {
171
- set.add(cloneDescriptorValue(entry[0]));
172
- }
173
- return set;
174
- }
175
- return value;
176
- }
177
- function objectType(value) {
178
- return Object.prototype.toString.call(value);
179
- }
180
-
181
- // src/lib/objects/extend.js
182
- function extendObject(object) {
183
- const orig = object;
184
- const extended = mix({}, object);
185
- extended.forEach = curry(objectForEach)(orig);
186
- extended.map = curry(objectMap)(orig);
187
- return { orig, extended };
188
- }
189
-
190
- // src/lib/checks.js
191
- function isObject(x) {
192
- return typeof x === "object" && !Array.isArray(x) && x !== null;
193
- }
194
-
195
- // src/lib/objects/flatten.js
196
- function flattenObject(obj, { separator, prefix = "" }) {
197
- return Object.entries(obj).reduce((acc, [key, value]) => {
198
- const newKey = prefix ? `${prefix}${separator}${key}` : key;
199
- const isAnObject = isObject(value);
200
- const hasNestedObject = isAnObject && Object.values(value).some(isObject);
201
- if (hasNestedObject) {
202
- Object.assign(acc, flattenObject(value, { separator, prefix: newKey }));
203
- } else {
204
- acc[newKey] = value;
205
- }
206
- return acc;
207
- }, {});
208
- }
209
-
210
- // src/lib/objects/json.js
211
- function parseJSON(value, defaultValue = {}) {
212
- try {
213
- return JSON.parse(value);
214
- } catch (e) {
215
- return defaultValue;
216
- }
217
- }
218
-
219
- // src/lib/objects/nested-property.js
220
- function getNestedProperty(object, pathArr) {
221
- return pathArr.reduce(
222
- (nestedObject, key) => nestedObject && nestedObject[key] !== "undefined" ? nestedObject[key] : void 0,
223
- object
224
- );
225
- }
226
- function getNestedProperty2(object, path) {
227
- const pathArray = path.split(".");
228
- return getNestedProperty(object, pathArray);
229
- }
230
- function getNestedValue(object, path) {
231
- return path.split(".").reduce((acc, part) => acc?.[part], object);
232
- }
233
-
234
- // src/lib/objects/omit-empty.js
235
- function omitEmpty(obj, shallow = false) {
236
- if (typeof obj !== "object" || obj === null) return obj;
237
- if (obj instanceof Date) return obj;
238
- const result = Array.isArray(obj) ? [] : {};
239
- for (const [key, value] of Object.entries(obj)) {
240
- if (value === null || value === void 0 || value === "" || typeof value === "object" && !(value instanceof Date) && Object.keys(value).length === 0) {
241
- continue;
242
- }
243
- result[key] = shallow ? value : omitEmpty(value);
244
- }
245
- return result;
246
- }
247
-
248
- // src/lib/objects/normalize-object.js
249
- function normalizeObject(object) {
250
- return pipe(omitEmpty, camelCaseKeys)(object);
251
- }
252
-
253
- // src/lib/objects/size.js
254
- function sizeOf(obj) {
255
- let bytes = 0;
256
- function size(obj2) {
257
- if (obj2 !== null && obj2 !== void 0) {
258
- switch (typeof obj2) {
259
- case "number":
260
- bytes += 8;
261
- break;
262
- case "string":
263
- bytes += obj2.length * 2;
264
- break;
265
- case "boolean":
266
- bytes += 4;
267
- break;
268
- case "object":
269
- const objClass = Object.prototype.toString.call(obj2).slice(8, -1);
270
- if (objClass === "Object" || objClass === "Array") {
271
- for (const key in obj2) {
272
- if (!obj2.hasOwnProperty(key)) continue;
273
- size(obj2[key]);
274
- }
275
- } else bytes += obj2.toString().length * 2;
276
- break;
277
- }
278
- }
279
- return bytes;
280
- }
281
- function formatByteSize(bytes2) {
282
- if (bytes2 < 1024) return bytes2 + " bytes";
283
- else if (bytes2 < 1048576) return (bytes2 / 1024).toFixed(3) + " KiB";
284
- else if (bytes2 < 1073741824) return (bytes2 / 1048576).toFixed(3) + " MiB";
285
- else return (bytes2 / 1073741824).toFixed(3) + " GiB";
286
- }
287
- return formatByteSize(size(obj));
288
- }
289
-
290
- // src/lib/objects/split.js
291
- function splitObject(obj, keys) {
292
- const picked = {};
293
- const omitted = { ...obj };
294
- keys.forEach((key) => {
295
- if (key in obj) {
296
- picked[key] = obj[key];
297
- delete omitted[key];
298
- }
299
- });
300
- return { picked, omitted, p: picked, o: omitted };
301
- }
302
- export {
303
- camelCaseKeys,
304
- concatMix,
305
- createMix,
306
- extendObject,
307
- flattenObject,
308
- getNestedProperty,
309
- getNestedProperty2,
310
- getNestedValue,
311
- isEmpty,
312
- isEqual,
313
- mix,
314
- normalizeObject,
315
- notEmpty,
316
- notEqual,
317
- objectForEach,
318
- objectMap,
319
- omitEmpty,
320
- parseJSON,
321
- sizeOf,
322
- splitObject
323
- };
1
+ export * from "./camelcase-keys.js";
2
+ export * from "./empty.js";
3
+ export * from "./equal.js";
4
+ export * from "./extend.js";
5
+ export * from "./flatten.js";
6
+ export * from "./json.js";
7
+ export * from "./loop.js";
8
+ export * from "./mix/mix.js";
9
+ export * from "./nested-property.js";
10
+ export * from "./normalize-object.js";
11
+ export * from "./omit-empty.js";
12
+ export * from "./size.js";
13
+ export * from "./split.js";
@@ -1,4 +1,3 @@
1
- // src/lib/objects/json.js
2
1
  function parseJSON(value, defaultValue = {}) {
3
2
  try {
4
3
  return JSON.parse(value);
@@ -1,4 +1,3 @@
1
- // src/lib/objects/loop.js
2
1
  function objectForEach(object, callback) {
3
2
  Object.entries(object).forEach(([key, value]) => {
4
3
  callback({ key, value });
@@ -1,7 +1,6 @@
1
- // src/lib/objects/mix/mix.js
2
- var DEFAULT_OPTIONS = { array: "replace" };
3
- var mix = createMix();
4
- var concatMix = createMix({ array: "concat" });
1
+ const DEFAULT_OPTIONS = { array: "replace" };
2
+ const mix = createMix();
3
+ const concatMix = createMix({ array: "concat" });
5
4
  function createMix(userOptions = {}) {
6
5
  const options = { ...DEFAULT_OPTIONS, ...userOptions };
7
6
  function _mix(...sources) {
@@ -1,4 +1,3 @@
1
- // src/lib/objects/nested-property.js
2
1
  function getNestedProperty(object, pathArr) {
3
2
  return pathArr.reduce(
4
3
  (nestedObject, key) => nestedObject && nestedObject[key] !== "undefined" ? nestedObject[key] : void 0,
@@ -1,77 +1,6 @@
1
- // src/lib/functions/functional.js
2
- function pipe(...fns) {
3
- return function(value) {
4
- return fns.reduce((acc, fn) => fn(acc), value);
5
- };
6
- }
7
-
8
- // src/lib/objects/loop.js
9
- function objectForEach(object, callback) {
10
- Object.entries(object).forEach(([key, value]) => {
11
- callback({ key, value });
12
- });
13
- }
14
-
15
- // src/lib/strings/convert-case/convert-case.js
16
- function toKebab(string) {
17
- if (!string) return "";
18
- return string.split("").map((letter, index) => {
19
- const previousLetter = string[index - 1] || "";
20
- const currentLetter = letter;
21
- if (isDigit(currentLetter) && !isDigit(previousLetter)) {
22
- return `-${currentLetter}`;
23
- }
24
- if (!isCaps(currentLetter)) return currentLetter;
25
- if (previousLetter === "") {
26
- return `${currentLetter.toLowerCase()}`;
27
- }
28
- if (isCaps(previousLetter)) {
29
- return `${currentLetter.toLowerCase()}`;
30
- }
31
- return `-${currentLetter.toLowerCase()}`;
32
- }).join("").trim().replace(/[-_\s]+/g, "-");
33
- }
34
- function toCamel(string) {
35
- return toKebab(string).split("-").map((word, index) => {
36
- if (index === 0) return word;
37
- return word.slice(0, 1).toUpperCase() + word.slice(1).toLowerCase();
38
- }).join("");
39
- }
40
- function isCaps(char) {
41
- return /\p{Lu}/u.test(char);
42
- }
43
- function isDigit(char) {
44
- return /[0-9]/.test(char);
45
- }
46
-
47
- // src/lib/objects/camelcase-keys.js
48
- function camelCaseKeys(obj) {
49
- if (typeof obj !== "object" || obj === null) {
50
- return obj;
51
- }
52
- const result = {};
53
- objectForEach(obj, ({ key, value }) => {
54
- const camelCaseKey = toCamel(key);
55
- result[camelCaseKey] = camelCaseKeys(value);
56
- });
57
- return result;
58
- }
59
-
60
- // src/lib/objects/omit-empty.js
61
- function omitEmpty(obj, shallow = false) {
62
- if (typeof obj !== "object" || obj === null) return obj;
63
- if (obj instanceof Date) return obj;
64
- const result = Array.isArray(obj) ? [] : {};
65
- for (const [key, value] of Object.entries(obj)) {
66
- if (value === null || value === void 0 || value === "" || typeof value === "object" && !(value instanceof Date) && Object.keys(value).length === 0) {
67
- continue;
68
- }
69
- result[key] = shallow ? value : omitEmpty(value);
70
- }
71
- return result;
72
- }
73
-
74
- // src/lib/objects/normalize-object.js
1
+ import { pipe } from "../functions/functional.js";
2
+ import { camelCaseKeys } from "./camelcase-keys.js";
3
+ import { omitEmpty } from "./omit-empty.js";
75
4
  function normalizeObject(object) {
76
5
  return pipe(omitEmpty, camelCaseKeys)(object);
77
6
  }
@@ -1,4 +1,3 @@
1
- // src/lib/objects/omit-empty.js
2
1
  function omitEmpty(obj, shallow = false) {
3
2
  if (typeof obj !== "object" || obj === null) return obj;
4
3
  if (obj instanceof Date) return obj;
@@ -1,4 +1,3 @@
1
- // src/lib/objects/size.js
2
1
  function sizeOf(obj) {
3
2
  let bytes = 0;
4
3
  function size(obj2) {
@@ -1,4 +1,3 @@
1
- // src/lib/objects/split.js
2
1
  function splitObject(obj, keys) {
3
2
  const picked = {};
4
3
  const omitted = { ...obj };