lifecycleion 0.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 (177) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +125 -0
  3. package/dist/index.cjs +7 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +2 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +5 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/lib/arrays.cjs +95 -0
  10. package/dist/lib/arrays.cjs.map +1 -0
  11. package/dist/lib/arrays.d.cts +15 -0
  12. package/dist/lib/arrays.d.ts +15 -0
  13. package/dist/lib/arrays.js +63 -0
  14. package/dist/lib/arrays.js.map +1 -0
  15. package/dist/lib/ascii-tables/index.cjs +642 -0
  16. package/dist/lib/ascii-tables/index.cjs.map +1 -0
  17. package/dist/lib/ascii-tables/index.d.cts +66 -0
  18. package/dist/lib/ascii-tables/index.d.ts +66 -0
  19. package/dist/lib/ascii-tables/index.js +603 -0
  20. package/dist/lib/ascii-tables/index.js.map +1 -0
  21. package/dist/lib/clamp.cjs +41 -0
  22. package/dist/lib/clamp.cjs.map +1 -0
  23. package/dist/lib/clamp.d.cts +26 -0
  24. package/dist/lib/clamp.d.ts +26 -0
  25. package/dist/lib/clamp.js +15 -0
  26. package/dist/lib/clamp.js.map +1 -0
  27. package/dist/lib/constants.cjs +73 -0
  28. package/dist/lib/constants.cjs.map +1 -0
  29. package/dist/lib/constants.d.cts +17 -0
  30. package/dist/lib/constants.d.ts +17 -0
  31. package/dist/lib/constants.js +34 -0
  32. package/dist/lib/constants.js.map +1 -0
  33. package/dist/lib/curly-brackets.cjs +77 -0
  34. package/dist/lib/curly-brackets.cjs.map +1 -0
  35. package/dist/lib/curly-brackets.d.cts +17 -0
  36. package/dist/lib/curly-brackets.d.ts +17 -0
  37. package/dist/lib/curly-brackets.js +52 -0
  38. package/dist/lib/curly-brackets.js.map +1 -0
  39. package/dist/lib/deep-clone.cjs +87 -0
  40. package/dist/lib/deep-clone.cjs.map +1 -0
  41. package/dist/lib/deep-clone.d.cts +19 -0
  42. package/dist/lib/deep-clone.d.ts +19 -0
  43. package/dist/lib/deep-clone.js +62 -0
  44. package/dist/lib/deep-clone.js.map +1 -0
  45. package/dist/lib/error-to-string.cjs +743 -0
  46. package/dist/lib/error-to-string.cjs.map +1 -0
  47. package/dist/lib/error-to-string.d.cts +3 -0
  48. package/dist/lib/error-to-string.d.ts +3 -0
  49. package/dist/lib/error-to-string.js +706 -0
  50. package/dist/lib/error-to-string.js.map +1 -0
  51. package/dist/lib/event-emitter.cjs +899 -0
  52. package/dist/lib/event-emitter.cjs.map +1 -0
  53. package/dist/lib/event-emitter.d.cts +78 -0
  54. package/dist/lib/event-emitter.d.ts +78 -0
  55. package/dist/lib/event-emitter.js +861 -0
  56. package/dist/lib/event-emitter.js.map +1 -0
  57. package/dist/lib/id-helpers.cjs +205 -0
  58. package/dist/lib/id-helpers.cjs.map +1 -0
  59. package/dist/lib/id-helpers.d.cts +198 -0
  60. package/dist/lib/id-helpers.d.ts +198 -0
  61. package/dist/lib/id-helpers.js +170 -0
  62. package/dist/lib/id-helpers.js.map +1 -0
  63. package/dist/lib/is-boolean.cjs +33 -0
  64. package/dist/lib/is-boolean.cjs.map +1 -0
  65. package/dist/lib/is-boolean.d.cts +19 -0
  66. package/dist/lib/is-boolean.d.ts +19 -0
  67. package/dist/lib/is-boolean.js +8 -0
  68. package/dist/lib/is-boolean.js.map +1 -0
  69. package/dist/lib/is-function.cjs +33 -0
  70. package/dist/lib/is-function.cjs.map +1 -0
  71. package/dist/lib/is-function.d.cts +3 -0
  72. package/dist/lib/is-function.d.ts +3 -0
  73. package/dist/lib/is-function.js +8 -0
  74. package/dist/lib/is-function.js.map +1 -0
  75. package/dist/lib/is-number.cjs +38 -0
  76. package/dist/lib/is-number.cjs.map +1 -0
  77. package/dist/lib/is-number.d.cts +38 -0
  78. package/dist/lib/is-number.d.ts +38 -0
  79. package/dist/lib/is-number.js +12 -0
  80. package/dist/lib/is-number.js.map +1 -0
  81. package/dist/lib/is-plain-object.cjs +33 -0
  82. package/dist/lib/is-plain-object.cjs.map +1 -0
  83. package/dist/lib/is-plain-object.d.cts +20 -0
  84. package/dist/lib/is-plain-object.d.ts +20 -0
  85. package/dist/lib/is-plain-object.js +8 -0
  86. package/dist/lib/is-plain-object.js.map +1 -0
  87. package/dist/lib/is-promise.cjs +34 -0
  88. package/dist/lib/is-promise.cjs.map +1 -0
  89. package/dist/lib/is-promise.d.cts +3 -0
  90. package/dist/lib/is-promise.d.ts +3 -0
  91. package/dist/lib/is-promise.js +9 -0
  92. package/dist/lib/is-promise.js.map +1 -0
  93. package/dist/lib/json-helpers.cjs +49 -0
  94. package/dist/lib/json-helpers.cjs.map +1 -0
  95. package/dist/lib/json-helpers.d.cts +10 -0
  96. package/dist/lib/json-helpers.d.ts +10 -0
  97. package/dist/lib/json-helpers.js +22 -0
  98. package/dist/lib/json-helpers.js.map +1 -0
  99. package/dist/lib/lifecycle-manager/index.cjs +5594 -0
  100. package/dist/lib/lifecycle-manager/index.cjs.map +1 -0
  101. package/dist/lib/lifecycle-manager/index.d.cts +2044 -0
  102. package/dist/lib/lifecycle-manager/index.d.ts +2044 -0
  103. package/dist/lib/lifecycle-manager/index.js +5543 -0
  104. package/dist/lib/lifecycle-manager/index.js.map +1 -0
  105. package/dist/lib/logger/index.cjs +2514 -0
  106. package/dist/lib/logger/index.cjs.map +1 -0
  107. package/dist/lib/logger/index.d.cts +630 -0
  108. package/dist/lib/logger/index.d.ts +630 -0
  109. package/dist/lib/logger/index.js +2470 -0
  110. package/dist/lib/logger/index.js.map +1 -0
  111. package/dist/lib/padding-utils.cjs +77 -0
  112. package/dist/lib/padding-utils.cjs.map +1 -0
  113. package/dist/lib/padding-utils.d.cts +44 -0
  114. package/dist/lib/padding-utils.d.ts +44 -0
  115. package/dist/lib/padding-utils.js +46 -0
  116. package/dist/lib/padding-utils.js.map +1 -0
  117. package/dist/lib/process-signal-manager.cjs +1306 -0
  118. package/dist/lib/process-signal-manager.cjs.map +1 -0
  119. package/dist/lib/process-signal-manager.d.cts +305 -0
  120. package/dist/lib/process-signal-manager.d.ts +305 -0
  121. package/dist/lib/process-signal-manager.js +1269 -0
  122. package/dist/lib/process-signal-manager.js.map +1 -0
  123. package/dist/lib/promise-protected-resolver.cjs +828 -0
  124. package/dist/lib/promise-protected-resolver.cjs.map +1 -0
  125. package/dist/lib/promise-protected-resolver.d.cts +17 -0
  126. package/dist/lib/promise-protected-resolver.d.ts +17 -0
  127. package/dist/lib/promise-protected-resolver.js +791 -0
  128. package/dist/lib/promise-protected-resolver.js.map +1 -0
  129. package/dist/lib/retry-utils/index.cjs +2183 -0
  130. package/dist/lib/retry-utils/index.cjs.map +1 -0
  131. package/dist/lib/retry-utils/index.d.cts +321 -0
  132. package/dist/lib/retry-utils/index.d.ts +321 -0
  133. package/dist/lib/retry-utils/index.js +2133 -0
  134. package/dist/lib/retry-utils/index.js.map +1 -0
  135. package/dist/lib/safe-handle-callback.cjs +818 -0
  136. package/dist/lib/safe-handle-callback.cjs.map +1 -0
  137. package/dist/lib/safe-handle-callback.d.cts +43 -0
  138. package/dist/lib/safe-handle-callback.d.ts +43 -0
  139. package/dist/lib/safe-handle-callback.js +780 -0
  140. package/dist/lib/safe-handle-callback.js.map +1 -0
  141. package/dist/lib/serialize-error/index.cjs +93 -0
  142. package/dist/lib/serialize-error/index.cjs.map +1 -0
  143. package/dist/lib/serialize-error/index.d.cts +26 -0
  144. package/dist/lib/serialize-error/index.d.ts +26 -0
  145. package/dist/lib/serialize-error/index.js +64 -0
  146. package/dist/lib/serialize-error/index.js.map +1 -0
  147. package/dist/lib/single-event-observer.cjs +841 -0
  148. package/dist/lib/single-event-observer.cjs.map +1 -0
  149. package/dist/lib/single-event-observer.d.cts +54 -0
  150. package/dist/lib/single-event-observer.d.ts +54 -0
  151. package/dist/lib/single-event-observer.js +803 -0
  152. package/dist/lib/single-event-observer.js.map +1 -0
  153. package/dist/lib/sleep.cjs +37 -0
  154. package/dist/lib/sleep.cjs.map +1 -0
  155. package/dist/lib/sleep.d.cts +11 -0
  156. package/dist/lib/sleep.d.ts +11 -0
  157. package/dist/lib/sleep.js +12 -0
  158. package/dist/lib/sleep.js.map +1 -0
  159. package/dist/lib/strings.cjs +186 -0
  160. package/dist/lib/strings.cjs.map +1 -0
  161. package/dist/lib/strings.d.cts +107 -0
  162. package/dist/lib/strings.d.ts +107 -0
  163. package/dist/lib/strings.js +149 -0
  164. package/dist/lib/strings.js.map +1 -0
  165. package/dist/lib/tmp-dir.cjs +254 -0
  166. package/dist/lib/tmp-dir.cjs.map +1 -0
  167. package/dist/lib/tmp-dir.d.cts +63 -0
  168. package/dist/lib/tmp-dir.d.ts +63 -0
  169. package/dist/lib/tmp-dir.js +211 -0
  170. package/dist/lib/tmp-dir.js.map +1 -0
  171. package/dist/lib/unix-time-helpers.cjs +53 -0
  172. package/dist/lib/unix-time-helpers.cjs.map +1 -0
  173. package/dist/lib/unix-time-helpers.d.cts +56 -0
  174. package/dist/lib/unix-time-helpers.d.ts +56 -0
  175. package/dist/lib/unix-time-helpers.js +24 -0
  176. package/dist/lib/unix-time-helpers.js.map +1 -0
  177. package/package.json +220 -0
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Supported identifier types:
3
+ *
4
+ * - **`objectID`**: MongoDB-style ObjectID
5
+ * - Format: 24 hexadecimal characters
6
+ * - Timestamp-based: Yes (sortable by creation time)
7
+ * - Case-sensitive: No (accepts both uppercase and lowercase)
8
+ * - Example: `"507f1f77bcf86cd799439011"`
9
+ *
10
+ * - **`uuid4`**: UUID version 4
11
+ * - Format: 36 characters (32 hex + 4 dashes): `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
12
+ * - Timestamp-based: No (random)
13
+ * - Case-sensitive: No (accepts both uppercase and lowercase)
14
+ * - Example: `"9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"`
15
+ *
16
+ * - **`uuid7`**: UUID version 7
17
+ * - Format: 36 characters (32 hex + 4 dashes): `xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx`
18
+ * - Timestamp-based: Yes (sortable by creation time)
19
+ * - Case-sensitive: No (accepts both uppercase and lowercase)
20
+ * - Example: `"018e8c6e-4f7e-7000-8000-0123456789ab"`
21
+ *
22
+ * - **`ulid`**: Universally Unique Lexicographically Sortable Identifier
23
+ * - Format: 26 characters using Crockford's base32 alphabet
24
+ * - Timestamp-based: Yes (sortable by creation time)
25
+ * - Case-sensitive: No (canonical form is uppercase, but accepts lowercase)
26
+ * - Example: `"01ARZ3NDEKTSV4RRFFQ69G5FAV"`
27
+ */
28
+ type IdentifierType = 'objectID' | 'uuid4' | 'uuid7' | 'ulid';
29
+ /**
30
+ * Array of all supported identifier types.
31
+ */
32
+ declare const IDENTIFIER_TYPES: readonly ["objectID", "uuid4", "uuid7", "ulid"];
33
+ /**
34
+ * Generates a unique identifier of the specified type.
35
+ *
36
+ * @param type - The type of identifier to generate:
37
+ * - `objectID`: MongoDB ObjectID (24 hex chars, timestamp-based)
38
+ * - `uuid4`: UUID v4 (random, not sortable)
39
+ * - `uuid7`: UUID v7 (timestamp-based, sortable)
40
+ * - `ulid`: ULID (timestamp-based, sortable, case-insensitive)
41
+ * @param seedTime - Optional timestamp in milliseconds to seed the ID with.
42
+ * - Supported by: `objectID`, `uuid7`, `ulid`
43
+ * - Ignored by: `uuid4` (always random)
44
+ * - Use this for testing or when you need IDs to have a specific timestamp
45
+ * @returns A unique identifier string
46
+ * @throws {TypeError} If an invalid type is provided
47
+ * @throws {TypeError} If `seedTime` is provided but is not a non-negative finite number
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // Generate random IDs
52
+ * const objId = generateID('objectID'); // "507f1f77bcf86cd799439011"
53
+ * const uuid4 = generateID('uuid4'); // "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"
54
+ * const uuid7 = generateID('uuid7'); // "018e8c6e-4f7e-7000-8000-0123456789ab"
55
+ * const ulid = generateID('ulid'); // "01ARZ3NDEKTSV4RRFFQ69G5FAV"
56
+ *
57
+ * // Generate IDs with a specific timestamp
58
+ * const timestamp = Date.now();
59
+ * const seededId = generateID('uuid7', timestamp);
60
+ * ```
61
+ */
62
+ declare function generateID(type: IdentifierType, seedTime?: number): string;
63
+ /**
64
+ * Validates that a string is a valid identifier of the specified type.
65
+ *
66
+ * Performs strict validation:
67
+ * - `objectID`: Must be 24 hexadecimal characters
68
+ * - `uuid4`: Must be a valid UUID with version 4
69
+ * - `uuid7`: Must be a valid UUID with version 7
70
+ * - `ulid`: Must be 26 characters from the ULID character set
71
+ *
72
+ * Empty IDs (from `emptyID()`) are considered valid.
73
+ * Non-string `id` values return `false`.
74
+ *
75
+ * @param type - The expected identifier type
76
+ * @param id - The identifier string to validate
77
+ * @returns `true` if the ID is valid for the specified type, `false` otherwise
78
+ * @throws {TypeError} If an invalid type is provided
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * validateID('uuid4', '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'); // true
83
+ * validateID('uuid4', '018e8c6e-4f7e-7000-8000-0123456789ab'); // false (this is uuid7)
84
+ * validateID('objectID', '507f1f77bcf86cd799439011'); // true
85
+ * validateID('objectID', 'invalid'); // false
86
+ * ```
87
+ */
88
+ declare function validateID(type: IdentifierType, id: string): boolean;
89
+ /**
90
+ * Returns an empty/null identifier for the specified type.
91
+ *
92
+ * Empty IDs are valid IDs (pass `validateID()`) but represent a null/empty state.
93
+ * Useful as default values or placeholders in databases.
94
+ *
95
+ * Empty ID formats:
96
+ * - `objectID`: `"000000000000000000000000"` (24 zeros)
97
+ * - `uuid4`: `"00000000-0000-0000-0000-000000000000"` (nil UUID)
98
+ * - `uuid7`: `"00000000-0000-0000-0000-000000000000"` (nil UUID)
99
+ * - `ulid`: `"00000000000000000000000000"` (26 zeros)
100
+ *
101
+ * @param type - The type of empty identifier to generate
102
+ * @returns An empty identifier string
103
+ * @throws {TypeError} If an invalid type is provided
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const emptyUuid = emptyID('uuid4'); // "00000000-0000-0000-0000-000000000000"
108
+ * validateID('uuid4', emptyUuid); // true
109
+ * isEmptyID('uuid4', emptyUuid); // true
110
+ * ```
111
+ */
112
+ declare function emptyID(type: IdentifierType): string;
113
+ /**
114
+ * Checks if an identifier is an empty/null ID.
115
+ *
116
+ * Compares the provided ID against the empty ID for the specified type.
117
+ * This is useful for checking if an ID represents a null/empty state.
118
+ *
119
+ * @param type - The identifier type to check against
120
+ * @param id - The identifier string to check
121
+ * @returns `true` if the ID is empty for the specified type, `false` otherwise.
122
+ * Non-string `id` values return `false`.
123
+ * @throws {TypeError} If an invalid type is provided
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const emptyUuid = emptyID('uuid4');
128
+ * const realUuid = generateID('uuid4');
129
+ *
130
+ * isEmptyID('uuid4', emptyUuid); // true
131
+ * isEmptyID('uuid4', realUuid); // false
132
+ * ```
133
+ */
134
+ declare function isEmptyID(type: IdentifierType, id: string): boolean;
135
+ /**
136
+ * Helper class for working with identifiers of a specific type.
137
+ *
138
+ * This class provides a convenient way to work with IDs without repeatedly
139
+ * specifying the type parameter. Initialize it with your preferred ID type,
140
+ * then use its methods without passing the type each time.
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * // Create a helper for UUID v7 identifiers
145
+ * const idHelper = new IDHelpers('uuid7');
146
+ *
147
+ * // Generate IDs without specifying type each time
148
+ * const id1 = idHelper.generateID();
149
+ * const id2 = idHelper.generateID(Date.now());
150
+ *
151
+ * // Validate IDs
152
+ * if (idHelper.validateID(someId)) {
153
+ * console.log('Valid uuid7');
154
+ * }
155
+ *
156
+ * // Check for empty IDs
157
+ * const empty = idHelper.emptyID();
158
+ * console.log(idHelper.isEmptyID(empty)); // true
159
+ * ```
160
+ */
161
+ declare class IDHelpers {
162
+ private _type;
163
+ /**
164
+ * Gets the identifier type this helper is configured for.
165
+ */
166
+ get type(): IdentifierType;
167
+ /**
168
+ * Creates a new ID helper for the specified type.
169
+ * @param type - The identifier type to use for all operations
170
+ * @throws {TypeError} If an invalid type is provided
171
+ */
172
+ constructor(type: IdentifierType);
173
+ /**
174
+ * Generates a new identifier using the configured type.
175
+ * @param seedTime - Optional timestamp in milliseconds to seed the ID with
176
+ * @returns A unique identifier string
177
+ */
178
+ generateID(seedTime?: number): string;
179
+ /**
180
+ * Validates an identifier against the configured type.
181
+ * @param id - The identifier string to validate
182
+ * @returns `true` if valid, `false` otherwise
183
+ */
184
+ validateID(id: string): boolean;
185
+ /**
186
+ * Returns an empty identifier for the configured type.
187
+ * @returns An empty identifier string
188
+ */
189
+ emptyID(): string;
190
+ /**
191
+ * Checks if an identifier is empty for the configured type.
192
+ * @param id - The identifier string to check
193
+ * @returns `true` if empty, `false` otherwise
194
+ */
195
+ isEmptyID(id: string): boolean;
196
+ }
197
+
198
+ export { IDENTIFIER_TYPES, IDHelpers, type IdentifierType, emptyID, generateID, isEmptyID, validateID };
@@ -0,0 +1,170 @@
1
+ // src/lib/id-helpers.ts
2
+ import ObjectID from "bson-objectid";
3
+ import {
4
+ v4 as UUIDv4,
5
+ v7 as UUIDv7,
6
+ validate as uuidValidate,
7
+ version as uuidVersion
8
+ } from "uuid";
9
+ import { ulid } from "ulid";
10
+
11
+ // src/lib/unix-time-helpers.ts
12
+ function convertMSToUnix(value) {
13
+ return Math.floor(value / 1e3);
14
+ }
15
+
16
+ // src/lib/id-helpers.ts
17
+ var IDENTIFIER_TYPES = ["objectID", "uuid4", "uuid7", "ulid"];
18
+ function assertIdentifierType(type) {
19
+ if (!IDENTIFIER_TYPES.includes(type)) {
20
+ throw new TypeError(
21
+ `Invalid ID type given: "${type}". Expected one of: ${IDENTIFIER_TYPES.join(", ")}`
22
+ );
23
+ }
24
+ }
25
+ function generateID(type, seedTime) {
26
+ assertIdentifierType(type);
27
+ if (seedTime !== void 0 && (!Number.isFinite(seedTime) || seedTime < 0)) {
28
+ throw new TypeError(
29
+ `seedTime must be a non-negative finite number (milliseconds), got: ${seedTime}`
30
+ );
31
+ }
32
+ if (type === "objectID") {
33
+ if (seedTime !== void 0) {
34
+ const unixTime = convertMSToUnix(seedTime);
35
+ return new ObjectID(unixTime).toHexString();
36
+ } else {
37
+ return new ObjectID().toHexString();
38
+ }
39
+ } else if (type === "uuid4") {
40
+ return UUIDv4();
41
+ } else if (type === "uuid7") {
42
+ if (seedTime !== void 0) {
43
+ return UUIDv7({ msecs: seedTime });
44
+ } else {
45
+ return UUIDv7();
46
+ }
47
+ } else if (type === "ulid") {
48
+ if (seedTime !== void 0) {
49
+ return ulid(seedTime);
50
+ } else {
51
+ return ulid();
52
+ }
53
+ } else {
54
+ throw new TypeError(`Unhandled identifier type: "${type}"`);
55
+ }
56
+ }
57
+ function validateID(type, id) {
58
+ assertIdentifierType(type);
59
+ if (typeof id !== "string") {
60
+ return false;
61
+ }
62
+ if (type === "objectID") {
63
+ if (id.match(/^[0-9a-fA-F]{24}$/)) {
64
+ return true;
65
+ } else {
66
+ return false;
67
+ }
68
+ } else if (type === "uuid4" || type === "uuid7") {
69
+ if (isEmptyID(type, id)) {
70
+ return true;
71
+ }
72
+ const isValid = uuidValidate(id);
73
+ if (!isValid) {
74
+ return false;
75
+ }
76
+ const version = uuidVersion(id);
77
+ if (type === "uuid4" && version === 4) {
78
+ return true;
79
+ } else if (type === "uuid7" && version === 7) {
80
+ return true;
81
+ } else {
82
+ return false;
83
+ }
84
+ } else if (type === "ulid") {
85
+ if (id.match(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)) {
86
+ return true;
87
+ } else {
88
+ return false;
89
+ }
90
+ } else {
91
+ throw new TypeError(`Unhandled identifier type: "${type}"`);
92
+ }
93
+ }
94
+ function emptyID(type) {
95
+ assertIdentifierType(type);
96
+ if (type === "objectID") {
97
+ return "0".repeat(24);
98
+ } else if (type === "uuid4" || type === "uuid7") {
99
+ return "00000000-0000-0000-0000-000000000000";
100
+ } else if (type === "ulid") {
101
+ return "0".repeat(26);
102
+ } else {
103
+ throw new TypeError(`Unhandled identifier type: "${type}"`);
104
+ }
105
+ }
106
+ function isEmptyID(type, id) {
107
+ assertIdentifierType(type);
108
+ if (typeof id !== "string") {
109
+ return false;
110
+ }
111
+ return emptyID(type) === id;
112
+ }
113
+ var IDHelpers = class {
114
+ _type;
115
+ /**
116
+ * Gets the identifier type this helper is configured for.
117
+ */
118
+ get type() {
119
+ return this._type;
120
+ }
121
+ /**
122
+ * Creates a new ID helper for the specified type.
123
+ * @param type - The identifier type to use for all operations
124
+ * @throws {TypeError} If an invalid type is provided
125
+ */
126
+ constructor(type) {
127
+ assertIdentifierType(type);
128
+ this._type = type;
129
+ }
130
+ /**
131
+ * Generates a new identifier using the configured type.
132
+ * @param seedTime - Optional timestamp in milliseconds to seed the ID with
133
+ * @returns A unique identifier string
134
+ */
135
+ generateID(seedTime) {
136
+ return generateID(this._type, seedTime);
137
+ }
138
+ /**
139
+ * Validates an identifier against the configured type.
140
+ * @param id - The identifier string to validate
141
+ * @returns `true` if valid, `false` otherwise
142
+ */
143
+ validateID(id) {
144
+ return validateID(this._type, id);
145
+ }
146
+ /**
147
+ * Returns an empty identifier for the configured type.
148
+ * @returns An empty identifier string
149
+ */
150
+ emptyID() {
151
+ return emptyID(this._type);
152
+ }
153
+ /**
154
+ * Checks if an identifier is empty for the configured type.
155
+ * @param id - The identifier string to check
156
+ * @returns `true` if empty, `false` otherwise
157
+ */
158
+ isEmptyID(id) {
159
+ return isEmptyID(this._type, id);
160
+ }
161
+ };
162
+ export {
163
+ IDENTIFIER_TYPES,
164
+ IDHelpers,
165
+ emptyID,
166
+ generateID,
167
+ isEmptyID,
168
+ validateID
169
+ };
170
+ //# sourceMappingURL=id-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/id-helpers.ts","../../src/lib/unix-time-helpers.ts"],"sourcesContent":["import ObjectID from 'bson-objectid';\nimport {\n v4 as UUIDv4,\n v7 as UUIDv7,\n validate as uuidValidate,\n version as uuidVersion,\n} from 'uuid';\nimport { ulid } from 'ulid';\nimport { convertMSToUnix } from './unix-time-helpers';\n\n/**\n * Supported identifier types:\n *\n * - **`objectID`**: MongoDB-style ObjectID\n * - Format: 24 hexadecimal characters\n * - Timestamp-based: Yes (sortable by creation time)\n * - Case-sensitive: No (accepts both uppercase and lowercase)\n * - Example: `\"507f1f77bcf86cd799439011\"`\n *\n * - **`uuid4`**: UUID version 4\n * - Format: 36 characters (32 hex + 4 dashes): `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`\n * - Timestamp-based: No (random)\n * - Case-sensitive: No (accepts both uppercase and lowercase)\n * - Example: `\"9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d\"`\n *\n * - **`uuid7`**: UUID version 7\n * - Format: 36 characters (32 hex + 4 dashes): `xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx`\n * - Timestamp-based: Yes (sortable by creation time)\n * - Case-sensitive: No (accepts both uppercase and lowercase)\n * - Example: `\"018e8c6e-4f7e-7000-8000-0123456789ab\"`\n *\n * - **`ulid`**: Universally Unique Lexicographically Sortable Identifier\n * - Format: 26 characters using Crockford's base32 alphabet\n * - Timestamp-based: Yes (sortable by creation time)\n * - Case-sensitive: No (canonical form is uppercase, but accepts lowercase)\n * - Example: `\"01ARZ3NDEKTSV4RRFFQ69G5FAV\"`\n */\nexport type IdentifierType = 'objectID' | 'uuid4' | 'uuid7' | 'ulid';\n\n/**\n * Array of all supported identifier types.\n */\nexport const IDENTIFIER_TYPES = ['objectID', 'uuid4', 'uuid7', 'ulid'] as const;\n\nfunction assertIdentifierType(type: unknown): asserts type is IdentifierType {\n if (!IDENTIFIER_TYPES.includes(type as IdentifierType)) {\n throw new TypeError(\n `Invalid ID type given: \"${type as string}\". Expected one of: ${IDENTIFIER_TYPES.join(', ')}`,\n );\n }\n}\n\n/**\n * Generates a unique identifier of the specified type.\n *\n * @param type - The type of identifier to generate:\n * - `objectID`: MongoDB ObjectID (24 hex chars, timestamp-based)\n * - `uuid4`: UUID v4 (random, not sortable)\n * - `uuid7`: UUID v7 (timestamp-based, sortable)\n * - `ulid`: ULID (timestamp-based, sortable, case-insensitive)\n * @param seedTime - Optional timestamp in milliseconds to seed the ID with.\n * - Supported by: `objectID`, `uuid7`, `ulid`\n * - Ignored by: `uuid4` (always random)\n * - Use this for testing or when you need IDs to have a specific timestamp\n * @returns A unique identifier string\n * @throws {TypeError} If an invalid type is provided\n * @throws {TypeError} If `seedTime` is provided but is not a non-negative finite number\n *\n * @example\n * ```typescript\n * // Generate random IDs\n * const objId = generateID('objectID'); // \"507f1f77bcf86cd799439011\"\n * const uuid4 = generateID('uuid4'); // \"9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d\"\n * const uuid7 = generateID('uuid7'); // \"018e8c6e-4f7e-7000-8000-0123456789ab\"\n * const ulid = generateID('ulid'); // \"01ARZ3NDEKTSV4RRFFQ69G5FAV\"\n *\n * // Generate IDs with a specific timestamp\n * const timestamp = Date.now();\n * const seededId = generateID('uuid7', timestamp);\n * ```\n */\nexport function generateID(type: IdentifierType, seedTime?: number): string {\n assertIdentifierType(type);\n\n if (seedTime !== undefined && (!Number.isFinite(seedTime) || seedTime < 0)) {\n throw new TypeError(\n `seedTime must be a non-negative finite number (milliseconds), got: ${seedTime}`,\n );\n }\n\n if (type === 'objectID') {\n if (seedTime !== undefined) {\n // expects as unix time\n const unixTime = convertMSToUnix(seedTime);\n\n return new ObjectID(unixTime).toHexString();\n } else {\n return new ObjectID().toHexString();\n }\n } else if (type === 'uuid4') {\n return UUIDv4();\n } else if (type === 'uuid7') {\n if (seedTime !== undefined) {\n // expect in milliseconds\n return UUIDv7({ msecs: seedTime });\n } else {\n return UUIDv7();\n }\n } else if (type === 'ulid') {\n if (seedTime !== undefined) {\n // expect in milliseconds\n return ulid(seedTime);\n } else {\n return ulid();\n }\n } else {\n throw new TypeError(`Unhandled identifier type: \"${type as string}\"`);\n }\n}\n\n/**\n * Validates that a string is a valid identifier of the specified type.\n *\n * Performs strict validation:\n * - `objectID`: Must be 24 hexadecimal characters\n * - `uuid4`: Must be a valid UUID with version 4\n * - `uuid7`: Must be a valid UUID with version 7\n * - `ulid`: Must be 26 characters from the ULID character set\n *\n * Empty IDs (from `emptyID()`) are considered valid.\n * Non-string `id` values return `false`.\n *\n * @param type - The expected identifier type\n * @param id - The identifier string to validate\n * @returns `true` if the ID is valid for the specified type, `false` otherwise\n * @throws {TypeError} If an invalid type is provided\n *\n * @example\n * ```typescript\n * validateID('uuid4', '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'); // true\n * validateID('uuid4', '018e8c6e-4f7e-7000-8000-0123456789ab'); // false (this is uuid7)\n * validateID('objectID', '507f1f77bcf86cd799439011'); // true\n * validateID('objectID', 'invalid'); // false\n * ```\n */\nexport function validateID(type: IdentifierType, id: string): boolean {\n assertIdentifierType(type);\n\n if (typeof id !== 'string') {\n return false;\n }\n\n if (type === 'objectID') {\n if (id.match(/^[0-9a-fA-F]{24}$/)) {\n return true;\n } else {\n return false;\n }\n } else if (type === 'uuid4' || type === 'uuid7') {\n // Check if it's the empty ID first\n if (isEmptyID(type, id)) {\n return true;\n }\n\n const isValid = uuidValidate(id);\n if (!isValid) {\n return false;\n }\n\n // Check the specific UUID version\n const version = uuidVersion(id);\n if (type === 'uuid4' && version === 4) {\n return true;\n } else if (type === 'uuid7' && version === 7) {\n return true;\n } else {\n return false;\n }\n } else if (type === 'ulid') {\n if (id.match(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)) {\n return true;\n } else {\n return false;\n }\n } else {\n throw new TypeError(`Unhandled identifier type: \"${type as string}\"`);\n }\n}\n\n/**\n * Returns an empty/null identifier for the specified type.\n *\n * Empty IDs are valid IDs (pass `validateID()`) but represent a null/empty state.\n * Useful as default values or placeholders in databases.\n *\n * Empty ID formats:\n * - `objectID`: `\"000000000000000000000000\"` (24 zeros)\n * - `uuid4`: `\"00000000-0000-0000-0000-000000000000\"` (nil UUID)\n * - `uuid7`: `\"00000000-0000-0000-0000-000000000000\"` (nil UUID)\n * - `ulid`: `\"00000000000000000000000000\"` (26 zeros)\n *\n * @param type - The type of empty identifier to generate\n * @returns An empty identifier string\n * @throws {TypeError} If an invalid type is provided\n *\n * @example\n * ```typescript\n * const emptyUuid = emptyID('uuid4'); // \"00000000-0000-0000-0000-000000000000\"\n * validateID('uuid4', emptyUuid); // true\n * isEmptyID('uuid4', emptyUuid); // true\n * ```\n */\nexport function emptyID(type: IdentifierType): string {\n assertIdentifierType(type);\n\n if (type === 'objectID') {\n return '0'.repeat(24);\n } else if (type === 'uuid4' || type === 'uuid7') {\n return '00000000-0000-0000-0000-000000000000';\n } else if (type === 'ulid') {\n return '0'.repeat(26);\n } else {\n throw new TypeError(`Unhandled identifier type: \"${type as string}\"`);\n }\n}\n\n/**\n * Checks if an identifier is an empty/null ID.\n *\n * Compares the provided ID against the empty ID for the specified type.\n * This is useful for checking if an ID represents a null/empty state.\n *\n * @param type - The identifier type to check against\n * @param id - The identifier string to check\n * @returns `true` if the ID is empty for the specified type, `false` otherwise.\n * Non-string `id` values return `false`.\n * @throws {TypeError} If an invalid type is provided\n *\n * @example\n * ```typescript\n * const emptyUuid = emptyID('uuid4');\n * const realUuid = generateID('uuid4');\n *\n * isEmptyID('uuid4', emptyUuid); // true\n * isEmptyID('uuid4', realUuid); // false\n * ```\n */\nexport function isEmptyID(type: IdentifierType, id: string): boolean {\n assertIdentifierType(type);\n\n if (typeof id !== 'string') {\n return false;\n }\n\n return emptyID(type) === id;\n}\n\n/**\n * Helper class for working with identifiers of a specific type.\n *\n * This class provides a convenient way to work with IDs without repeatedly\n * specifying the type parameter. Initialize it with your preferred ID type,\n * then use its methods without passing the type each time.\n *\n * @example\n * ```typescript\n * // Create a helper for UUID v7 identifiers\n * const idHelper = new IDHelpers('uuid7');\n *\n * // Generate IDs without specifying type each time\n * const id1 = idHelper.generateID();\n * const id2 = idHelper.generateID(Date.now());\n *\n * // Validate IDs\n * if (idHelper.validateID(someId)) {\n * console.log('Valid uuid7');\n * }\n *\n * // Check for empty IDs\n * const empty = idHelper.emptyID();\n * console.log(idHelper.isEmptyID(empty)); // true\n * ```\n */\nexport class IDHelpers {\n private _type: IdentifierType;\n\n /**\n * Gets the identifier type this helper is configured for.\n */\n public get type(): IdentifierType {\n return this._type;\n }\n\n /**\n * Creates a new ID helper for the specified type.\n * @param type - The identifier type to use for all operations\n * @throws {TypeError} If an invalid type is provided\n */\n constructor(type: IdentifierType) {\n assertIdentifierType(type);\n this._type = type;\n }\n\n /**\n * Generates a new identifier using the configured type.\n * @param seedTime - Optional timestamp in milliseconds to seed the ID with\n * @returns A unique identifier string\n */\n public generateID(seedTime?: number): string {\n return generateID(this._type, seedTime);\n }\n\n /**\n * Validates an identifier against the configured type.\n * @param id - The identifier string to validate\n * @returns `true` if valid, `false` otherwise\n */\n public validateID(id: string): boolean {\n return validateID(this._type, id);\n }\n\n /**\n * Returns an empty identifier for the configured type.\n * @returns An empty identifier string\n */\n public emptyID(): string {\n return emptyID(this._type);\n }\n\n /**\n * Checks if an identifier is empty for the configured type.\n * @param id - The identifier string to check\n * @returns `true` if empty, `false` otherwise\n */\n public isEmptyID(id: string): boolean {\n return isEmptyID(this._type, id);\n }\n}\n","/**\n * Returns the current unix time in seconds\n *\n * ```typescript\n * const time = unix();\n * ```\n */\n\nexport function unix(): number {\n return Math.floor(Date.now() / 1000);\n}\n\n/**\n * Returns the current unix time in milliseconds\n *\n * ```typescript\n * const time = ms();\n * ```\n */\n\nexport function ms(): number {\n return Date.now();\n}\n\n/**\n * Returns a high resolution timestamp\n * Returns the time measured in milliseconds\n * This is aimed at performance monitoring\n *\n * ```typescript\n * const time = performance();\n * ```\n */\n\nexport function performance(): number {\n return globalThis.performance.now();\n}\n\n/**\n * Converts a Unix timestamp from milliseconds to seconds.\n * Useful for converting the millisecond-based timestamp from JavaScript's Date.now() into a Unix timestamp in seconds.\n *\n * @param {number} value - Unix timestamp in milliseconds.\n * @returns {number} - Unix timestamp converted to seconds.\n *\n * ```typescript\n * convertMSToUnix(1593189055006); // returns 1593189055\n * ```\n */\n\nexport function convertMSToUnix(value: number): number {\n return Math.floor(value / 1000);\n}\n\n/**\n * Converts a Unix timestamp from seconds to milliseconds.\n *\n * This function takes a Unix timestamp in seconds and converts it to milliseconds.\n * This is useful when dealing with JavaScript's Date object or other systems that\n * require time in milliseconds.\n *\n * @param {number} value - The Unix timestamp in seconds.\n * @returns {number} The Unix timestamp in milliseconds.\n *\n * Example:\n * ```typescript\n * convertUnix(1593189055); // returns 1593189055000\n * ```\n */\n\nexport function convertUnixToMS(value: number): number {\n return value * 1000;\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/is-boolean.ts
21
+ var is_boolean_exports = {};
22
+ __export(is_boolean_exports, {
23
+ isBoolean: () => isBoolean
24
+ });
25
+ module.exports = __toCommonJS(is_boolean_exports);
26
+ function isBoolean(value) {
27
+ return typeof value === "boolean";
28
+ }
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ isBoolean
32
+ });
33
+ //# sourceMappingURL=is-boolean.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/is-boolean.ts"],"sourcesContent":["/**\n * Type guard to check if a value is a boolean.\n *\n * @param value - Value to check\n * @returns `true` if the value is a boolean, `false` otherwise\n *\n * @example\n * ```typescript\n * isBoolean(true); // true\n * isBoolean(false); // true\n * isBoolean(1); // false\n * isBoolean('true'); // false\n * isBoolean(null); // false\n * isBoolean(undefined); // false\n * ```\n */\nexport function isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,SAAS,UAAU,OAAkC;AAC1D,SAAO,OAAO,UAAU;AAC1B;","names":[]}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Type guard to check if a value is a boolean.
3
+ *
4
+ * @param value - Value to check
5
+ * @returns `true` if the value is a boolean, `false` otherwise
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * isBoolean(true); // true
10
+ * isBoolean(false); // true
11
+ * isBoolean(1); // false
12
+ * isBoolean('true'); // false
13
+ * isBoolean(null); // false
14
+ * isBoolean(undefined); // false
15
+ * ```
16
+ */
17
+ declare function isBoolean(value: unknown): value is boolean;
18
+
19
+ export { isBoolean };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Type guard to check if a value is a boolean.
3
+ *
4
+ * @param value - Value to check
5
+ * @returns `true` if the value is a boolean, `false` otherwise
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * isBoolean(true); // true
10
+ * isBoolean(false); // true
11
+ * isBoolean(1); // false
12
+ * isBoolean('true'); // false
13
+ * isBoolean(null); // false
14
+ * isBoolean(undefined); // false
15
+ * ```
16
+ */
17
+ declare function isBoolean(value: unknown): value is boolean;
18
+
19
+ export { isBoolean };
@@ -0,0 +1,8 @@
1
+ // src/lib/is-boolean.ts
2
+ function isBoolean(value) {
3
+ return typeof value === "boolean";
4
+ }
5
+ export {
6
+ isBoolean
7
+ };
8
+ //# sourceMappingURL=is-boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/is-boolean.ts"],"sourcesContent":["/**\n * Type guard to check if a value is a boolean.\n *\n * @param value - Value to check\n * @returns `true` if the value is a boolean, `false` otherwise\n *\n * @example\n * ```typescript\n * isBoolean(true); // true\n * isBoolean(false); // true\n * isBoolean(1); // false\n * isBoolean('true'); // false\n * isBoolean(null); // false\n * isBoolean(undefined); // false\n * ```\n */\nexport function isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean';\n}\n"],"mappings":";AAgBO,SAAS,UAAU,OAAkC;AAC1D,SAAO,OAAO,UAAU;AAC1B;","names":[]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/is-function.ts
21
+ var is_function_exports = {};
22
+ __export(is_function_exports, {
23
+ isFunction: () => isFunction
24
+ });
25
+ module.exports = __toCommonJS(is_function_exports);
26
+ function isFunction(value) {
27
+ return typeof value === "function" || value instanceof Function;
28
+ }
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ isFunction
32
+ });
33
+ //# sourceMappingURL=is-function.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/is-function.ts"],"sourcesContent":["export function isFunction(value: unknown): boolean {\n return typeof value === 'function' || value instanceof Function;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,WAAW,OAAyB;AAClD,SAAO,OAAO,UAAU,cAAc,iBAAiB;AACzD;","names":[]}
@@ -0,0 +1,3 @@
1
+ declare function isFunction(value: unknown): boolean;
2
+
3
+ export { isFunction };
@@ -0,0 +1,3 @@
1
+ declare function isFunction(value: unknown): boolean;
2
+
3
+ export { isFunction };
@@ -0,0 +1,8 @@
1
+ // src/lib/is-function.ts
2
+ function isFunction(value) {
3
+ return typeof value === "function" || value instanceof Function;
4
+ }
5
+ export {
6
+ isFunction
7
+ };
8
+ //# sourceMappingURL=is-function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/is-function.ts"],"sourcesContent":["export function isFunction(value: unknown): boolean {\n return typeof value === 'function' || value instanceof Function;\n}\n"],"mappings":";AAAO,SAAS,WAAW,OAAyB;AAClD,SAAO,OAAO,UAAU,cAAc,iBAAiB;AACzD;","names":[]}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/is-number.ts
21
+ var is_number_exports = {};
22
+ __export(is_number_exports, {
23
+ isFiniteNumber: () => isFiniteNumber,
24
+ isNumber: () => isNumber
25
+ });
26
+ module.exports = __toCommonJS(is_number_exports);
27
+ function isNumber(value) {
28
+ return typeof value === "number" && !isNaN(value);
29
+ }
30
+ function isFiniteNumber(value) {
31
+ return typeof value === "number" && isFinite(value);
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ isFiniteNumber,
36
+ isNumber
37
+ });
38
+ //# sourceMappingURL=is-number.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/is-number.ts"],"sourcesContent":["/**\n * Type guard to check if a value is a valid number.\n *\n * @param value - Value to check\n * @returns `true` if the value is a number and not NaN, `false` otherwise\n *\n * @example\n * ```typescript\n * isNumber(42); // true\n * isNumber(3.14); // true\n * isNumber(NaN); // false\n * isNumber('123'); // false\n * isNumber(null); // false\n * isNumber(undefined); // false\n * ```\n */\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number' && !isNaN(value);\n}\n\n/**\n * Type guard to check if a value is a finite number.\n *\n * @param value - Value to check\n * @returns `true` if the value is a number and is finite (excludes NaN, Infinity, -Infinity), `false` otherwise\n *\n * @example\n * ```typescript\n * isFiniteNumber(42); // true\n * isFiniteNumber(3.14); // true\n * isFiniteNumber(Infinity); // false\n * isFiniteNumber(-Infinity); // false\n * isFiniteNumber(NaN); // false\n * isFiniteNumber('123'); // false\n * isFiniteNumber(null); // false\n * isFiniteNumber(undefined); // false\n * ```\n */\nexport function isFiniteNumber(value: unknown): value is number {\n return typeof value === 'number' && isFinite(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,SAAS,SAAS,OAAiC;AACxD,SAAO,OAAO,UAAU,YAAY,CAAC,MAAM,KAAK;AAClD;AAoBO,SAAS,eAAe,OAAiC;AAC9D,SAAO,OAAO,UAAU,YAAY,SAAS,KAAK;AACpD;","names":[]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Type guard to check if a value is a valid number.
3
+ *
4
+ * @param value - Value to check
5
+ * @returns `true` if the value is a number and not NaN, `false` otherwise
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * isNumber(42); // true
10
+ * isNumber(3.14); // true
11
+ * isNumber(NaN); // false
12
+ * isNumber('123'); // false
13
+ * isNumber(null); // false
14
+ * isNumber(undefined); // false
15
+ * ```
16
+ */
17
+ declare function isNumber(value: unknown): value is number;
18
+ /**
19
+ * Type guard to check if a value is a finite number.
20
+ *
21
+ * @param value - Value to check
22
+ * @returns `true` if the value is a number and is finite (excludes NaN, Infinity, -Infinity), `false` otherwise
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * isFiniteNumber(42); // true
27
+ * isFiniteNumber(3.14); // true
28
+ * isFiniteNumber(Infinity); // false
29
+ * isFiniteNumber(-Infinity); // false
30
+ * isFiniteNumber(NaN); // false
31
+ * isFiniteNumber('123'); // false
32
+ * isFiniteNumber(null); // false
33
+ * isFiniteNumber(undefined); // false
34
+ * ```
35
+ */
36
+ declare function isFiniteNumber(value: unknown): value is number;
37
+
38
+ export { isFiniteNumber, isNumber };