ts-data-forge 1.0.0 → 1.0.1

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 (292) hide show
  1. package/README.md +1 -1
  2. package/dist/array/array-utils.d.mts +2617 -0
  3. package/dist/array/array-utils.d.mts.map +1 -0
  4. package/dist/array/array-utils.mjs +2915 -0
  5. package/dist/array/array-utils.mjs.map +1 -0
  6. package/dist/array/index.d.mts +3 -0
  7. package/dist/array/index.d.mts.map +1 -0
  8. package/dist/array/index.mjs +3 -0
  9. package/dist/array/index.mjs.map +1 -0
  10. package/dist/array/tuple-utils.d.mts +421 -0
  11. package/dist/array/tuple-utils.d.mts.map +1 -0
  12. package/dist/array/tuple-utils.mjs +391 -0
  13. package/dist/array/tuple-utils.mjs.map +1 -0
  14. package/dist/collections/imap-mapped.d.mts +445 -0
  15. package/dist/collections/imap-mapped.d.mts.map +1 -0
  16. package/dist/collections/imap-mapped.mjs +424 -0
  17. package/dist/collections/imap-mapped.mjs.map +1 -0
  18. package/dist/collections/imap.d.mts +359 -0
  19. package/dist/collections/imap.d.mts.map +1 -0
  20. package/dist/collections/imap.mjs +338 -0
  21. package/dist/collections/imap.mjs.map +1 -0
  22. package/dist/collections/index.d.mts +7 -0
  23. package/dist/collections/index.d.mts.map +1 -0
  24. package/dist/collections/index.mjs +7 -0
  25. package/dist/collections/index.mjs.map +1 -0
  26. package/dist/collections/iset-mapped.d.mts +576 -0
  27. package/dist/collections/iset-mapped.d.mts.map +1 -0
  28. package/dist/collections/iset-mapped.mjs +522 -0
  29. package/dist/collections/iset-mapped.mjs.map +1 -0
  30. package/dist/collections/iset.d.mts +426 -0
  31. package/dist/collections/iset.d.mts.map +1 -0
  32. package/dist/collections/iset.mjs +437 -0
  33. package/dist/collections/iset.mjs.map +1 -0
  34. package/dist/collections/queue.d.mts +190 -0
  35. package/dist/collections/queue.d.mts.map +1 -0
  36. package/dist/collections/queue.mjs +317 -0
  37. package/dist/collections/queue.mjs.map +1 -0
  38. package/dist/collections/stack.d.mts +210 -0
  39. package/dist/collections/stack.d.mts.map +1 -0
  40. package/dist/collections/stack.mjs +353 -0
  41. package/dist/collections/stack.mjs.map +1 -0
  42. package/dist/expect-type.d.mts +199 -0
  43. package/dist/expect-type.d.mts.map +1 -0
  44. package/dist/expect-type.mjs +201 -0
  45. package/dist/expect-type.mjs.map +1 -0
  46. package/dist/functional/index.d.mts +5 -0
  47. package/dist/functional/index.d.mts.map +1 -0
  48. package/dist/functional/index.mjs +5 -0
  49. package/dist/functional/index.mjs.map +1 -0
  50. package/dist/functional/match.d.mts +215 -0
  51. package/dist/functional/match.d.mts.map +1 -0
  52. package/dist/functional/match.mjs +139 -0
  53. package/dist/functional/match.mjs.map +1 -0
  54. package/dist/functional/optional.d.mts +517 -0
  55. package/dist/functional/optional.d.mts.map +1 -0
  56. package/dist/functional/optional.mjs +532 -0
  57. package/dist/functional/optional.mjs.map +1 -0
  58. package/dist/functional/pipe.d.mts +185 -0
  59. package/dist/functional/pipe.d.mts.map +1 -0
  60. package/dist/functional/pipe.mjs +129 -0
  61. package/dist/functional/pipe.mjs.map +1 -0
  62. package/dist/functional/result.d.mts +796 -0
  63. package/dist/functional/result.d.mts.map +1 -0
  64. package/dist/functional/result.mjs +844 -0
  65. package/dist/functional/result.mjs.map +1 -0
  66. package/dist/globals.d.mts +38 -0
  67. package/dist/guard/has-key.d.mts +100 -0
  68. package/dist/guard/has-key.d.mts.map +1 -0
  69. package/dist/guard/has-key.mjs +94 -0
  70. package/dist/guard/has-key.mjs.map +1 -0
  71. package/dist/guard/index.d.mts +8 -0
  72. package/dist/guard/index.d.mts.map +1 -0
  73. package/dist/guard/index.mjs +8 -0
  74. package/dist/guard/index.mjs.map +1 -0
  75. package/dist/guard/is-non-empty-string.d.mts +106 -0
  76. package/dist/guard/is-non-empty-string.d.mts.map +1 -0
  77. package/dist/guard/is-non-empty-string.mjs +108 -0
  78. package/dist/guard/is-non-empty-string.mjs.map +1 -0
  79. package/dist/guard/is-non-null-object.d.mts +105 -0
  80. package/dist/guard/is-non-null-object.d.mts.map +1 -0
  81. package/dist/guard/is-non-null-object.mjs +108 -0
  82. package/dist/guard/is-non-null-object.mjs.map +1 -0
  83. package/dist/guard/is-primitive.d.mts +146 -0
  84. package/dist/guard/is-primitive.d.mts.map +1 -0
  85. package/dist/guard/is-primitive.mjs +161 -0
  86. package/dist/guard/is-primitive.mjs.map +1 -0
  87. package/dist/guard/is-record.d.mts +151 -0
  88. package/dist/guard/is-record.d.mts.map +1 -0
  89. package/dist/guard/is-record.mjs +155 -0
  90. package/dist/guard/is-record.mjs.map +1 -0
  91. package/dist/guard/is-type.d.mts +430 -0
  92. package/dist/guard/is-type.d.mts.map +1 -0
  93. package/dist/guard/is-type.mjs +432 -0
  94. package/dist/guard/is-type.mjs.map +1 -0
  95. package/dist/guard/key-is-in.d.mts +158 -0
  96. package/dist/guard/key-is-in.d.mts.map +1 -0
  97. package/dist/guard/key-is-in.mjs +160 -0
  98. package/dist/guard/key-is-in.mjs.map +1 -0
  99. package/dist/index.d.mts +11 -0
  100. package/dist/index.d.mts.map +1 -0
  101. package/dist/index.mjs +61 -0
  102. package/dist/index.mjs.map +1 -0
  103. package/dist/iterator/index.d.mts +2 -0
  104. package/dist/iterator/index.d.mts.map +1 -0
  105. package/dist/iterator/index.mjs +2 -0
  106. package/dist/iterator/index.mjs.map +1 -0
  107. package/dist/iterator/range.d.mts +97 -0
  108. package/dist/iterator/range.d.mts.map +1 -0
  109. package/dist/iterator/range.mjs +130 -0
  110. package/dist/iterator/range.mjs.map +1 -0
  111. package/dist/json/index.d.mts +2 -0
  112. package/dist/json/index.d.mts.map +1 -0
  113. package/dist/json/index.mjs +2 -0
  114. package/dist/json/index.mjs.map +1 -0
  115. package/dist/json/json.d.mts +597 -0
  116. package/dist/json/json.d.mts.map +1 -0
  117. package/dist/json/json.mjs +687 -0
  118. package/dist/json/json.mjs.map +1 -0
  119. package/dist/number/branded-types/finite-number.d.mts +291 -0
  120. package/dist/number/branded-types/finite-number.d.mts.map +1 -0
  121. package/dist/number/branded-types/finite-number.mjs +296 -0
  122. package/dist/number/branded-types/finite-number.mjs.map +1 -0
  123. package/dist/number/branded-types/index.d.mts +27 -0
  124. package/dist/number/branded-types/index.d.mts.map +1 -0
  125. package/dist/number/branded-types/index.mjs +27 -0
  126. package/dist/number/branded-types/index.mjs.map +1 -0
  127. package/dist/number/branded-types/int.d.mts +242 -0
  128. package/dist/number/branded-types/int.d.mts.map +1 -0
  129. package/dist/number/branded-types/int.mjs +239 -0
  130. package/dist/number/branded-types/int.mjs.map +1 -0
  131. package/dist/number/branded-types/int16.d.mts +162 -0
  132. package/dist/number/branded-types/int16.d.mts.map +1 -0
  133. package/dist/number/branded-types/int16.mjs +141 -0
  134. package/dist/number/branded-types/int16.mjs.map +1 -0
  135. package/dist/number/branded-types/int32.d.mts +155 -0
  136. package/dist/number/branded-types/int32.d.mts.map +1 -0
  137. package/dist/number/branded-types/int32.mjs +142 -0
  138. package/dist/number/branded-types/int32.mjs.map +1 -0
  139. package/dist/number/branded-types/non-negative-finite-number.d.mts +165 -0
  140. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -0
  141. package/dist/number/branded-types/non-negative-finite-number.mjs +160 -0
  142. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -0
  143. package/dist/number/branded-types/non-negative-int16.d.mts +160 -0
  144. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -0
  145. package/dist/number/branded-types/non-negative-int16.mjs +138 -0
  146. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -0
  147. package/dist/number/branded-types/non-negative-int32.d.mts +156 -0
  148. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -0
  149. package/dist/number/branded-types/non-negative-int32.mjs +138 -0
  150. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -0
  151. package/dist/number/branded-types/non-zero-finite-number.d.mts +154 -0
  152. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -0
  153. package/dist/number/branded-types/non-zero-finite-number.mjs +160 -0
  154. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -0
  155. package/dist/number/branded-types/non-zero-int.d.mts +131 -0
  156. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -0
  157. package/dist/number/branded-types/non-zero-int.mjs +128 -0
  158. package/dist/number/branded-types/non-zero-int.mjs.map +1 -0
  159. package/dist/number/branded-types/non-zero-int16.d.mts +166 -0
  160. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -0
  161. package/dist/number/branded-types/non-zero-int16.mjs +145 -0
  162. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -0
  163. package/dist/number/branded-types/non-zero-int32.d.mts +158 -0
  164. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -0
  165. package/dist/number/branded-types/non-zero-int32.mjs +145 -0
  166. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -0
  167. package/dist/number/branded-types/non-zero-safe-int.d.mts +148 -0
  168. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -0
  169. package/dist/number/branded-types/non-zero-safe-int.mjs +145 -0
  170. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -0
  171. package/dist/number/branded-types/non-zero-uint16.d.mts +160 -0
  172. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -0
  173. package/dist/number/branded-types/non-zero-uint16.mjs +140 -0
  174. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -0
  175. package/dist/number/branded-types/non-zero-uint32.d.mts +156 -0
  176. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -0
  177. package/dist/number/branded-types/non-zero-uint32.mjs +140 -0
  178. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -0
  179. package/dist/number/branded-types/positive-finite-number.d.mts +171 -0
  180. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -0
  181. package/dist/number/branded-types/positive-finite-number.mjs +165 -0
  182. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -0
  183. package/dist/number/branded-types/positive-int.d.mts +270 -0
  184. package/dist/number/branded-types/positive-int.d.mts.map +1 -0
  185. package/dist/number/branded-types/positive-int.mjs +257 -0
  186. package/dist/number/branded-types/positive-int.mjs.map +1 -0
  187. package/dist/number/branded-types/positive-int16.d.mts +162 -0
  188. package/dist/number/branded-types/positive-int16.d.mts.map +1 -0
  189. package/dist/number/branded-types/positive-int16.mjs +139 -0
  190. package/dist/number/branded-types/positive-int16.mjs.map +1 -0
  191. package/dist/number/branded-types/positive-int32.d.mts +158 -0
  192. package/dist/number/branded-types/positive-int32.d.mts.map +1 -0
  193. package/dist/number/branded-types/positive-int32.mjs +139 -0
  194. package/dist/number/branded-types/positive-int32.mjs.map +1 -0
  195. package/dist/number/branded-types/positive-safe-int.d.mts +152 -0
  196. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -0
  197. package/dist/number/branded-types/positive-safe-int.mjs +138 -0
  198. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -0
  199. package/dist/number/branded-types/positive-uint16.d.mts +160 -0
  200. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -0
  201. package/dist/number/branded-types/positive-uint16.mjs +139 -0
  202. package/dist/number/branded-types/positive-uint16.mjs.map +1 -0
  203. package/dist/number/branded-types/positive-uint32.d.mts +156 -0
  204. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -0
  205. package/dist/number/branded-types/positive-uint32.mjs +139 -0
  206. package/dist/number/branded-types/positive-uint32.mjs.map +1 -0
  207. package/dist/number/branded-types/safe-int.d.mts +243 -0
  208. package/dist/number/branded-types/safe-int.d.mts.map +1 -0
  209. package/dist/number/branded-types/safe-int.mjs +240 -0
  210. package/dist/number/branded-types/safe-int.mjs.map +1 -0
  211. package/dist/number/branded-types/safe-uint.d.mts +151 -0
  212. package/dist/number/branded-types/safe-uint.d.mts.map +1 -0
  213. package/dist/number/branded-types/safe-uint.mjs +138 -0
  214. package/dist/number/branded-types/safe-uint.mjs.map +1 -0
  215. package/dist/number/branded-types/uint.d.mts +144 -0
  216. package/dist/number/branded-types/uint.d.mts.map +1 -0
  217. package/dist/number/branded-types/uint.mjs +132 -0
  218. package/dist/number/branded-types/uint.mjs.map +1 -0
  219. package/dist/number/branded-types/uint16.d.mts +157 -0
  220. package/dist/number/branded-types/uint16.d.mts.map +1 -0
  221. package/dist/number/branded-types/uint16.mjs +137 -0
  222. package/dist/number/branded-types/uint16.mjs.map +1 -0
  223. package/dist/number/branded-types/uint32.d.mts +185 -0
  224. package/dist/number/branded-types/uint32.d.mts.map +1 -0
  225. package/dist/number/branded-types/uint32.mjs +169 -0
  226. package/dist/number/branded-types/uint32.mjs.map +1 -0
  227. package/dist/number/enum/index.d.mts +3 -0
  228. package/dist/number/enum/index.d.mts.map +1 -0
  229. package/dist/number/enum/index.mjs +3 -0
  230. package/dist/number/enum/index.mjs.map +1 -0
  231. package/dist/number/enum/int8.d.mts +202 -0
  232. package/dist/number/enum/int8.d.mts.map +1 -0
  233. package/dist/number/enum/int8.mjs +296 -0
  234. package/dist/number/enum/int8.mjs.map +1 -0
  235. package/dist/number/enum/uint8.d.mts +128 -0
  236. package/dist/number/enum/uint8.d.mts.map +1 -0
  237. package/dist/number/enum/uint8.mjs +251 -0
  238. package/dist/number/enum/uint8.mjs.map +1 -0
  239. package/dist/number/index.d.mts +5 -0
  240. package/dist/number/index.d.mts.map +1 -0
  241. package/dist/number/index.mjs +31 -0
  242. package/dist/number/index.mjs.map +1 -0
  243. package/dist/number/num.d.mts +515 -0
  244. package/dist/number/num.d.mts.map +1 -0
  245. package/dist/number/num.mjs +513 -0
  246. package/dist/number/num.mjs.map +1 -0
  247. package/dist/number/refined-number-utils.d.mts +191 -0
  248. package/dist/number/refined-number-utils.d.mts.map +1 -0
  249. package/dist/number/refined-number-utils.mjs +179 -0
  250. package/dist/number/refined-number-utils.mjs.map +1 -0
  251. package/dist/object/index.d.mts +2 -0
  252. package/dist/object/index.d.mts.map +1 -0
  253. package/dist/object/index.mjs +2 -0
  254. package/dist/object/index.mjs.map +1 -0
  255. package/dist/object/object.d.mts +296 -0
  256. package/dist/object/object.d.mts.map +1 -0
  257. package/dist/object/object.mjs +295 -0
  258. package/dist/object/object.mjs.map +1 -0
  259. package/dist/others/cast-mutable.d.mts +110 -0
  260. package/dist/others/cast-mutable.d.mts.map +1 -0
  261. package/dist/others/cast-mutable.mjs +114 -0
  262. package/dist/others/cast-mutable.mjs.map +1 -0
  263. package/dist/others/cast-readonly.d.mts +189 -0
  264. package/dist/others/cast-readonly.d.mts.map +1 -0
  265. package/dist/others/cast-readonly.mjs +193 -0
  266. package/dist/others/cast-readonly.mjs.map +1 -0
  267. package/dist/others/if-then.d.mts +98 -0
  268. package/dist/others/if-then.d.mts.map +1 -0
  269. package/dist/others/if-then.mjs +100 -0
  270. package/dist/others/if-then.mjs.map +1 -0
  271. package/dist/others/index.d.mts +8 -0
  272. package/dist/others/index.d.mts.map +1 -0
  273. package/dist/others/index.mjs +8 -0
  274. package/dist/others/index.mjs.map +1 -0
  275. package/dist/others/map-nullable.d.mts +151 -0
  276. package/dist/others/map-nullable.d.mts.map +1 -0
  277. package/dist/others/map-nullable.mjs +159 -0
  278. package/dist/others/map-nullable.mjs.map +1 -0
  279. package/dist/others/memoize-function.d.mts +173 -0
  280. package/dist/others/memoize-function.d.mts.map +1 -0
  281. package/dist/others/memoize-function.mjs +189 -0
  282. package/dist/others/memoize-function.mjs.map +1 -0
  283. package/dist/others/tuple.d.mts +159 -0
  284. package/dist/others/tuple.d.mts.map +1 -0
  285. package/dist/others/tuple.mjs +161 -0
  286. package/dist/others/tuple.mjs.map +1 -0
  287. package/dist/others/unknown-to-string.d.mts +180 -0
  288. package/dist/others/unknown-to-string.d.mts.map +1 -0
  289. package/dist/others/unknown-to-string.mjs +211 -0
  290. package/dist/others/unknown-to-string.mjs.map +1 -0
  291. package/dist/tsconfig.json +1 -0
  292. package/package.json +16 -14
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Type guard that checks if a value is a non-null object.
3
+ *
4
+ * This function checks if a value has type `"object"` according to the `typeof` operator
5
+ * and is not `null`. This includes all object types such as plain objects, arrays, dates,
6
+ * regular expressions, and other object instances, but excludes functions.
7
+ *
8
+ * **Type Narrowing Behavior:**
9
+ * - Narrows `unknown` to `object`
10
+ * - Excludes `null`, `undefined`, and all primitive types
11
+ * - Excludes functions (they have `typeof` === `"function"`, not `"object"`)
12
+ * - Includes arrays, dates, regex, and other object instances
13
+ *
14
+ * **Note:** This function returns `true` for arrays. If you need to check for plain objects
15
+ * specifically (excluding arrays), use `isRecord()` instead.
16
+ *
17
+ * @param u - The value to check
18
+ * @returns `true` if `u` is an object and not `null`, `false` otherwise.
19
+ * When `true`, TypeScript narrows the type to `object`.
20
+ *
21
+ * @example
22
+ * Basic usage with different value types:
23
+ * ```typescript
24
+ * isNonNullObject({}); // true (plain object)
25
+ * isNonNullObject([]); // true (arrays are objects)
26
+ * isNonNullObject(new Date()); // true (Date instance)
27
+ * isNonNullObject(/regex/); // true (RegExp instance)
28
+ * isNonNullObject(new Map()); // true (Map instance)
29
+ * isNonNullObject(null); // false (null is not considered object here)
30
+ * isNonNullObject(undefined); // false (primitive)
31
+ * isNonNullObject("string"); // false (primitive)
32
+ * isNonNullObject(42); // false (primitive)
33
+ * isNonNullObject(true); // false (primitive)
34
+ * isNonNullObject(() => {}); // false (functions are not objects in this context)
35
+ * ```
36
+ *
37
+ * @example
38
+ * Type guard usage with unknown values:
39
+ * ```typescript
40
+ * const value: unknown = parseJsonData();
41
+ *
42
+ * if (isNonNullObject(value)) {
43
+ * // value is now typed as object
44
+ * console.log('Value is an object');
45
+ *
46
+ * // You can now safely use object-specific operations
47
+ * console.log(Object.keys(value)); // Safe to call Object.keys
48
+ * console.log(value.toString()); // Safe to call methods
49
+ *
50
+ * // But you may need additional checks for specific object types
51
+ * if (Array.isArray(value)) {
52
+ * console.log('It\'s an array with length:', value.length);
53
+ * }
54
+ * } else {
55
+ * console.log('Value is not an object');
56
+ * }
57
+ * ```
58
+ *
59
+ * @example
60
+ * Filtering arrays to find objects:
61
+ * ```typescript
62
+ * const mixedArray: unknown[] = [
63
+ * { name: 'John' },
64
+ * 'string',
65
+ * [1, 2, 3],
66
+ * 42,
67
+ * null,
68
+ * new Date(),
69
+ * () => 'function'
70
+ * ];
71
+ *
72
+ * const objects = mixedArray.filter(isNonNullObject);
73
+ * // objects contains: [{ name: 'John' }, [1, 2, 3], Date instance]
74
+ * // Note: includes both plain objects and arrays
75
+ *
76
+ * objects.forEach(obj => {
77
+ * // Each obj is guaranteed to be an object
78
+ * console.log('Object type:', obj.constructor.name);
79
+ * });
80
+ * ```
81
+ *
82
+ * @example
83
+ * Progressive type narrowing with other guards:
84
+ * ```typescript
85
+ * const apiResponse: unknown = await fetchData();
86
+ *
87
+ * if (isNonNullObject(apiResponse)) {
88
+ * // apiResponse is now object
89
+ *
90
+ * if (isRecord(apiResponse)) {
91
+ * // Further narrowed to UnknownRecord (plain object, not array)
92
+ *
93
+ * if (hasKey(apiResponse, 'status')) {
94
+ * console.log('API status:', apiResponse.status);
95
+ * }
96
+ * } else if (Array.isArray(apiResponse)) {
97
+ * console.log('Response is an array with length:', apiResponse.length);
98
+ * }
99
+ * }
100
+ * ```
101
+ *
102
+ * @see {@link isRecord} - For checking plain objects specifically (excludes arrays)
103
+ */
104
+ // eslint-disable-next-line @typescript-eslint/no-restricted-types
105
+ const isNonNullObject = (u) => typeof u === 'object' && u !== null;
106
+
107
+ export { isNonNullObject };
108
+ //# sourceMappingURL=is-non-null-object.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-non-null-object.mjs","sources":["../../src/guard/is-non-null-object.mts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGG;AACH;AACO,MAAM,eAAe,GAAG,CAAC,CAAU,KACxC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK;;;;"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Type guard that checks if a value is a primitive type.
3
+ *
4
+ * This function identifies JavaScript primitive types, which are immutable data types that are
5
+ * not objects. The primitive types are: `string`, `number`, `boolean`, `undefined`, `symbol`,
6
+ * `bigint`, and `null`.
7
+ *
8
+ * **Important Note:** Although `null` has `typeof null === "object"` due to a historical
9
+ * JavaScript quirk, this function correctly identifies `null` as a primitive value.
10
+ *
11
+ * **Type Narrowing Behavior:**
12
+ * - Narrows the input type to `Primitive` (union of all primitive types)
13
+ * - Excludes object types, arrays, functions, and other non-primitive values
14
+ * - Includes `null` despite its misleading `typeof` result
15
+ *
16
+ * @param u - The value to check
17
+ * @returns `true` if `u` is a primitive type, `false` otherwise.
18
+ * When `true`, TypeScript narrows the type to `Primitive`.
19
+ *
20
+ * @example
21
+ * Basic usage with different value types:
22
+ * ```typescript
23
+ * isPrimitive("hello"); // true (string)
24
+ * isPrimitive(42); // true (number)
25
+ * isPrimitive(true); // true (boolean)
26
+ * isPrimitive(undefined); // true (undefined)
27
+ * isPrimitive(Symbol('test')); // true (symbol)
28
+ * isPrimitive(123n); // true (bigint)
29
+ * isPrimitive(null); // true (null is primitive despite typeof quirk)
30
+ *
31
+ * isPrimitive({}); // false (object)
32
+ * isPrimitive([]); // false (array)
33
+ * isPrimitive(() => {}); // false (function)
34
+ * isPrimitive(new Date()); // false (object instance)
35
+ * isPrimitive(/regex/); // false (RegExp object)
36
+ * ```
37
+ *
38
+ * @example
39
+ * Type guard usage for separating primitives from objects:
40
+ * ```typescript
41
+ * const values: unknown[] = [
42
+ * 'string',
43
+ * 42,
44
+ * true,
45
+ * null,
46
+ * undefined,
47
+ * {},
48
+ * [],
49
+ * new Date()
50
+ * ];
51
+ *
52
+ * const primitives = values.filter(isPrimitive);
53
+ * const objects = values.filter(value => !isPrimitive(value));
54
+ *
55
+ * primitives.forEach(primitive => {
56
+ * // primitive is now typed as Primitive
57
+ * console.log('Primitive value:', primitive);
58
+ * console.log('Type:', typeof primitive);
59
+ * });
60
+ * ```
61
+ *
62
+ * @example
63
+ * Deep cloning detection - primitives don't need cloning:
64
+ * ```typescript
65
+ * function deepClone<T>(value: T): T {
66
+ * if (isPrimitive(value)) {
67
+ * // Primitives are immutable, return as-is
68
+ * return value;
69
+ * }
70
+ *
71
+ * // Handle object cloning for non-primitives
72
+ * if (Array.isArray(value)) {
73
+ * return value.map(deepClone) as T;
74
+ * }
75
+ *
76
+ * if (isRecord(value)) {
77
+ * const cloned = {} as T;
78
+ * for (const key in value) {
79
+ * if (Object.hasOwn(value, key)) {
80
+ * cloned[key] = deepClone(value[key]);
81
+ * }
82
+ * }
83
+ * return cloned;
84
+ * }
85
+ *
86
+ * // For other object types, return as-is or implement specific cloning
87
+ * return value;
88
+ * }
89
+ * ```
90
+ *
91
+ * @example
92
+ * Serialization helpers:
93
+ * ```typescript
94
+ * function canSerializeDirectly(value: unknown): boolean {
95
+ * if (isPrimitive(value)) {
96
+ * // Most primitives can be serialized directly
97
+ * return typeof value !== 'symbol' && typeof value !== 'bigint';
98
+ * }
99
+ * return false;
100
+ * }
101
+ *
102
+ * function safeStringify(value: unknown): string {
103
+ * if (isPrimitive(value)) {
104
+ * if (value === null) return 'null';
105
+ * if (value === undefined) return 'undefined';
106
+ * if (typeof value === 'symbol') return value.toString();
107
+ * if (typeof value === 'bigint') return value.toString() + 'n';
108
+ * return String(value);
109
+ * }
110
+ *
111
+ * return JSON.stringify(value);
112
+ * }
113
+ * ```
114
+ *
115
+ * @example
116
+ * Type narrowing in conditional logic:
117
+ * ```typescript
118
+ * function processValue(value: unknown): string {
119
+ * if (isPrimitive(value)) {
120
+ * // value is now Primitive type
121
+ * switch (typeof value) {
122
+ * case 'string':
123
+ * return `String: ${value}`;
124
+ * case 'number':
125
+ * return `Number: ${value}`;
126
+ * case 'boolean':
127
+ * return `Boolean: ${value}`;
128
+ * case 'undefined':
129
+ * return 'Undefined';
130
+ * case 'symbol':
131
+ * return `Symbol: ${value.description || 'unnamed'}`;
132
+ * case 'bigint':
133
+ * return `BigInt: ${value}n`;
134
+ * case 'object': // This is null
135
+ * return 'Null';
136
+ * default:
137
+ * return 'Unknown primitive';
138
+ * }
139
+ * } else {
140
+ * return `Object: ${value?.constructor?.name || 'Unknown'}`;
141
+ * }
142
+ * }
143
+ * ```
144
+ */
145
+ export declare const isPrimitive: (u: unknown) => u is Primitive;
146
+ //# sourceMappingURL=is-primitive.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-primitive.d.mts","sourceRoot":"","sources":["../../src/guard/is-primitive.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+IG;AACH,eAAO,MAAM,WAAW,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,SAa7C,CAAC"}
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Type guard that checks if a value is a primitive type.
3
+ *
4
+ * This function identifies JavaScript primitive types, which are immutable data types that are
5
+ * not objects. The primitive types are: `string`, `number`, `boolean`, `undefined`, `symbol`,
6
+ * `bigint`, and `null`.
7
+ *
8
+ * **Important Note:** Although `null` has `typeof null === "object"` due to a historical
9
+ * JavaScript quirk, this function correctly identifies `null` as a primitive value.
10
+ *
11
+ * **Type Narrowing Behavior:**
12
+ * - Narrows the input type to `Primitive` (union of all primitive types)
13
+ * - Excludes object types, arrays, functions, and other non-primitive values
14
+ * - Includes `null` despite its misleading `typeof` result
15
+ *
16
+ * @param u - The value to check
17
+ * @returns `true` if `u` is a primitive type, `false` otherwise.
18
+ * When `true`, TypeScript narrows the type to `Primitive`.
19
+ *
20
+ * @example
21
+ * Basic usage with different value types:
22
+ * ```typescript
23
+ * isPrimitive("hello"); // true (string)
24
+ * isPrimitive(42); // true (number)
25
+ * isPrimitive(true); // true (boolean)
26
+ * isPrimitive(undefined); // true (undefined)
27
+ * isPrimitive(Symbol('test')); // true (symbol)
28
+ * isPrimitive(123n); // true (bigint)
29
+ * isPrimitive(null); // true (null is primitive despite typeof quirk)
30
+ *
31
+ * isPrimitive({}); // false (object)
32
+ * isPrimitive([]); // false (array)
33
+ * isPrimitive(() => {}); // false (function)
34
+ * isPrimitive(new Date()); // false (object instance)
35
+ * isPrimitive(/regex/); // false (RegExp object)
36
+ * ```
37
+ *
38
+ * @example
39
+ * Type guard usage for separating primitives from objects:
40
+ * ```typescript
41
+ * const values: unknown[] = [
42
+ * 'string',
43
+ * 42,
44
+ * true,
45
+ * null,
46
+ * undefined,
47
+ * {},
48
+ * [],
49
+ * new Date()
50
+ * ];
51
+ *
52
+ * const primitives = values.filter(isPrimitive);
53
+ * const objects = values.filter(value => !isPrimitive(value));
54
+ *
55
+ * primitives.forEach(primitive => {
56
+ * // primitive is now typed as Primitive
57
+ * console.log('Primitive value:', primitive);
58
+ * console.log('Type:', typeof primitive);
59
+ * });
60
+ * ```
61
+ *
62
+ * @example
63
+ * Deep cloning detection - primitives don't need cloning:
64
+ * ```typescript
65
+ * function deepClone<T>(value: T): T {
66
+ * if (isPrimitive(value)) {
67
+ * // Primitives are immutable, return as-is
68
+ * return value;
69
+ * }
70
+ *
71
+ * // Handle object cloning for non-primitives
72
+ * if (Array.isArray(value)) {
73
+ * return value.map(deepClone) as T;
74
+ * }
75
+ *
76
+ * if (isRecord(value)) {
77
+ * const cloned = {} as T;
78
+ * for (const key in value) {
79
+ * if (Object.hasOwn(value, key)) {
80
+ * cloned[key] = deepClone(value[key]);
81
+ * }
82
+ * }
83
+ * return cloned;
84
+ * }
85
+ *
86
+ * // For other object types, return as-is or implement specific cloning
87
+ * return value;
88
+ * }
89
+ * ```
90
+ *
91
+ * @example
92
+ * Serialization helpers:
93
+ * ```typescript
94
+ * function canSerializeDirectly(value: unknown): boolean {
95
+ * if (isPrimitive(value)) {
96
+ * // Most primitives can be serialized directly
97
+ * return typeof value !== 'symbol' && typeof value !== 'bigint';
98
+ * }
99
+ * return false;
100
+ * }
101
+ *
102
+ * function safeStringify(value: unknown): string {
103
+ * if (isPrimitive(value)) {
104
+ * if (value === null) return 'null';
105
+ * if (value === undefined) return 'undefined';
106
+ * if (typeof value === 'symbol') return value.toString();
107
+ * if (typeof value === 'bigint') return value.toString() + 'n';
108
+ * return String(value);
109
+ * }
110
+ *
111
+ * return JSON.stringify(value);
112
+ * }
113
+ * ```
114
+ *
115
+ * @example
116
+ * Type narrowing in conditional logic:
117
+ * ```typescript
118
+ * function processValue(value: unknown): string {
119
+ * if (isPrimitive(value)) {
120
+ * // value is now Primitive type
121
+ * switch (typeof value) {
122
+ * case 'string':
123
+ * return `String: ${value}`;
124
+ * case 'number':
125
+ * return `Number: ${value}`;
126
+ * case 'boolean':
127
+ * return `Boolean: ${value}`;
128
+ * case 'undefined':
129
+ * return 'Undefined';
130
+ * case 'symbol':
131
+ * return `Symbol: ${value.description || 'unnamed'}`;
132
+ * case 'bigint':
133
+ * return `BigInt: ${value}n`;
134
+ * case 'object': // This is null
135
+ * return 'Null';
136
+ * default:
137
+ * return 'Unknown primitive';
138
+ * }
139
+ * } else {
140
+ * return `Object: ${value?.constructor?.name || 'Unknown'}`;
141
+ * }
142
+ * }
143
+ * ```
144
+ */
145
+ const isPrimitive = (u) => {
146
+ switch (typeof u) {
147
+ case 'string':
148
+ case 'number':
149
+ case 'boolean':
150
+ case 'undefined':
151
+ case 'symbol':
152
+ case 'bigint':
153
+ return true;
154
+ case 'function':
155
+ case 'object':
156
+ return u === null;
157
+ }
158
+ };
159
+
160
+ export { isPrimitive };
161
+ //# sourceMappingURL=is-primitive.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-primitive.mjs","sources":["../../src/guard/is-primitive.mts"],"sourcesContent":[null],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+IG;AACI,MAAM,WAAW,GAAG,CAAC,CAAU,KAAoB;IACxD,QAAQ,OAAO,CAAC;AACd,QAAA,KAAK,QAAQ;AACb,QAAA,KAAK,QAAQ;AACb,QAAA,KAAK,SAAS;AACd,QAAA,KAAK,WAAW;AAChB,QAAA,KAAK,QAAQ;AACb,QAAA,KAAK,QAAQ;AACX,YAAA,OAAO,IAAI;AACb,QAAA,KAAK,UAAU;AACf,QAAA,KAAK,QAAQ;YACX,OAAO,CAAC,KAAK,IAAI;;AAEvB;;;;"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Type guard that checks if a value is a plain object (record) - a non-null object that is not an array.
3
+ *
4
+ * This function is useful for identifying "plain" JavaScript objects (also called records or
5
+ * dictionaries) - objects that are typically used as key-value collections. It excludes arrays,
6
+ * functions, and special object types like Date, RegExp, etc., focusing on objects that can be
7
+ * safely treated as property collections.
8
+ *
9
+ * **Type Narrowing Behavior:**
10
+ * - Narrows `unknown` to `UnknownRecord` (equivalent to `Record<PropertyKey, unknown>`)
11
+ * - Excludes `null`, `undefined`, primitives, arrays, and functions
12
+ * - Returns `true` for plain objects `{}`, object literals, and objects created with `Object.create()`
13
+ * - Returns `false` for arrays, even though they are technically objects
14
+ *
15
+ * **Implementation:** Uses `isNonNullObject()` to check for objects, then `Array.isArray()` to exclude arrays.
16
+ *
17
+ * @param u - The value to check
18
+ * @returns `true` if `u` is a non-null object and not an array, `false` otherwise.
19
+ * When `true`, TypeScript narrows the type to `UnknownRecord`.
20
+ *
21
+ * @example
22
+ * Basic usage with different value types:
23
+ * ```typescript
24
+ * isRecord({}); // true (empty object)
25
+ * isRecord({ name: 'John' }); // true (object literal)
26
+ * isRecord(Object.create(null)); // true (object created with Object.create)
27
+ * isRecord(new Object()); // true (object constructor)
28
+ *
29
+ * isRecord([]); // false (array)
30
+ * isRecord([1, 2, 3]); // false (array with elements)
31
+ * isRecord(null); // false (null)
32
+ * isRecord(undefined); // false (undefined)
33
+ * isRecord("string"); // false (primitive)
34
+ * isRecord(42); // false (primitive)
35
+ * isRecord(() => {}); // false (function)
36
+ * isRecord(new Date()); // false (Date object - not a plain record)
37
+ * isRecord(/regex/); // false (RegExp object)
38
+ * ```
39
+ *
40
+ * @example
41
+ * Type guard usage for safe property access:
42
+ * ```typescript
43
+ * const apiResponse: unknown = await fetchUserData();
44
+ *
45
+ * if (isRecord(apiResponse)) {
46
+ * // apiResponse is now typed as UnknownRecord
47
+ * console.log('Response keys:', Object.keys(apiResponse));
48
+ *
49
+ * // Safe to access properties (though values are still unknown)
50
+ * const userId = apiResponse.id; // Type: unknown
51
+ * const userName = apiResponse.name; // Type: unknown
52
+ *
53
+ * // You can combine with other type guards for further narrowing
54
+ * if (hasKey(apiResponse, 'id') && isString(apiResponse.id)) {
55
+ * console.log('User ID:', apiResponse.id); // Now safely typed as string
56
+ * }
57
+ * } else {
58
+ * console.log('API response is not a valid object');
59
+ * }
60
+ * ```
61
+ *
62
+ * @example
63
+ * Filtering mixed arrays to find plain objects:
64
+ * ```typescript
65
+ * const mixedData: unknown[] = [
66
+ * { type: 'user', name: 'Alice' },
67
+ * [1, 2, 3],
68
+ * 'string',
69
+ * { type: 'admin', permissions: ['read', 'write'] },
70
+ * new Date(),
71
+ * null,
72
+ * { id: 123 }
73
+ * ];
74
+ *
75
+ * const records = mixedData.filter(isRecord);
76
+ * // records contains only the plain objects:
77
+ * // [{ type: 'user', name: 'Alice' }, { type: 'admin', permissions: [...] }, { id: 123 }]
78
+ *
79
+ * records.forEach(record => {
80
+ * // Each record is guaranteed to be UnknownRecord
81
+ * const keys = Object.keys(record);
82
+ * console.log('Object keys:', keys);
83
+ * });
84
+ * ```
85
+ *
86
+ * @example
87
+ * Progressive validation of nested structures:
88
+ * ```typescript
89
+ * interface User {
90
+ * id: string;
91
+ * profile: {
92
+ * name: string;
93
+ * email: string;
94
+ * };
95
+ * }
96
+ *
97
+ * function validateUser(data: unknown): User | null {
98
+ * if (!isRecord(data)) {
99
+ * return null;
100
+ * }
101
+ *
102
+ * // data is now UnknownRecord
103
+ * if (!hasKey(data, 'id') || !isString(data.id)) {
104
+ * return null;
105
+ * }
106
+ *
107
+ * if (!hasKey(data, 'profile') || !isRecord(data.profile)) {
108
+ * return null;
109
+ * }
110
+ *
111
+ * const profile = data.profile;
112
+ * if (!hasKey(profile, 'name') || !isString(profile.name) ||
113
+ * !hasKey(profile, 'email') || !isString(profile.email)) {
114
+ * return null;
115
+ * }
116
+ *
117
+ * return {
118
+ * id: data.id,
119
+ * profile: {
120
+ * name: profile.name,
121
+ * email: profile.email
122
+ * }
123
+ * };
124
+ * }
125
+ * ```
126
+ *
127
+ * @example
128
+ * Object transformation and mapping:
129
+ * ```typescript
130
+ * function transformRecords(data: unknown[]): Record<string, unknown>[] {
131
+ * return data
132
+ * .filter(isRecord) // Keep only plain objects
133
+ * .map(record => {
134
+ * // Transform each record
135
+ * const transformed: Record<string, unknown> = {};
136
+ *
137
+ * for (const [key, value] of Object.entries(record)) {
138
+ * // Apply some transformation logic
139
+ * transformed[key.toLowerCase()] = value;
140
+ * }
141
+ *
142
+ * return transformed;
143
+ * });
144
+ * }
145
+ * ```
146
+ *
147
+ * @see {@link isNonNullObject} - For checking any object type (includes arrays)
148
+ * @see {@link hasKey} - For checking if a record has specific keys
149
+ */
150
+ export declare const isRecord: (u: unknown) => u is UnknownRecord;
151
+ //# sourceMappingURL=is-record.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-record.d.mts","sourceRoot":"","sources":["../../src/guard/is-record.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoJG;AACH,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,aACF,CAAC"}