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,155 @@
1
+ import { isNonNullObject } from './is-non-null-object.mjs';
2
+
3
+ /**
4
+ * Type guard that checks if a value is a plain object (record) - a non-null object that is not an array.
5
+ *
6
+ * This function is useful for identifying "plain" JavaScript objects (also called records or
7
+ * dictionaries) - objects that are typically used as key-value collections. It excludes arrays,
8
+ * functions, and special object types like Date, RegExp, etc., focusing on objects that can be
9
+ * safely treated as property collections.
10
+ *
11
+ * **Type Narrowing Behavior:**
12
+ * - Narrows `unknown` to `UnknownRecord` (equivalent to `Record<PropertyKey, unknown>`)
13
+ * - Excludes `null`, `undefined`, primitives, arrays, and functions
14
+ * - Returns `true` for plain objects `{}`, object literals, and objects created with `Object.create()`
15
+ * - Returns `false` for arrays, even though they are technically objects
16
+ *
17
+ * **Implementation:** Uses `isNonNullObject()` to check for objects, then `Array.isArray()` to exclude arrays.
18
+ *
19
+ * @param u - The value to check
20
+ * @returns `true` if `u` is a non-null object and not an array, `false` otherwise.
21
+ * When `true`, TypeScript narrows the type to `UnknownRecord`.
22
+ *
23
+ * @example
24
+ * Basic usage with different value types:
25
+ * ```typescript
26
+ * isRecord({}); // true (empty object)
27
+ * isRecord({ name: 'John' }); // true (object literal)
28
+ * isRecord(Object.create(null)); // true (object created with Object.create)
29
+ * isRecord(new Object()); // true (object constructor)
30
+ *
31
+ * isRecord([]); // false (array)
32
+ * isRecord([1, 2, 3]); // false (array with elements)
33
+ * isRecord(null); // false (null)
34
+ * isRecord(undefined); // false (undefined)
35
+ * isRecord("string"); // false (primitive)
36
+ * isRecord(42); // false (primitive)
37
+ * isRecord(() => {}); // false (function)
38
+ * isRecord(new Date()); // false (Date object - not a plain record)
39
+ * isRecord(/regex/); // false (RegExp object)
40
+ * ```
41
+ *
42
+ * @example
43
+ * Type guard usage for safe property access:
44
+ * ```typescript
45
+ * const apiResponse: unknown = await fetchUserData();
46
+ *
47
+ * if (isRecord(apiResponse)) {
48
+ * // apiResponse is now typed as UnknownRecord
49
+ * console.log('Response keys:', Object.keys(apiResponse));
50
+ *
51
+ * // Safe to access properties (though values are still unknown)
52
+ * const userId = apiResponse.id; // Type: unknown
53
+ * const userName = apiResponse.name; // Type: unknown
54
+ *
55
+ * // You can combine with other type guards for further narrowing
56
+ * if (hasKey(apiResponse, 'id') && isString(apiResponse.id)) {
57
+ * console.log('User ID:', apiResponse.id); // Now safely typed as string
58
+ * }
59
+ * } else {
60
+ * console.log('API response is not a valid object');
61
+ * }
62
+ * ```
63
+ *
64
+ * @example
65
+ * Filtering mixed arrays to find plain objects:
66
+ * ```typescript
67
+ * const mixedData: unknown[] = [
68
+ * { type: 'user', name: 'Alice' },
69
+ * [1, 2, 3],
70
+ * 'string',
71
+ * { type: 'admin', permissions: ['read', 'write'] },
72
+ * new Date(),
73
+ * null,
74
+ * { id: 123 }
75
+ * ];
76
+ *
77
+ * const records = mixedData.filter(isRecord);
78
+ * // records contains only the plain objects:
79
+ * // [{ type: 'user', name: 'Alice' }, { type: 'admin', permissions: [...] }, { id: 123 }]
80
+ *
81
+ * records.forEach(record => {
82
+ * // Each record is guaranteed to be UnknownRecord
83
+ * const keys = Object.keys(record);
84
+ * console.log('Object keys:', keys);
85
+ * });
86
+ * ```
87
+ *
88
+ * @example
89
+ * Progressive validation of nested structures:
90
+ * ```typescript
91
+ * interface User {
92
+ * id: string;
93
+ * profile: {
94
+ * name: string;
95
+ * email: string;
96
+ * };
97
+ * }
98
+ *
99
+ * function validateUser(data: unknown): User | null {
100
+ * if (!isRecord(data)) {
101
+ * return null;
102
+ * }
103
+ *
104
+ * // data is now UnknownRecord
105
+ * if (!hasKey(data, 'id') || !isString(data.id)) {
106
+ * return null;
107
+ * }
108
+ *
109
+ * if (!hasKey(data, 'profile') || !isRecord(data.profile)) {
110
+ * return null;
111
+ * }
112
+ *
113
+ * const profile = data.profile;
114
+ * if (!hasKey(profile, 'name') || !isString(profile.name) ||
115
+ * !hasKey(profile, 'email') || !isString(profile.email)) {
116
+ * return null;
117
+ * }
118
+ *
119
+ * return {
120
+ * id: data.id,
121
+ * profile: {
122
+ * name: profile.name,
123
+ * email: profile.email
124
+ * }
125
+ * };
126
+ * }
127
+ * ```
128
+ *
129
+ * @example
130
+ * Object transformation and mapping:
131
+ * ```typescript
132
+ * function transformRecords(data: unknown[]): Record<string, unknown>[] {
133
+ * return data
134
+ * .filter(isRecord) // Keep only plain objects
135
+ * .map(record => {
136
+ * // Transform each record
137
+ * const transformed: Record<string, unknown> = {};
138
+ *
139
+ * for (const [key, value] of Object.entries(record)) {
140
+ * // Apply some transformation logic
141
+ * transformed[key.toLowerCase()] = value;
142
+ * }
143
+ *
144
+ * return transformed;
145
+ * });
146
+ * }
147
+ * ```
148
+ *
149
+ * @see {@link isNonNullObject} - For checking any object type (includes arrays)
150
+ * @see {@link hasKey} - For checking if a record has specific keys
151
+ */
152
+ const isRecord = (u) => isNonNullObject(u) && !Array.isArray(u);
153
+
154
+ export { isRecord };
155
+ //# sourceMappingURL=is-record.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-record.mjs","sources":["../../src/guard/is-record.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoJG;MACU,QAAQ,GAAG,CAAC,CAAU,KACjC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;;;;"}
@@ -0,0 +1,430 @@
1
+ /**
2
+ * Type guard that checks if a value is `undefined`.
3
+ *
4
+ * **Type Narrowing Behavior:**
5
+ * - Narrows the input type to `undefined` when `true`
6
+ * - Useful for explicit undefined checks
7
+ *
8
+ * @param u - The value to check
9
+ * @returns `true` if `u` is `undefined`, `false` otherwise.
10
+ * When `true`, TypeScript narrows the type to `undefined`.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const value: string | undefined = getValue();
15
+ *
16
+ * if (isUndefined(value)) {
17
+ * // value is now typed as undefined
18
+ * console.log('Value is undefined');
19
+ * } else {
20
+ * // value is now typed as string
21
+ * console.log('Value length:', value.length);
22
+ * }
23
+ * ```
24
+ */
25
+ export declare const isUndefined: (u: unknown) => u is undefined;
26
+ /**
27
+ * Type guard that checks if a value is not `undefined`.
28
+ *
29
+ * **Type Narrowing Behavior:**
30
+ * - Excludes `undefined` from the input type when `true`
31
+ * - Preserves all other types in the union
32
+ * - Commonly used to filter out undefined values
33
+ *
34
+ * @template T - The type of the input value
35
+ * @param u - The value to check
36
+ * @returns `true` if `u` is not `undefined`, `false` otherwise.
37
+ * When `true`, TypeScript excludes `undefined` from the type.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const items: (string | undefined)[] = ['a', undefined, 'b', undefined, 'c'];
42
+ *
43
+ * const definedItems = items.filter(isNotUndefined);
44
+ * // definedItems is now string[] - undefined values are filtered out
45
+ *
46
+ * definedItems.forEach(item => {
47
+ * // item is guaranteed to be string, not undefined
48
+ * console.log(item.toUpperCase());
49
+ * });
50
+ * ```
51
+ */
52
+ export declare const isNotUndefined: <T>(u: T) => u is RelaxedExclude<T, undefined>;
53
+ /**
54
+ * Type guard that checks if a value is a boolean.
55
+ *
56
+ * **Type Narrowing Behavior:**
57
+ * - Narrows `unknown` to `boolean` when `true`
58
+ * - Preserves literal boolean types (`true | false`)
59
+ *
60
+ * @param u - The value to check
61
+ * @returns `true` if `u` is a boolean, `false` otherwise.
62
+ * When `true`, TypeScript narrows the type to `boolean`.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const userInput: unknown = parseInput();
67
+ *
68
+ * if (isBoolean(userInput)) {
69
+ * // userInput is now typed as boolean
70
+ * console.log('Boolean value:', userInput ? 'true' : 'false');
71
+ * }
72
+ * ```
73
+ */
74
+ export declare const isBoolean: (u: unknown) => u is boolean;
75
+ /**
76
+ * Type guard that checks if a value is not a boolean.
77
+ *
78
+ * **Type Narrowing Behavior:**
79
+ * - Excludes `boolean` from the input type when `true`
80
+ * - Preserves all other types in the union
81
+ *
82
+ * @template T - The type of the input value
83
+ * @param u - The value to check
84
+ * @returns `true` if `u` is not a boolean, `false` otherwise.
85
+ * When `true`, TypeScript excludes `boolean` from the type.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * type MixedValue = string | number | boolean;
90
+ * const value: MixedValue = getValue();
91
+ *
92
+ * if (isNotBoolean(value)) {
93
+ * // value is now string | number
94
+ * console.log('Non-boolean value:', value);
95
+ * }
96
+ * ```
97
+ */
98
+ export declare const isNotBoolean: <T>(u: T) => u is RelaxedExclude<T, boolean>;
99
+ /**
100
+ * Type guard that checks if a value is a number.
101
+ *
102
+ * **Type Narrowing Behavior:**
103
+ * - Narrows `unknown` to `number` when `true`
104
+ * - Includes `NaN`, `Infinity`, and `-Infinity` as valid numbers
105
+ * - Preserves literal number types when possible
106
+ *
107
+ * @param u - The value to check
108
+ * @returns `true` if `u` is a number, `false` otherwise.
109
+ * When `true`, TypeScript narrows the type to `number`.
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * const userInput: unknown = parseInput();
114
+ *
115
+ * if (isNumber(userInput)) {
116
+ * // userInput is now typed as number
117
+ * console.log('Number value:', userInput.toFixed(2));
118
+ *
119
+ * // Note: this includes NaN and Infinity
120
+ * if (Number.isFinite(userInput)) {
121
+ * console.log('Finite number:', userInput);
122
+ * }
123
+ * }
124
+ * ```
125
+ */
126
+ export declare const isNumber: (u: unknown) => u is number;
127
+ /**
128
+ * Type guard that checks if a value is not a number.
129
+ *
130
+ * **Type Narrowing Behavior:**
131
+ * - Excludes `number` from the input type when `true`
132
+ * - Preserves all other types in the union
133
+ *
134
+ * @template T - The type of the input value
135
+ * @param u - The value to check
136
+ * @returns `true` if `u` is not a number, `false` otherwise.
137
+ * When `true`, TypeScript excludes `number` from the type.
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * type Value = string | number | boolean;
142
+ * const values: Value[] = ['hello', 42, true, 3.14, false];
143
+ *
144
+ * const nonNumbers = values.filter(isNotNumber);
145
+ * // nonNumbers is now (string | boolean)[] - numbers are filtered out
146
+ * ```
147
+ */
148
+ export declare const isNotNumber: <T>(u: T) => u is RelaxedExclude<T, number>;
149
+ /**
150
+ * Type guard that checks if a value is a bigint.
151
+ *
152
+ * **Type Narrowing Behavior:**
153
+ * - Narrows `unknown` to `bigint` when `true`
154
+ * - Identifies values created with `BigInt()` constructor or `n` suffix
155
+ *
156
+ * @param u - The value to check
157
+ * @returns `true` if `u` is a bigint, `false` otherwise.
158
+ * When `true`, TypeScript narrows the type to `bigint`.
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * const userInput: unknown = parseInput();
163
+ *
164
+ * if (isBigint(userInput)) {
165
+ * // userInput is now typed as bigint
166
+ * console.log('BigInt value:', userInput.toString());
167
+ * const doubled = userInput * 2n; // Safe bigint operations
168
+ * }
169
+ * ```
170
+ */
171
+ export declare const isBigint: (u: unknown) => u is bigint;
172
+ /**
173
+ * Type guard that checks if a value is not a bigint.
174
+ *
175
+ * **Type Narrowing Behavior:**
176
+ * - Excludes `bigint` from the input type when `true`
177
+ * - Preserves all other types in the union
178
+ *
179
+ * @template T - The type of the input value
180
+ * @param u - The value to check
181
+ * @returns `true` if `u` is not a bigint, `false` otherwise.
182
+ * When `true`, TypeScript excludes `bigint` from the type.
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * type NumericValue = number | bigint;
187
+ * const value: NumericValue = getValue();
188
+ *
189
+ * if (isNotBigint(value)) {
190
+ * // value is now number
191
+ * console.log('Regular number:', value.toFixed(2));
192
+ * }
193
+ * ```
194
+ */
195
+ export declare const isNotBigint: <T>(u: T) => u is RelaxedExclude<T, bigint>;
196
+ /**
197
+ * Type guard that checks if a value is a string.
198
+ *
199
+ * **Type Narrowing Behavior:**
200
+ * - Narrows `unknown` to `string` when `true`
201
+ * - Preserves literal string types when possible
202
+ * - Includes empty strings
203
+ *
204
+ * @param u - The value to check
205
+ * @returns `true` if `u` is a string, `false` otherwise.
206
+ * When `true`, TypeScript narrows the type to `string`.
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * const userInput: unknown = parseInput();
211
+ *
212
+ * if (isString(userInput)) {
213
+ * // userInput is now typed as string
214
+ * console.log('String length:', userInput.length);
215
+ * console.log('Uppercase:', userInput.toUpperCase());
216
+ *
217
+ * // You can further check for non-empty strings
218
+ * if (userInput.length > 0) {
219
+ * console.log('Non-empty string:', userInput);
220
+ * }
221
+ * }
222
+ * ```
223
+ */
224
+ export declare const isString: (u: unknown) => u is string;
225
+ /**
226
+ * Type guard that checks if a value is not a string.
227
+ *
228
+ * **Type Narrowing Behavior:**
229
+ * - Excludes `string` from the input type when `true`
230
+ * - Preserves all other types in the union
231
+ *
232
+ * @template T - The type of the input value
233
+ * @param u - The value to check
234
+ * @returns `true` if `u` is not a string, `false` otherwise.
235
+ * When `true`, TypeScript excludes `string` from the type.
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * type Value = string | number | boolean;
240
+ * const mixedValues: Value[] = ['hello', 42, true, 'world', 3.14];
241
+ *
242
+ * const nonStrings = mixedValues.filter(isNotString);
243
+ * // nonStrings is now (number | boolean)[] - strings are filtered out
244
+ * ```
245
+ */
246
+ export declare const isNotString: <T>(u: T) => u is RelaxedExclude<T, string>;
247
+ /**
248
+ * Type guard that checks if a value is a symbol.
249
+ *
250
+ * **Type Narrowing Behavior:**
251
+ * - Narrows `unknown` to `symbol` when `true`
252
+ * - Identifies values created with `Symbol()` constructor
253
+ *
254
+ * @param u - The value to check
255
+ * @returns `true` if `u` is a symbol, `false` otherwise.
256
+ * When `true`, TypeScript narrows the type to `symbol`.
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * const userInput: unknown = parseInput();
261
+ *
262
+ * if (isSymbol(userInput)) {
263
+ * // userInput is now typed as symbol
264
+ * console.log('Symbol description:', userInput.description);
265
+ * console.log('Symbol string:', userInput.toString());
266
+ * }
267
+ * ```
268
+ */
269
+ export declare const isSymbol: (u: unknown) => u is symbol;
270
+ /**
271
+ * Type guard that checks if a value is not a symbol.
272
+ *
273
+ * **Type Narrowing Behavior:**
274
+ * - Excludes `symbol` from the input type when `true`
275
+ * - Preserves all other types in the union
276
+ *
277
+ * @template T - The type of the input value
278
+ * @param u - The value to check
279
+ * @returns `true` if `u` is not a symbol, `false` otherwise.
280
+ * When `true`, TypeScript excludes `symbol` from the type.
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * type PropertyKey = string | number | symbol;
285
+ * const key: PropertyKey = getPropertyKey();
286
+ *
287
+ * if (isNotSymbol(key)) {
288
+ * // key is now string | number
289
+ * console.log('Non-symbol key:', key);
290
+ * }
291
+ * ```
292
+ */
293
+ export declare const isNotSymbol: <T>(u: T) => u is RelaxedExclude<T, symbol>;
294
+ /**
295
+ * Type guard that checks if a value is `null`.
296
+ *
297
+ * **Type Narrowing Behavior:**
298
+ * - Narrows the input type to `null` when `true`
299
+ * - Useful for explicit null checks
300
+ *
301
+ * @param u - The value to check
302
+ * @returns `true` if `u` is `null`, `false` otherwise.
303
+ * When `true`, TypeScript narrows the type to `null`.
304
+ *
305
+ * @example
306
+ * ```typescript
307
+ * const value: string | null = getValue();
308
+ *
309
+ * if (isNull(value)) {
310
+ * // value is now typed as null
311
+ * console.log('Value is null');
312
+ * } else {
313
+ * // value is now typed as string
314
+ * console.log('Value length:', value.length);
315
+ * }
316
+ * ```
317
+ */
318
+ export declare const isNull: (u: unknown) => u is null;
319
+ /**
320
+ * Type guard that checks if a value is not `null`.
321
+ *
322
+ * **Type Narrowing Behavior:**
323
+ * - Excludes `null` from the input type when `true`
324
+ * - Preserves all other types including `undefined`
325
+ * - Commonly used to filter out null values
326
+ *
327
+ * @template T - The type of the input value (which could be `null`)
328
+ * @param u - The value to check
329
+ * @returns `true` if `u` is not `null`, `false` otherwise.
330
+ * When `true`, TypeScript excludes `null` from the type.
331
+ *
332
+ * @example
333
+ * ```typescript
334
+ * const items: (string | null)[] = ['a', null, 'b', null, 'c'];
335
+ *
336
+ * const nonNullItems = items.filter(isNotNull);
337
+ * // nonNullItems is now string[] - null values are filtered out
338
+ *
339
+ * nonNullItems.forEach(item => {
340
+ * // item is guaranteed to be string, not null
341
+ * console.log(item.toUpperCase());
342
+ * });
343
+ * ```
344
+ */
345
+ export declare const isNotNull: <T>(u: T | null) => u is T;
346
+ /**
347
+ * Type guard that checks if a value is `null` or `undefined` (nullish).
348
+ *
349
+ * This function uses the loose equality operator (`==`) to check for both `null` and `undefined`
350
+ * in a single comparison, which is the standard JavaScript idiom for nullish checks.
351
+ *
352
+ * **Type Narrowing Behavior:**
353
+ * - Narrows the input type to `null | undefined` when `true`
354
+ * - Useful for checking if a value is "nullish" (either null or undefined)
355
+ *
356
+ * @param u - The value to check
357
+ * @returns `true` if `u` is `null` or `undefined`, `false` otherwise.
358
+ * When `true`, TypeScript narrows the type to `null | undefined`.
359
+ *
360
+ * @example
361
+ * ```typescript
362
+ * const value: string | null | undefined = getValue();
363
+ *
364
+ * if (isNullish(value)) {
365
+ * // value is now typed as null | undefined
366
+ * console.log('Value is nullish');
367
+ * } else {
368
+ * // value is now typed as string
369
+ * console.log('Value length:', value.length);
370
+ * }
371
+ * ```
372
+ */
373
+ export declare const isNullish: (u: unknown) => u is null | undefined;
374
+ /**
375
+ * Type guard that checks if a value is not `null` or `undefined` (non-nullish).
376
+ *
377
+ * This function uses the loose inequality operator (`!=`) to check that a value is neither
378
+ * `null` nor `undefined` in a single comparison. This is equivalent to TypeScript's
379
+ * `NonNullable<T>` utility type.
380
+ *
381
+ * **Type Narrowing Behavior:**
382
+ * - Excludes both `null` and `undefined` from the input type when `true`
383
+ * - Equivalent to applying TypeScript's `NonNullable<T>` utility type
384
+ * - Commonly used to filter out nullish values from arrays
385
+ *
386
+ * @template T - The type of the input value
387
+ * @param u - The value to check
388
+ * @returns `true` if `u` is not `null` and not `undefined`, `false` otherwise.
389
+ * When `true`, TypeScript narrows the type to `NonNullable<T>`.
390
+ *
391
+ * @example
392
+ * ```typescript
393
+ * const items: (string | null | undefined)[] = [
394
+ * 'hello',
395
+ * null,
396
+ * 'world',
397
+ * undefined,
398
+ * 'test'
399
+ * ];
400
+ *
401
+ * const definedItems = items.filter(isNonNullish);
402
+ * // definedItems is now string[] - both null and undefined values are filtered out
403
+ *
404
+ * definedItems.forEach(item => {
405
+ * // item is guaranteed to be string, never null or undefined
406
+ * console.log(item.toUpperCase());
407
+ * });
408
+ * ```
409
+ *
410
+ * @example
411
+ * Progressive validation with optional chaining alternative:
412
+ * ```typescript
413
+ * interface User {
414
+ * profile?: {
415
+ * name?: string;
416
+ * email?: string;
417
+ * };
418
+ * }
419
+ *
420
+ * const user: User = getUser();
421
+ *
422
+ * // Instead of optional chaining: user.profile?.name
423
+ * if (isNonNullish(user.profile) && isNonNullish(user.profile.name)) {
424
+ * // user.profile.name is now guaranteed to be string
425
+ * console.log('User name:', user.profile.name.toUpperCase());
426
+ * }
427
+ * ```
428
+ */
429
+ export declare const isNonNullish: <T>(u: T) => u is NonNullable<T>;
430
+ //# sourceMappingURL=is-type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-type.d.mts","sourceRoot":"","sources":["../../src/guard/is-type.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,WAAW,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,SAA4B,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAAG,GAAG,CAAC,KAAG,CAAC,IAAI,cAAc,CAAC,CAAC,EAAE,SAAS,CACzD,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,SAAS,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,OAAiC,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAAG,GAAG,CAAC,KAAG,CAAC,IAAI,cAAc,CAAC,CAAC,EAAE,OAAO,CAC9C,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,MAA+B,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAG,GAAG,CAAC,KAAG,CAAC,IAAI,cAAc,CAAC,CAAC,EAAE,MAAM,CAC7C,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,MAA+B,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAG,GAAG,CAAC,KAAG,CAAC,IAAI,cAAc,CAAC,CAAC,EAAE,MAAM,CAC7C,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,MAA+B,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAG,GAAG,CAAC,KAAG,CAAC,IAAI,cAAc,CAAC,CAAC,EAAE,MAAM,CAC7C,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,MAA+B,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAG,GAAG,CAAC,KAAG,CAAC,IAAI,cAAc,CAAC,CAAC,EAAE,MAAM,CAC7C,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,MAAM,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,IAAkB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EAAG,GAAG,CAAC,GAAG,IAAI,KAAG,CAAC,IAAI,CAAe,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,SAAS,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,IAAI,GAAG,SAAsB,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAAG,GAAG,CAAC,KAAG,CAAC,IAAI,WAAW,CAAC,CAAC,CAAc,CAAC"}