@rootreeweb/js-lib 4.0.10

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 (218) hide show
  1. package/README.md +49 -0
  2. package/dist/cjs/browser/dom.cjs +95 -0
  3. package/dist/cjs/browser/dom.d.ts +44 -0
  4. package/dist/cjs/browser/dom.d.ts.map +1 -0
  5. package/dist/cjs/browser/dom.js.map +1 -0
  6. package/dist/cjs/browser/download.cjs +40 -0
  7. package/dist/cjs/browser/download.d.ts +16 -0
  8. package/dist/cjs/browser/download.d.ts.map +1 -0
  9. package/dist/cjs/browser/download.js.map +1 -0
  10. package/dist/cjs/browser/index.cjs +20 -0
  11. package/dist/cjs/browser/index.d.ts +4 -0
  12. package/dist/cjs/browser/index.d.ts.map +1 -0
  13. package/dist/cjs/browser/index.js.map +1 -0
  14. package/dist/cjs/browser/queryOrThrow.cjs +42 -0
  15. package/dist/cjs/browser/queryOrThrow.d.ts +44 -0
  16. package/dist/cjs/browser/queryOrThrow.d.ts.map +1 -0
  17. package/dist/cjs/browser/queryOrThrow.js.map +1 -0
  18. package/dist/cjs/general/arrays.cjs +151 -0
  19. package/dist/cjs/general/arrays.d.ts +70 -0
  20. package/dist/cjs/general/arrays.d.ts.map +1 -0
  21. package/dist/cjs/general/arrays.js.map +1 -0
  22. package/dist/cjs/general/boolean.cjs +19 -0
  23. package/dist/cjs/general/boolean.d.ts +10 -0
  24. package/dist/cjs/general/boolean.d.ts.map +1 -0
  25. package/dist/cjs/general/boolean.js.map +1 -0
  26. package/dist/cjs/general/clock.cjs +22 -0
  27. package/dist/cjs/general/clock.d.ts +12 -0
  28. package/dist/cjs/general/clock.d.ts.map +1 -0
  29. package/dist/cjs/general/clock.js.map +1 -0
  30. package/dist/cjs/general/dates/create.cjs +81 -0
  31. package/dist/cjs/general/dates/create.d.ts +54 -0
  32. package/dist/cjs/general/dates/create.d.ts.map +1 -0
  33. package/dist/cjs/general/dates/create.js.map +1 -0
  34. package/dist/cjs/general/dates/dates.cjs +88 -0
  35. package/dist/cjs/general/dates/dates.d.ts +56 -0
  36. package/dist/cjs/general/dates/dates.d.ts.map +1 -0
  37. package/dist/cjs/general/dates/dates.js.map +1 -0
  38. package/dist/cjs/general/dates/get.cjs +77 -0
  39. package/dist/cjs/general/dates/get.d.ts +41 -0
  40. package/dist/cjs/general/dates/get.d.ts.map +1 -0
  41. package/dist/cjs/general/dates/get.js.map +1 -0
  42. package/dist/cjs/general/dates/index.cjs +20 -0
  43. package/dist/cjs/general/dates/index.d.ts +4 -0
  44. package/dist/cjs/general/dates/index.d.ts.map +1 -0
  45. package/dist/cjs/general/dates/index.js.map +1 -0
  46. package/dist/cjs/general/forms.cjs +31 -0
  47. package/dist/cjs/general/forms.d.ts +17 -0
  48. package/dist/cjs/general/forms.d.ts.map +1 -0
  49. package/dist/cjs/general/forms.js.map +1 -0
  50. package/dist/cjs/general/images.cjs +23 -0
  51. package/dist/cjs/general/images.d.ts +17 -0
  52. package/dist/cjs/general/images.d.ts.map +1 -0
  53. package/dist/cjs/general/images.js.map +1 -0
  54. package/dist/cjs/general/index.cjs +31 -0
  55. package/dist/cjs/general/index.d.ts +15 -0
  56. package/dist/cjs/general/index.d.ts.map +1 -0
  57. package/dist/cjs/general/index.js.map +1 -0
  58. package/dist/cjs/general/localization.cjs +199 -0
  59. package/dist/cjs/general/localization.d.ts +83 -0
  60. package/dist/cjs/general/localization.d.ts.map +1 -0
  61. package/dist/cjs/general/localization.js.map +1 -0
  62. package/dist/cjs/general/maps.cjs +63 -0
  63. package/dist/cjs/general/maps.d.ts +35 -0
  64. package/dist/cjs/general/maps.d.ts.map +1 -0
  65. package/dist/cjs/general/maps.js.map +1 -0
  66. package/dist/cjs/general/messenger/createMessenger.cjs +68 -0
  67. package/dist/cjs/general/messenger/createMessenger.d.ts +10 -0
  68. package/dist/cjs/general/messenger/createMessenger.d.ts.map +1 -0
  69. package/dist/cjs/general/messenger/createMessenger.js.map +1 -0
  70. package/dist/cjs/general/messenger/index.cjs +19 -0
  71. package/dist/cjs/general/messenger/index.d.ts +3 -0
  72. package/dist/cjs/general/messenger/index.d.ts.map +1 -0
  73. package/dist/cjs/general/messenger/index.js.map +1 -0
  74. package/dist/cjs/general/messenger/types.cjs +3 -0
  75. package/dist/cjs/general/messenger/types.d.ts +26 -0
  76. package/dist/cjs/general/messenger/types.d.ts.map +1 -0
  77. package/dist/cjs/general/messenger/types.js.map +1 -0
  78. package/dist/cjs/general/namedEntities.cjs +260 -0
  79. package/dist/cjs/general/namedEntities.d.ts +256 -0
  80. package/dist/cjs/general/namedEntities.d.ts.map +1 -0
  81. package/dist/cjs/general/namedEntities.js.map +1 -0
  82. package/dist/cjs/general/numbers.cjs +94 -0
  83. package/dist/cjs/general/numbers.d.ts +43 -0
  84. package/dist/cjs/general/numbers.d.ts.map +1 -0
  85. package/dist/cjs/general/numbers.js.map +1 -0
  86. package/dist/cjs/general/objects.cjs +98 -0
  87. package/dist/cjs/general/objects.d.ts +45 -0
  88. package/dist/cjs/general/objects.d.ts.map +1 -0
  89. package/dist/cjs/general/objects.js.map +1 -0
  90. package/dist/cjs/general/sorting.cjs +72 -0
  91. package/dist/cjs/general/sorting.d.ts +32 -0
  92. package/dist/cjs/general/sorting.d.ts.map +1 -0
  93. package/dist/cjs/general/sorting.js.map +1 -0
  94. package/dist/cjs/general/string.cjs +73 -0
  95. package/dist/cjs/general/string.d.ts +31 -0
  96. package/dist/cjs/general/string.d.ts.map +1 -0
  97. package/dist/cjs/general/string.js.map +1 -0
  98. package/dist/cjs/general/timeout.cjs +17 -0
  99. package/dist/cjs/general/timeout.d.ts +8 -0
  100. package/dist/cjs/general/timeout.d.ts.map +1 -0
  101. package/dist/cjs/general/timeout.js.map +1 -0
  102. package/dist/cjs/index.cjs +20 -0
  103. package/dist/cjs/index.d.ts +4 -0
  104. package/dist/cjs/index.d.ts.map +1 -0
  105. package/dist/cjs/index.js.map +1 -0
  106. package/dist/cjs/node/index.cjs +30 -0
  107. package/dist/cjs/node/index.d.ts +25 -0
  108. package/dist/cjs/node/index.d.ts.map +1 -0
  109. package/dist/cjs/node/index.js.map +1 -0
  110. package/dist/esm/browser/dom.d.ts +44 -0
  111. package/dist/esm/browser/dom.d.ts.map +1 -0
  112. package/dist/esm/browser/dom.js +88 -0
  113. package/dist/esm/browser/dom.js.map +1 -0
  114. package/dist/esm/browser/download.d.ts +16 -0
  115. package/dist/esm/browser/download.d.ts.map +1 -0
  116. package/dist/esm/browser/download.js +36 -0
  117. package/dist/esm/browser/download.js.map +1 -0
  118. package/dist/esm/browser/index.d.ts +4 -0
  119. package/dist/esm/browser/index.d.ts.map +1 -0
  120. package/dist/esm/browser/index.js +4 -0
  121. package/dist/esm/browser/index.js.map +1 -0
  122. package/dist/esm/browser/queryOrThrow.d.ts +44 -0
  123. package/dist/esm/browser/queryOrThrow.d.ts.map +1 -0
  124. package/dist/esm/browser/queryOrThrow.js +39 -0
  125. package/dist/esm/browser/queryOrThrow.js.map +1 -0
  126. package/dist/esm/general/arrays.d.ts +70 -0
  127. package/dist/esm/general/arrays.d.ts.map +1 -0
  128. package/dist/esm/general/arrays.js +144 -0
  129. package/dist/esm/general/arrays.js.map +1 -0
  130. package/dist/esm/general/boolean.d.ts +10 -0
  131. package/dist/esm/general/boolean.d.ts.map +1 -0
  132. package/dist/esm/general/boolean.js +16 -0
  133. package/dist/esm/general/boolean.js.map +1 -0
  134. package/dist/esm/general/clock.d.ts +12 -0
  135. package/dist/esm/general/clock.d.ts.map +1 -0
  136. package/dist/esm/general/clock.js +19 -0
  137. package/dist/esm/general/clock.js.map +1 -0
  138. package/dist/esm/general/dates/create.d.ts +54 -0
  139. package/dist/esm/general/dates/create.d.ts.map +1 -0
  140. package/dist/esm/general/dates/create.js +73 -0
  141. package/dist/esm/general/dates/create.js.map +1 -0
  142. package/dist/esm/general/dates/dates.d.ts +56 -0
  143. package/dist/esm/general/dates/dates.d.ts.map +1 -0
  144. package/dist/esm/general/dates/dates.js +82 -0
  145. package/dist/esm/general/dates/dates.js.map +1 -0
  146. package/dist/esm/general/dates/get.d.ts +41 -0
  147. package/dist/esm/general/dates/get.d.ts.map +1 -0
  148. package/dist/esm/general/dates/get.js +70 -0
  149. package/dist/esm/general/dates/get.js.map +1 -0
  150. package/dist/esm/general/dates/index.d.ts +4 -0
  151. package/dist/esm/general/dates/index.d.ts.map +1 -0
  152. package/dist/esm/general/dates/index.js +4 -0
  153. package/dist/esm/general/dates/index.js.map +1 -0
  154. package/dist/esm/general/forms.d.ts +17 -0
  155. package/dist/esm/general/forms.d.ts.map +1 -0
  156. package/dist/esm/general/forms.js +27 -0
  157. package/dist/esm/general/forms.js.map +1 -0
  158. package/dist/esm/general/images.d.ts +17 -0
  159. package/dist/esm/general/images.d.ts.map +1 -0
  160. package/dist/esm/general/images.js +20 -0
  161. package/dist/esm/general/images.js.map +1 -0
  162. package/dist/esm/general/index.d.ts +15 -0
  163. package/dist/esm/general/index.d.ts.map +1 -0
  164. package/dist/esm/general/index.js +15 -0
  165. package/dist/esm/general/index.js.map +1 -0
  166. package/dist/esm/general/localization.d.ts +83 -0
  167. package/dist/esm/general/localization.d.ts.map +1 -0
  168. package/dist/esm/general/localization.js +188 -0
  169. package/dist/esm/general/localization.js.map +1 -0
  170. package/dist/esm/general/maps.d.ts +35 -0
  171. package/dist/esm/general/maps.d.ts.map +1 -0
  172. package/dist/esm/general/maps.js +59 -0
  173. package/dist/esm/general/maps.js.map +1 -0
  174. package/dist/esm/general/messenger/createMessenger.d.ts +10 -0
  175. package/dist/esm/general/messenger/createMessenger.d.ts.map +1 -0
  176. package/dist/esm/general/messenger/createMessenger.js +65 -0
  177. package/dist/esm/general/messenger/createMessenger.js.map +1 -0
  178. package/dist/esm/general/messenger/index.d.ts +3 -0
  179. package/dist/esm/general/messenger/index.d.ts.map +1 -0
  180. package/dist/esm/general/messenger/index.js +3 -0
  181. package/dist/esm/general/messenger/index.js.map +1 -0
  182. package/dist/esm/general/messenger/types.d.ts +26 -0
  183. package/dist/esm/general/messenger/types.d.ts.map +1 -0
  184. package/dist/esm/general/messenger/types.js +2 -0
  185. package/dist/esm/general/messenger/types.js.map +1 -0
  186. package/dist/esm/general/namedEntities.d.ts +256 -0
  187. package/dist/esm/general/namedEntities.d.ts.map +1 -0
  188. package/dist/esm/general/namedEntities.js +257 -0
  189. package/dist/esm/general/namedEntities.js.map +1 -0
  190. package/dist/esm/general/numbers.d.ts +43 -0
  191. package/dist/esm/general/numbers.d.ts.map +1 -0
  192. package/dist/esm/general/numbers.js +87 -0
  193. package/dist/esm/general/numbers.js.map +1 -0
  194. package/dist/esm/general/objects.d.ts +45 -0
  195. package/dist/esm/general/objects.d.ts.map +1 -0
  196. package/dist/esm/general/objects.js +91 -0
  197. package/dist/esm/general/objects.js.map +1 -0
  198. package/dist/esm/general/sorting.d.ts +32 -0
  199. package/dist/esm/general/sorting.d.ts.map +1 -0
  200. package/dist/esm/general/sorting.js +67 -0
  201. package/dist/esm/general/sorting.js.map +1 -0
  202. package/dist/esm/general/string.d.ts +31 -0
  203. package/dist/esm/general/string.d.ts.map +1 -0
  204. package/dist/esm/general/string.js +68 -0
  205. package/dist/esm/general/string.js.map +1 -0
  206. package/dist/esm/general/timeout.d.ts +8 -0
  207. package/dist/esm/general/timeout.d.ts.map +1 -0
  208. package/dist/esm/general/timeout.js +14 -0
  209. package/dist/esm/general/timeout.js.map +1 -0
  210. package/dist/esm/index.d.ts +4 -0
  211. package/dist/esm/index.d.ts.map +1 -0
  212. package/dist/esm/index.js +4 -0
  213. package/dist/esm/index.js.map +1 -0
  214. package/dist/esm/node/index.d.ts +25 -0
  215. package/dist/esm/node/index.d.ts.map +1 -0
  216. package/dist/esm/node/index.js +27 -0
  217. package/dist/esm/node/index.js.map +1 -0
  218. package/package.json +62 -0
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Deep merge two objects.
3
+ *
4
+ * @template T The type of the objects to merge.
5
+ * @template U The type of the data object.
6
+ * @param defaults The defaults object.
7
+ * @param data The data object to merge into the defaults.
8
+ * @returns The merged object.
9
+ */
10
+ export declare function deepMerge<T extends object, U extends object>(defaults: T, data: U): T & U;
11
+ /**
12
+ * Removes any unserializable objects from the object.
13
+ *
14
+ * @template T The type of the object.
15
+ * @param obj The object to flatten.
16
+ * @returns The flattened object.
17
+ */
18
+ export declare function flattenObject<T>(obj: T): T;
19
+ /**
20
+ * Determines if an object is empty.
21
+ *
22
+ * @param obj The object to check.
23
+ * @returns True if the object is empty.
24
+ */
25
+ export declare function isEmptyObject(obj: object): boolean;
26
+ /**
27
+ * Test if a value is a plain object for RSC purposes.
28
+ *
29
+ * @param value The value to check.
30
+ * @param parentKey The nested key being checked.
31
+ * @returns True if the object is deemed passable to a client component.
32
+ */
33
+ export declare function isPlainObject(value: unknown, parentKey?: string): boolean;
34
+ /**
35
+ * Checks that the field exists on the object itself before getting it.
36
+ *
37
+ * @template TParent The type of the object.
38
+ * @template TField The key of the of the object.
39
+ * @param object The object to get the property from.
40
+ * @param field The field to get.
41
+ * @returns The value of the field, or undefined if it does not exist.
42
+ */
43
+ export declare function safeishGetProperty<TParent extends object, TField extends keyof TParent>(object: TParent, field: TField): TParent[TField];
44
+ export declare function safeishGetProperty<TParent extends object>(object: TParent, field: PropertyKey): unknown;
45
+ //# sourceMappingURL=objects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../../../src/general/objects.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC3D,QAAQ,EAAE,CAAC,EACX,IAAI,EAAE,CAAC,GACL,CAAC,GAAG,CAAC,CAmBP;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAE1C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAkBzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,SAAS,MAAM,EACtB,MAAM,SAAS,MAAM,OAAO,EAC3B,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AACnD,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,MAAM,EACxD,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,WAAW,GAChB,OAAO,CAAC"}
@@ -0,0 +1,91 @@
1
+ import { dedupe } from "./arrays.js";
2
+ /**
3
+ * Deep merge two objects.
4
+ *
5
+ * @template T The type of the objects to merge.
6
+ * @template U The type of the data object.
7
+ * @param defaults The defaults object.
8
+ * @param data The data object to merge into the defaults.
9
+ * @returns The merged object.
10
+ */
11
+ export function deepMerge(defaults, data) {
12
+ const output = { ...defaults };
13
+ for (const key in data) {
14
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
15
+ const dataValue = safeishGetProperty(data, key);
16
+ const defaultsValue = safeishGetProperty(defaults, key);
17
+ if (isObject(dataValue) && isObject(defaultsValue)) {
18
+ output[key] = deepMerge(defaultsValue, dataValue);
19
+ }
20
+ else if (Array.isArray(dataValue) && Array.isArray(defaultsValue)) {
21
+ output[key] = dedupe([...defaultsValue, ...dataValue]);
22
+ }
23
+ else {
24
+ output[key] = dataValue;
25
+ }
26
+ }
27
+ }
28
+ return output;
29
+ }
30
+ /**
31
+ * Removes any unserializable objects from the object.
32
+ *
33
+ * @template T The type of the object.
34
+ * @param obj The object to flatten.
35
+ * @returns The flattened object.
36
+ */
37
+ export function flattenObject(obj) {
38
+ return JSON.parse(JSON.stringify(obj));
39
+ }
40
+ /**
41
+ * Determines if an object is empty.
42
+ *
43
+ * @param obj The object to check.
44
+ * @returns True if the object is empty.
45
+ */
46
+ export function isEmptyObject(obj) {
47
+ return Object.keys(obj).length === 0;
48
+ }
49
+ /**
50
+ * Test if a value is a plain object for RSC purposes.
51
+ *
52
+ * @param value The value to check.
53
+ * @param parentKey The nested key being checked.
54
+ * @returns True if the object is deemed passable to a client component.
55
+ */
56
+ export function isPlainObject(value, parentKey) {
57
+ if (!isObject(value))
58
+ return true;
59
+ for (const key in value) {
60
+ if (!isPlainObject(value[key], key)) {
61
+ return false;
62
+ }
63
+ }
64
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
65
+ const ownPrototype = Object.getPrototypeOf(value);
66
+ const isSelfPlain = ownPrototype === Object.prototype;
67
+ if (!isSelfPlain) {
68
+ console.error(
69
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
70
+ `Non-plain object found at ${parentKey || "root"}: ${String(ownPrototype)}`);
71
+ return false;
72
+ }
73
+ return true;
74
+ }
75
+ export function safeishGetProperty(object, field) {
76
+ if (Object.prototype.hasOwnProperty.call(object, field)) {
77
+ // eslint-disable-next-line security/detect-object-injection
78
+ return object[field];
79
+ }
80
+ return undefined;
81
+ }
82
+ /**
83
+ * Check if a value is an object.
84
+ *
85
+ * @param obj The value to check.
86
+ * @returns True if the value is an object.
87
+ */
88
+ function isObject(obj) {
89
+ return !!(obj && typeof obj === "object" && !Array.isArray(obj));
90
+ }
91
+ //# sourceMappingURL=objects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objects.js","sourceRoot":"","sources":["../../../src/general/objects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CACxB,QAAW,EACX,IAAO;IAEP,MAAM,MAAM,GAAG,EAAE,GAAG,QAAQ,EAAW,CAAC;IAExC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAA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CAAC;YAC3D,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IACD,mEAAmE;IACnE,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,YAAY,KAAK,MAAM,CAAC,SAAS,CAAC;IACtD,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK;QACZ,wEAAwE;QACxE,6BAA6B,SAAS,IAAI,MAAM,KAAK,MAAM,CAAC,YAAY,CAAC,EAAE,CAC3E,CAAC;QACF,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAmBD,MAAM,UAAU,kBAAkB,CACjC,MAAe,EACf,KAAkB;IAElB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;QACzD,4DAA4D;QAC5D,OAAQ,MAAuC,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AACD;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,GAAY;IAC7B,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import { dedupe } from \"./arrays.js\";\n\n/**\n * Deep merge two objects.\n *\n * @template T The type of the objects to merge.\n * @template U The type of the data object.\n * @param defaults The defaults object.\n * @param data The data object to merge into the defaults.\n * @returns The merged object.\n */\nexport function deepMerge<T extends object, U extends object>(\n\tdefaults: T,\n\tdata: U,\n): T & U {\n\tconst output = { ...defaults } as T & U;\n\n\tfor (const key in data) {\n\t\tif (Object.prototype.hasOwnProperty.call(data, key)) {\n\t\t\tconst dataValue = safeishGetProperty(data, key as keyof U);\n\t\t\tconst defaultsValue = safeishGetProperty(defaults as T & U, key);\n\n\t\t\tif (isObject(dataValue) && isObject(defaultsValue)) {\n\t\t\t\toutput[key] = deepMerge(defaultsValue, dataValue);\n\t\t\t} else if (Array.isArray(dataValue) && Array.isArray(defaultsValue)) {\n\t\t\t\t(output as any)[key] = dedupe([...defaultsValue, ...dataValue]);\n\t\t\t} else {\n\t\t\t\t(output as any)[key] = dataValue;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn output;\n}\n\n/**\n * Removes any unserializable objects from the object.\n *\n * @template T The type of the object.\n * @param obj The object to flatten.\n * @returns The flattened object.\n */\nexport function flattenObject<T>(obj: T): T {\n\treturn JSON.parse(JSON.stringify(obj)) as T;\n}\n\n/**\n * Determines if an object is empty.\n *\n * @param obj The object to check.\n * @returns True if the object is empty.\n */\nexport function isEmptyObject(obj: object): boolean {\n\treturn Object.keys(obj).length === 0;\n}\n\n/**\n * Test if a value is a plain object for RSC purposes.\n *\n * @param value The value to check.\n * @param parentKey The nested key being checked.\n * @returns True if the object is deemed passable to a client component.\n */\nexport function isPlainObject(value: unknown, parentKey?: string): boolean {\n\tif (!isObject(value)) return true;\n\tfor (const key in value) {\n\t\tif (!isPlainObject(value[key as keyof typeof value], key)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\tconst ownPrototype = Object.getPrototypeOf(value);\n\tconst isSelfPlain = ownPrototype === Object.prototype;\n\tif (!isSelfPlain) {\n\t\tconsole.error(\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\t`Non-plain object found at ${parentKey || \"root\"}: ${String(ownPrototype)}`,\n\t\t);\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/**\n * Checks that the field exists on the object itself before getting it.\n *\n * @template TParent The type of the object.\n * @template TField The key of the of the object.\n * @param object The object to get the property from.\n * @param field The field to get.\n * @returns The value of the field, or undefined if it does not exist.\n */\nexport function safeishGetProperty<\n\tTParent extends object,\n\tTField extends keyof TParent,\n>(object: TParent, field: TField): TParent[TField];\nexport function safeishGetProperty<TParent extends object>(\n\tobject: TParent,\n\tfield: PropertyKey,\n): unknown;\nexport function safeishGetProperty<TParent extends object>(\n\tobject: TParent,\n\tfield: PropertyKey,\n): unknown {\n\tif (Object.prototype.hasOwnProperty.call(object, field)) {\n\t\t// eslint-disable-next-line security/detect-object-injection\n\t\treturn (object as Record<PropertyKey, unknown>)[field];\n\t}\n\treturn undefined;\n}\n/**\n * Check if a value is an object.\n *\n * @param obj The value to check.\n * @returns True if the value is an object.\n */\nfunction isObject(obj: unknown): obj is Record<PropertyKey, unknown> {\n\treturn !!(obj && typeof obj === \"object\" && !Array.isArray(obj));\n}\n"]}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Compare two values for sorting
3
+ *
4
+ * @param aValue The first value to compare
5
+ * @param bValue The second value to compare
6
+ * @param ascending Whether to sort ascending
7
+ * @returns The sort order
8
+ * @throws {TypeError} An error if the types are not supported
9
+ */
10
+ export declare function compareForSort(aValue: unknown, bValue: unknown, ascending?: boolean): number;
11
+ /**
12
+ * Compare two objects for sorting by a field
13
+ *
14
+ * @template T The type of the objects
15
+ * @param a The first object to compare
16
+ * @param b The second object to compare
17
+ * @param field The field to compare by
18
+ * @param ascending Whether to sort ascending
19
+ * @returns The sort order
20
+ */
21
+ export declare function compareForSortByField<T extends object>(a: T, b: T, field: keyof T & string, ascending?: boolean): number;
22
+ /**
23
+ * Sort an array of objects by a field
24
+ *
25
+ * @template T The type of the objects
26
+ * @param rows The rows to sort
27
+ * @param field The field to sort by
28
+ * @param ascending Whether to sort ascending
29
+ * @returns The sorted rows
30
+ */
31
+ export declare function sortOnField<T extends object>(rows: T[], field: keyof T & string, ascending?: boolean): T[];
32
+ //# sourceMappingURL=sorting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sorting.d.ts","sourceRoot":"","sources":["../../../src/general/sorting.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,OAAO,EACf,SAAS,UAAO,GACd,MAAM,CAwBR;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EACrD,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,EACvB,SAAS,UAAO,GACd,MAAM,CAIR;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC3C,IAAI,EAAE,CAAC,EAAE,EACT,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,EACvB,SAAS,UAAO,GACd,CAAC,EAAE,CAIL"}
@@ -0,0 +1,67 @@
1
+ import { safeishGetProperty } from "./objects.js";
2
+ /**
3
+ * Compare two values for sorting
4
+ *
5
+ * @param aValue The first value to compare
6
+ * @param bValue The second value to compare
7
+ * @param ascending Whether to sort ascending
8
+ * @returns The sort order
9
+ * @throws {TypeError} An error if the types are not supported
10
+ */
11
+ export function compareForSort(aValue, bValue, ascending = true) {
12
+ let diff = 0;
13
+ if (aValue && !bValue) {
14
+ diff = 1;
15
+ }
16
+ else if (!aValue && bValue) {
17
+ diff = -1;
18
+ }
19
+ else if (aValue || bValue) {
20
+ if (typeof aValue === "string" && typeof bValue === "string") {
21
+ diff = aValue.localeCompare(bValue);
22
+ }
23
+ else if (typeof aValue === "number" && typeof bValue === "number") {
24
+ diff = aValue - bValue;
25
+ }
26
+ else if (aValue instanceof Date && bValue instanceof Date) {
27
+ diff = aValue.getTime() - bValue.getTime();
28
+ }
29
+ else if (typeof aValue !== "boolean" || typeof bValue !== "boolean") {
30
+ throw new TypeError(`Unsupported types for sorting: A type: "${typeof aValue}" A Value: "${String(aValue)}" B Type: "${typeof bValue}" && B Value: "${String(bValue)}"`);
31
+ }
32
+ }
33
+ if (ascending) {
34
+ return diff;
35
+ }
36
+ return Object.is(-diff, -0) ? 0 : -diff;
37
+ }
38
+ /**
39
+ * Compare two objects for sorting by a field
40
+ *
41
+ * @template T The type of the objects
42
+ * @param a The first object to compare
43
+ * @param b The second object to compare
44
+ * @param field The field to compare by
45
+ * @param ascending Whether to sort ascending
46
+ * @returns The sort order
47
+ */
48
+ export function compareForSortByField(a, b, field, ascending = true) {
49
+ const valueA = safeishGetProperty(a, field);
50
+ const valueB = safeishGetProperty(b, field);
51
+ return compareForSort(valueA, valueB, ascending);
52
+ }
53
+ /**
54
+ * Sort an array of objects by a field
55
+ *
56
+ * @template T The type of the objects
57
+ * @param rows The rows to sort
58
+ * @param field The field to sort by
59
+ * @param ascending Whether to sort ascending
60
+ * @returns The sorted rows
61
+ */
62
+ export function sortOnField(rows, field, ascending = true) {
63
+ return rows
64
+ .slice()
65
+ .sort((a, b) => compareForSortByField(a, b, field, ascending));
66
+ }
67
+ //# sourceMappingURL=sorting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sorting.js","sourceRoot":"","sources":["../../../src/general/sorting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC7B,MAAe,EACf,MAAe,EACf,SAAS,GAAG,IAAI;IAEhB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,IAAI,GAAG,CAAC,CAAC;IACV,CAAC;SAAM,IAAI,CAAC,MAAM,IAAI,MAAM,EAAE,CAAC;QAC9B,IAAI,GAAG,CAAC,CAAC,CAAC;IACX,CAAC;SAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QAC7B,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC9D,IAAI,GAAG,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;aAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAA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C,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { safeishGetProperty } from \"./objects.js\";\n\n/**\n * Compare two values for sorting\n *\n * @param aValue The first value to compare\n * @param bValue The second value to compare\n * @param ascending Whether to sort ascending\n * @returns The sort order\n * @throws {TypeError} An error if the types are not supported\n */\nexport function compareForSort(\n\taValue: unknown,\n\tbValue: unknown,\n\tascending = true,\n): number {\n\tlet diff = 0;\n\tif (aValue && !bValue) {\n\t\tdiff = 1;\n\t} else if (!aValue && bValue) {\n\t\tdiff = -1;\n\t} else if (aValue || bValue) {\n\t\tif (typeof aValue === \"string\" && typeof bValue === \"string\") {\n\t\t\tdiff = aValue.localeCompare(bValue);\n\t\t} else if (typeof aValue === \"number\" && typeof bValue === \"number\") {\n\t\t\tdiff = aValue - bValue;\n\t\t} else if (aValue instanceof Date && bValue instanceof Date) {\n\t\t\tdiff = aValue.getTime() - bValue.getTime();\n\t\t} else if (typeof aValue !== \"boolean\" || typeof bValue !== \"boolean\") {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Unsupported types for sorting: A type: \"${typeof aValue}\" A Value: \"${String(aValue)}\" B Type: \"${typeof bValue}\" && B Value: \"${String(bValue)}\"`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (ascending) {\n\t\treturn diff;\n\t}\n\treturn Object.is(-diff, -0) ? 0 : -diff;\n}\n\n/**\n * Compare two objects for sorting by a field\n *\n * @template T The type of the objects\n * @param a The first object to compare\n * @param b The second object to compare\n * @param field The field to compare by\n * @param ascending Whether to sort ascending\n * @returns The sort order\n */\nexport function compareForSortByField<T extends object>(\n\ta: T,\n\tb: T,\n\tfield: keyof T & string,\n\tascending = true,\n): number {\n\tconst valueA = safeishGetProperty(a, field);\n\tconst valueB = safeishGetProperty(b, field);\n\treturn compareForSort(valueA, valueB, ascending);\n}\n\n/**\n * Sort an array of objects by a field\n *\n * @template T The type of the objects\n * @param rows The rows to sort\n * @param field The field to sort by\n * @param ascending Whether to sort ascending\n * @returns The sorted rows\n */\nexport function sortOnField<T extends object>(\n\trows: T[],\n\tfield: keyof T & string,\n\tascending = true,\n): T[] {\n\treturn rows\n\t\t.slice()\n\t\t.sort((a, b) => compareForSortByField(a, b, field, ascending));\n}\n"]}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Capitalizes a string.
3
+ *
4
+ * @example
5
+ * const str = capitalizeString("hello world!");
6
+ * console.log(str);
7
+ * // Hello world!
8
+ *
9
+ * @param str The string to capitalize.
10
+ * @returns The capitalized string.
11
+ */
12
+ export declare function capitalizeString(str: string): string;
13
+ /**
14
+ * Decode HTML entities in a string.
15
+ *
16
+ * @example
17
+ * decodeHTMLEntities("That&#39;s cool!"); // => "That's cool!"
18
+ * decodeHTMLEntities("&lt;div&gt;"); // => "<div>" Note that this should be used with caution, as it can be a security risk.
19
+ *
20
+ * @param string The string to decode
21
+ * @returns The decoded string
22
+ */
23
+ export declare function decodeHTMLEntities(string: string): string;
24
+ /**
25
+ * Converts a string to title-case.
26
+ *
27
+ * @param string The text to convert to title-case
28
+ * @returns The text in title-case
29
+ */
30
+ export declare function toTitleCase(string: string): string;
31
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../src/general/string.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAUzD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKlD"}
@@ -0,0 +1,68 @@
1
+ import { namedEntities } from "./namedEntities.js";
2
+ /**
3
+ * Capitalizes a string.
4
+ *
5
+ * @example
6
+ * const str = capitalizeString("hello world!");
7
+ * console.log(str);
8
+ * // Hello world!
9
+ *
10
+ * @param str The string to capitalize.
11
+ * @returns The capitalized string.
12
+ */
13
+ export function capitalizeString(str) {
14
+ return (str[0] ?? "").toUpperCase() + str.slice(1);
15
+ }
16
+ /**
17
+ * Decode HTML entities in a string.
18
+ *
19
+ * @example
20
+ * decodeHTMLEntities("That&#39;s cool!"); // => "That's cool!"
21
+ * decodeHTMLEntities("&lt;div&gt;"); // => "<div>" Note that this should be used with caution, as it can be a security risk.
22
+ *
23
+ * @param string The string to decode
24
+ * @returns The decoded string
25
+ */
26
+ export function decodeHTMLEntities(string) {
27
+ let str = string.replace(/&#(\d+);/g, (_, dec) => {
28
+ return String.fromCharCode(dec);
29
+ });
30
+ for (const [key, value] of Object.entries(namedEntities)) {
31
+ // From an internal source.
32
+ // eslint-disable-next-line security/detect-non-literal-regexp
33
+ str = str.replace(new RegExp(`&${key};`, "g"), value);
34
+ }
35
+ return str;
36
+ }
37
+ /**
38
+ * Converts a string to title-case.
39
+ *
40
+ * @param string The text to convert to title-case
41
+ * @returns The text in title-case
42
+ */
43
+ export function toTitleCase(string) {
44
+ if (string.length === 0) {
45
+ return string;
46
+ }
47
+ return handleSplitter(handleSplitter(string.toLowerCase(), " "), "\n");
48
+ }
49
+ /**
50
+ * Converts a string to sentence-case, for a given splitter.
51
+ *
52
+ * @param string The text to convert to sentence-case
53
+ * @param splitter The character to split the string by
54
+ * @returns The text in sentence-case
55
+ */
56
+ function handleSplitter(string, splitter) {
57
+ const sentence = string.split(splitter);
58
+ for (let i = 0; i < sentence.length; i++) {
59
+ // eslint-disable-next-line security/detect-object-injection
60
+ if (!sentence[i]?.length) {
61
+ continue;
62
+ }
63
+ // eslint-disable-next-line security/detect-object-injection, @typescript-eslint/no-non-null-assertion
64
+ sentence[i] = capitalizeString(sentence[i]);
65
+ }
66
+ return sentence.join(splitter);
67
+ }
68
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src/general/string.ts"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QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,4DAA4D;QAC5D,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;YAC1B,SAAS;QACV,CAAC;QACD,sGAAsG;QACtG,QAAQ,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAE,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { namedEntities } from \"./namedEntities.js\";\n\n/**\n * Capitalizes a string.\n *\n * @example\n * \tconst str = capitalizeString(\"hello world!\");\n * \tconsole.log(str);\n * \t// Hello world!\n *\n * @param str The string to capitalize.\n * @returns The capitalized string.\n */\nexport function capitalizeString(str: string): string {\n\treturn (str[0] ?? \"\").toUpperCase() + str.slice(1);\n}\n\n/**\n * Decode HTML entities in a string.\n *\n * @example\n * \tdecodeHTMLEntities(\"That&#39;s cool!\"); // => \"That's cool!\"\n * \tdecodeHTMLEntities(\"&lt;div&gt;\"); // => \"<div>\" Note that this should be used with caution, as it can be a security risk.\n *\n * @param string The string to decode\n * @returns The decoded string\n */\nexport function decodeHTMLEntities(string: string): string {\n\tlet str = string.replace(/&#(\\d+);/g, (_, dec: number) => {\n\t\treturn String.fromCharCode(dec);\n\t});\n\tfor (const [key, value] of Object.entries(namedEntities)) {\n\t\t// From an internal source.\n\t\t// eslint-disable-next-line security/detect-non-literal-regexp\n\t\tstr = str.replace(new RegExp(`&${key};`, \"g\"), value);\n\t}\n\treturn str;\n}\n\n/**\n * Converts a string to title-case.\n *\n * @param string The text to convert to title-case\n * @returns The text in title-case\n */\nexport function toTitleCase(string: string): string {\n\tif (string.length === 0) {\n\t\treturn string;\n\t}\n\treturn handleSplitter(handleSplitter(string.toLowerCase(), \" \"), \"\\n\");\n}\n\n/**\n * Converts a string to sentence-case, for a given splitter.\n *\n * @param string The text to convert to sentence-case\n * @param splitter The character to split the string by\n * @returns The text in sentence-case\n */\nfunction handleSplitter(string: string, splitter: string) {\n\tconst sentence = string.split(splitter);\n\tfor (let i = 0; i < sentence.length; i++) {\n\t\t// eslint-disable-next-line security/detect-object-injection\n\t\tif (!sentence[i]?.length) {\n\t\t\tcontinue;\n\t\t}\n\t\t// eslint-disable-next-line security/detect-object-injection, @typescript-eslint/no-non-null-assertion\n\t\tsentence[i] = capitalizeString(sentence[i]!);\n\t}\n\treturn sentence.join(splitter);\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Wait for a set amount of time.
3
+ *
4
+ * @param timeout The amount of time to wait.
5
+ * @returns A promise that resolves after the timeout.
6
+ */
7
+ export declare function waitForTimeout(timeout: number): Promise<true>;
8
+ //# sourceMappingURL=timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../../src/general/timeout.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7D"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Wait for a set amount of time.
3
+ *
4
+ * @param timeout The amount of time to wait.
5
+ * @returns A promise that resolves after the timeout.
6
+ */
7
+ export function waitForTimeout(timeout) {
8
+ return new Promise((resolve) => {
9
+ setTimeout(() => {
10
+ resolve(true);
11
+ }, timeout);
12
+ });
13
+ }
14
+ //# sourceMappingURL=timeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../../src/general/timeout.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC7C,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACpC,UAAU,CAAC,GAAG,EAAE;YACf,OAAO,CAAC,IAAI,CAAC,CAAC;QACf,CAAC,EAAE,OAAO,CAAC,CAAC;IACb,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Wait for a set amount of time.\n *\n * @param timeout The amount of time to wait.\n * @returns A promise that resolves after the timeout.\n */\nexport function waitForTimeout(timeout: number): Promise<true> {\n\treturn new Promise<true>((resolve) => {\n\t\tsetTimeout(() => {\n\t\t\tresolve(true);\n\t\t}, timeout);\n\t});\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export * from "./browser/index.js";
2
+ export * from "./general/index.js";
3
+ export * from "./node/index.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./browser/index.js";
2
+ export * from "./general/index.js";
3
+ export * from "./node/index.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./browser/index.js\";\nexport * from \"./general/index.js\";\nexport * from \"./node/index.js\";\n"]}
@@ -0,0 +1,25 @@
1
+ export type ExpectedEnvironmentSuccess<TKey extends string> = Record<ExtractVariableNames<ExpectedEnvironmentVariables<TKey>>, string>;
2
+ /**
3
+ * The expected environment variables.
4
+ *
5
+ * @template TKey An expected environment key.
6
+ */
7
+ export type ExpectedEnvironmentVariables<TKey extends string> = TKey[] | {
8
+ message: string;
9
+ name: TKey;
10
+ }[];
11
+ type ExtractVariableNames<T extends ExpectedEnvironmentVariables<string>> = T extends string[] ? T[number] : T extends {
12
+ name: infer N;
13
+ }[] ? N extends string ? N : never : never;
14
+ /**
15
+ * Checks if the expected environment variables are set.
16
+ *
17
+ * @template TKey An expected environment key.
18
+ * @param expected The expected environment variables.
19
+ * @returns A key, value set of the environment variables requested for
20
+ * validation.
21
+ * @throws {TypeError} If an expected environment variable hasn't been set.
22
+ */
23
+ export declare function checkEnvironmentVariables<TKey extends string>(expected: ExpectedEnvironmentVariables<TKey>): ExpectedEnvironmentSuccess<TKey>;
24
+ export {};
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,0BAA0B,CAAC,IAAI,SAAS,MAAM,IAAI,MAAM,CACnE,oBAAoB,CAAC,4BAA4B,CAAC,IAAI,CAAC,CAAC,EACxD,MAAM,CACN,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,CAAC,IAAI,SAAS,MAAM,IACzD,IAAI,EAAE,GACN;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,EAAE,CAAC;AAErC,KAAK,oBAAoB,CAAC,CAAC,SAAS,4BAA4B,CAAC,MAAM,CAAC,IACvE,CAAC,SAAS,MAAM,EAAE,GACf,CAAC,CAAC,MAAM,CAAC,GACT,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC,CAAA;CAAE,EAAE,GAC5B,CAAC,SAAS,MAAM,GACf,CAAC,GACD,KAAK,GACN,KAAK,CAAC;AACX;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,SAAS,MAAM,EAC5D,QAAQ,EAAE,4BAA4B,CAAC,IAAI,CAAC,GAC1C,0BAA0B,CAAC,IAAI,CAAC,CAkBlC"}
@@ -0,0 +1,27 @@
1
+ import { safeishGetProperty } from "../general/objects.js";
2
+ /**
3
+ * Checks if the expected environment variables are set.
4
+ *
5
+ * @template TKey An expected environment key.
6
+ * @param expected The expected environment variables.
7
+ * @returns A key, value set of the environment variables requested for
8
+ * validation.
9
+ * @throws {TypeError} If an expected environment variable hasn't been set.
10
+ */
11
+ export function checkEnvironmentVariables(expected) {
12
+ const env = process.env.NODE_ENV;
13
+ const result = {};
14
+ for (const variable of expected) {
15
+ const key = (typeof variable === "string" ? variable : variable.name);
16
+ const value = safeishGetProperty(process.env, key);
17
+ if (!value) {
18
+ const message = typeof variable === "string"
19
+ ? `Environment variable ${variable} is not set in ${String(env)} environment`
20
+ : variable.message;
21
+ throw new TypeError(message);
22
+ }
23
+ result[key] = value;
24
+ }
25
+ return result;
26
+ }
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAwB3D;;;;;;;;GAQG;AACH,MAAM,UAAU,yBAAyB,CACxC,QAA4C;IAE5C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IACjC,MAAM,MAAM,GAA8C,EAAE,CAAC;IAC7D,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,CACX,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CACd,CAAC;QAC3C,MAAM,KAAK,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnD,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,MAAM,OAAO,GACZ,OAAO,QAAQ,KAAK,QAAQ;gBAC3B,CAAC,CAAC,wBAAwB,QAAQ,kBAAkB,MAAM,CAAC,GAAG,CAAC,cAAc;gBAC7E,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;YACrB,MAAM,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACrB,CAAC;IACD,OAAO,MAA0C,CAAC;AACnD,CAAC","sourcesContent":["import { safeishGetProperty } from \"../general/objects.js\";\n\nexport type ExpectedEnvironmentSuccess<TKey extends string> = Record<\n\tExtractVariableNames<ExpectedEnvironmentVariables<TKey>>,\n\tstring\n>;\n\n/**\n * The expected environment variables.\n *\n * @template TKey An expected environment key.\n */\nexport type ExpectedEnvironmentVariables<TKey extends string> =\n\t| TKey[]\n\t| { message: string; name: TKey }[];\n\ntype ExtractVariableNames<T extends ExpectedEnvironmentVariables<string>> =\n\tT extends string[]\n\t\t? T[number]\n\t\t: T extends { name: infer N }[]\n\t\t\t? N extends string\n\t\t\t\t? N\n\t\t\t\t: never\n\t\t\t: never;\n/**\n * Checks if the expected environment variables are set.\n *\n * @template TKey An expected environment key.\n * @param expected The expected environment variables.\n * @returns A key, value set of the environment variables requested for\n * validation.\n * @throws {TypeError} If an expected environment variable hasn't been set.\n */\nexport function checkEnvironmentVariables<TKey extends string>(\n\texpected: ExpectedEnvironmentVariables<TKey>,\n): ExpectedEnvironmentSuccess<TKey> {\n\tconst env = process.env.NODE_ENV;\n\tconst result: Partial<ExpectedEnvironmentSuccess<TKey>> = {};\n\tfor (const variable of expected) {\n\t\tconst key = (\n\t\t\ttypeof variable === \"string\" ? variable : variable.name\n\t\t) as ExtractVariableNames<typeof expected>;\n\t\tconst value = safeishGetProperty(process.env, key);\n\t\tif (!value) {\n\t\t\tconst message =\n\t\t\t\ttypeof variable === \"string\"\n\t\t\t\t\t? `Environment variable ${variable} is not set in ${String(env)} environment`\n\t\t\t\t\t: variable.message;\n\t\t\tthrow new TypeError(message);\n\t\t}\n\t\tresult[key] = value;\n\t}\n\treturn result as ExpectedEnvironmentSuccess<TKey>;\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@rootreeweb/js-lib",
3
+ "version": "4.0.10",
4
+ "description": "A collection of useful JavaScript functions",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/rootreeweb/rt-js-lib.git"
8
+ },
9
+ "sideEffects": false,
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/esm/index.d.ts",
15
+ "default": "./dist/esm/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/esm/index.d.ts",
19
+ "default": "./dist/cjs/index.cjs"
20
+ }
21
+ }
22
+ },
23
+ "types": "./dist/esm/index.d.ts",
24
+ "files": [
25
+ "dist/**/*"
26
+ ],
27
+ "scripts": {
28
+ "build": "yarn run clean && yarn run build:esm & yarn run build:cjs",
29
+ "build:cjs": "tsc -p ./configs/tsconfig.cjs.json && yarn dlx -p @rootreeweb/rt-node-lib 'rename-cjs'",
30
+ "build:esm": "tsc -p ./configs/tsconfig.esm.json",
31
+ "check": "tsc --noEmit",
32
+ "clean": "del-cli ./dist",
33
+ "format": "prettier . --ignore-path .gitignore --write --cache",
34
+ "lint": "eslint --fix --cache",
35
+ "prepare": "husky",
36
+ "release": "yarn dlx -p @rootreeweb/rt-node-lib release ${0}",
37
+ "test": "vitest run --coverage",
38
+ "test:watch": "vitest --coverage --ui"
39
+ },
40
+ "release": {
41
+ "branches": [
42
+ "main"
43
+ ]
44
+ },
45
+ "devDependencies": {
46
+ "@rootreeweb/linting": "^4.2.1",
47
+ "@rootreeweb/tsconfigs": "^3.3.8",
48
+ "@types/jsdom": "^28.0.3",
49
+ "@vitest/coverage-v8": "^4.1.7",
50
+ "@vitest/ui": "^4.1.7",
51
+ "del-cli": "^7.0.0",
52
+ "eslint": "^10.4.0",
53
+ "husky": "^9.1.7",
54
+ "jsdom": "^29.1.1",
55
+ "knip": "^6.14.2",
56
+ "lint-staged": "^17.0.5",
57
+ "prettier": "^3.8.3",
58
+ "typescript": "^6.0.3",
59
+ "vitest": "^4.1.7"
60
+ },
61
+ "packageManager": "yarn@4.15.0"
62
+ }