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 @@
1
+ {"version":3,"sources":["../../src/lib/strings.ts","../../src/lib/constants.ts","../../src/lib/padding-utils.ts","../../src/lib/ascii-tables/ascii-table-utils.ts","../../src/lib/ascii-tables/multi-column-ascii-table.ts","../../src/lib/ascii-tables/key-value-ascii-table.ts","../../src/lib/clamp.ts","../../src/lib/error-to-string.ts","../../src/lib/is-promise.ts","../../src/lib/is-function.ts","../../src/lib/safe-handle-callback.ts","../../src/lib/event-emitter.ts"],"sourcesContent":["import { removeEmptyStringsFromArray } from './arrays';\n\nexport function isString(value: unknown): value is string {\n return typeof value === 'string';\n}\n\n/**\n * Converts a string or an array of strings to Pascal Case.\n *\n * This function takes an input string or an array of strings, each potentially containing hyphens,\n * and converts them to Pascal Case. It removes any characters that are not letters or numbers,\n * capitalizes the first letter of each substring, and ensures the rest of the substring\n * is in lowercase. Finally, it concatenates all these substrings to produce a Pascal Case\n * output.\n *\n * @param {string | string[]} input - The input string or array of strings to be converted to Pascal Case.\n * @returns {string} The converted string in Pascal Case.\n *\n * Examples:\n * toPascalCase(\"hello-world-123!$\") will return \"HelloWorld123\"\n * toPascalCase([\"hello\", \"world-123!$\"]) will return \"HelloWorld123\"\n */\n\nexport function toPascalCase(input: string | string[]): string {\n // Ensure input is an array\n const inputArray = Array.isArray(input) ? input : [input];\n\n // Process each string in the array\n const parts: string[] = [];\n\n for (const item of inputArray) {\n // Clean the string, split by hyphen, and remove empty strings\n const cleanedItem = item.replace(/[^a-zA-Z0-9-]/g, '');\n parts.push(...removeEmptyStringsFromArray(cleanedItem.split('-')));\n }\n\n // Process and rejoin the input strings\n return parts\n .map(\n (subString) =>\n subString.charAt(0).toUpperCase() + subString.slice(1).toLowerCase(),\n )\n .join('');\n}\n\n/**\n * Converts a string or an array of strings to Camel Case.\n *\n * This function takes an input string or an array of strings, each potentially containing hyphens,\n * and converts them to Camel Case. It removes any characters that are not letters or numbers,\n * capitalizes the first letter of each substring after the first one, and ensures the rest of the substring\n * is in lowercase. For the first substring, it ensures the entire substring is in lowercase.\n * Finally, it concatenates all these substrings to produce a Camel Case output.\n *\n * @param {string | string[]} input - The input string or array of strings to be converted to Camel Case.\n * @returns {string} The converted string in Camel Case.\n *\n * Examples:\n * toCamelCase(\"hello-world-123!$\") will return \"helloWorld123\"\n * toCamelCase([\"hello\", \"world-123!$\"]) will return \"helloWorld123\"\n */\n\nexport function toCamelCase(input: string | string[]): string {\n // Ensure input is an array\n const inputArray = Array.isArray(input) ? input : [input];\n\n // Process each string in the array\n const parts: string[] = [];\n\n for (const item of inputArray) {\n // Clean the string, split by hyphen, and remove empty strings\n const cleanedItem = item.replace(/[^a-zA-Z0-9-]/g, '');\n parts.push(...removeEmptyStringsFromArray(cleanedItem.split('-')));\n }\n\n // Process and rejoin the input strings\n return parts\n .map((subString, index) =>\n index === 0\n ? subString.toLowerCase()\n : subString.charAt(0).toUpperCase() + subString.slice(1).toLowerCase(),\n )\n .join('');\n}\n\n/**\n * This method converts a string or an array of strings to camel case,\n * but if starting with a leading hyphen, it will convert to Pascal case.\n */\n\nexport function toCamelCaseWithPascalOverride(\n input: string | string[],\n): string {\n if (isString(input) && input.startsWith('-')) {\n return toPascalCase(input);\n } else if (\n Array.isArray(input) &&\n input.length > 0 &&\n input[0].startsWith('-')\n ) {\n return toPascalCase(input);\n } else {\n return toCamelCase(input);\n }\n}\n\n/**\n * Converts a string or an array of strings to constant case.\n *\n * The function takes a string or an array of strings, where each string can be separated by a '-',\n * and converts them into a constant case format (all uppercase with underscores between words).\n * It first cleans the input by removing non-alphanumeric characters (except for hyphens), splits the\n * string into parts on hyphens, and then joins these parts with underscores, converting the entire\n * result to uppercase.\n *\n * @param {string | string[]} input - The input string or array of strings to be converted.\n * @returns {string} The converted string in constant case.\n *\n * Example:\n * toConstantCase(\"hello-world\") will return \"HELLO_WORLD\"\n * toConstantCase([\"hello\", \"world\"]) will return \"HELLO_WORLD\"\n */\n\nexport function toConstantCase(input: string | string[]): string {\n // Ensure input is an array\n const inputArray = Array.isArray(input) ? input : [input];\n\n // Process each string in the array\n let parts: string[] = [];\n\n for (const item of inputArray) {\n // Clean the string and split by hyphen\n const cleanedItem = item.replace(/[^a-zA-Z0-9-]/g, '');\n parts.push(...cleanedItem.split('-'));\n }\n\n // Remove empty strings from the array\n parts = removeEmptyStringsFromArray(parts);\n\n // Join parts with underscore and convert to uppercase\n return parts.join('_').toUpperCase();\n}\n\nexport function splitGraphemes(text: string): string[] {\n const graphemes: string[] = [];\n let grapheme = '';\n let zwjSequence = '';\n\n for (let i = 0; i < text.length; i++) {\n const char = text[i];\n const nextChar = text[i + 1] || '';\n const code = char.charCodeAt(0);\n\n // Handling combining marks and zero width joiner\n if (\n (code >= 0x0300 && code <= 0x036f) || // Combining Diacritical Marks\n (code >= 0x1ab0 && code <= 0x1aff) || // Combining Diacritical Marks Extended\n (code >= 0x1dc0 && code <= 0x1dff) || // Combining Diacritical Marks Supplement\n (code >= 0xfe20 && code <= 0xfe2f) || // Combining Half Marks\n (code >= 0x0e31 && code <= 0x0e3a) || // Thai combining marks\n (code >= 0x0e47 && code <= 0x0e4e)\n ) {\n // Thai combining marks\n grapheme += char;\n } else if (char === '\\u200d') {\n // Zero Width Joiner (ZWJ)\n zwjSequence += grapheme + char;\n grapheme = '';\n } else {\n if (grapheme) {\n if (zwjSequence) {\n graphemes.push(zwjSequence + grapheme);\n zwjSequence = '';\n } else {\n graphemes.push(grapheme);\n }\n }\n grapheme = char;\n\n // Handle surrogate pairs (needed for certain characters including emojis)\n if (\n char >= '\\ud800' &&\n char <= '\\udbff' &&\n nextChar >= '\\udc00' &&\n nextChar <= '\\udfff'\n ) {\n grapheme += nextChar;\n i++;\n }\n }\n }\n\n if (grapheme) {\n if (zwjSequence) {\n graphemes.push(zwjSequence + grapheme);\n } else {\n graphemes.push(grapheme);\n }\n }\n\n return graphemes;\n}\n\nexport function skipTrailingNewLines(str: string): string {\n return str.replace(/\\n+$/, '');\n}\n\n/**\n * Filters a string to include only specified characters, optionally replacing disallowed characters.\n *\n * @param str - The input string to be filtered.\n * @param list - An array of allowed characters.\n * @param caseInsensitive - Optional. If true, the filtering is case-insensitive. Default is false.\n * @param replacementChar - Optional. Character to replace disallowed characters. If empty, disallowed characters are removed. Default is ''.\n * @returns A new string containing only the allowed characters from the input string, with disallowed characters optionally replaced.\n *\n * @example\n * // Case-sensitive usage, removing disallowed characters\n * characterAllowedOnly(\"Hello123!\", [\"H\", \"e\", \"l\", \"o\"]);\n * // Returns: \"Hello\"\n *\n * @example\n * // Case-insensitive usage, removing disallowed characters\n * characterAllowedOnly(\"Hello123!\", [\"h\", \"E\", \"L\", \"O\"], true);\n * // Returns: \"Hello\"\n *\n * @example\n * // Using replacement character\n * characterAllowedOnly(\"Hello123!\", [\"H\", \"e\", \"l\", \"o\"], false, \"-\");\n * // Returns: \"Hello---\"\n */\n\nexport function characterAllowedOnly(\n str: string,\n list: string[],\n // eslint-disable-next-line @typescript-eslint/naming-convention\n caseInsensitive = false,\n replacementChar = '',\n): string {\n let newStr = '';\n\n // Convert the allowed list to lowercase if case-insensitive\n if (caseInsensitive) {\n list = Array.from(new Set(list.map((item) => item.toLowerCase())));\n }\n\n // Convert the entire input string to lowercase if case-insensitive\n const processedStr = caseInsensitive ? str.toLowerCase() : str;\n\n for (const c of processedStr) {\n if (list.includes(c)) {\n newStr += c;\n } else if (replacementChar !== '') {\n newStr += replacementChar;\n }\n }\n\n return newStr;\n}\n\n// functions to chop characters from a string.\n\n/**\n * Will remove the matching first character from a string\n * @param str\n * @param char\n * @returns\n */\n\nexport function chopBeginningCharacter(str: string, char: string): string {\n if (str.startsWith(char)) {\n return str.slice(1);\n } else {\n return str;\n }\n}\n\n/**\n * Will remove the matching last character from the string\n * @param str\n * @param char\n * @returns\n */\nexport function chopEndingCharacter(str: string, char: string): string {\n if (str.endsWith(char)) {\n return str.slice(0, -1);\n } else {\n return str;\n }\n}\n\n/**\n * Will remove the matching character, from the beginning and/or end of the string if matching\n * @param str\n * @param char\n * @returns\n */\n\nexport function chopBothBeginningAndEndingCharacters(\n str: string,\n char: string,\n): string {\n return chopBeginningCharacter(chopEndingCharacter(str, char), char);\n}\n","// prettier-ignore\nexport const BLANK_SPACE = ' ';\n\nexport const EOL = '\\n';\nexport const DOUBLE_EOL = EOL + EOL;\nexport const INDENT = ' '.repeat(4);\nexport const DOUBLE_INDENT = INDENT + INDENT;\n\n// prettier-ignore\nexport const SINGLE_QUOTE = \"'\";\n\n// similar to Python string library\nexport const ASCII_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';\nexport const ASCII_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\nexport const ASCII_LETTERS = ASCII_LOWERCASE + ASCII_UPPERCASE;\nexport const DIGITS = '0123456789';\nexport const HEX_DIGITS = DIGITS + 'abcdefABCDEF';\nexport const OCT_DIGITS = '01234567';\nexport const PUNCTUATION = '!\"#$%&\\'()*+,-./:;<=>?@[\\\\]^_`{|}~';\nexport const WHITESPACE = ' \\t\\n\\r\\v\\f';\nexport const PRINTABLE = DIGITS + ASCII_LETTERS + PUNCTUATION + WHITESPACE;\n","/**\n * Utilities to pad strings with another string up to a defined length.\n * Each function takes a string, length to pad and the string to be used for padding (but defaults to a blank space if not provided) and returns the modified string\n *\n * This only pads on the left side, so text is added to the front until the total string equals the given length.\n *\n * ```typescript\n * padLeft('Hey', 6, '*'); // returns ***Hey\n * ```\n * @category String Padding\n */\n\nimport { BLANK_SPACE } from './constants';\n\nexport function padLeft(\n str: string,\n length: number,\n padStr = BLANK_SPACE,\n): string {\n return str.padStart(length, padStr);\n}\n\n/**\n * This only pads on the right side, so text is added to the end until the total string equals the given length.\n *\n * ```typescript\n * padRight('Hey', 6, '*'); // returns Hey***\n * ```\n *\n * @category String Padding\n */\n\nexport function padRight(\n str: string,\n length: number,\n padStr = BLANK_SPACE,\n): string {\n return str.padEnd(length, padStr);\n}\n\n/**\n * Same as `padCenterPreferLeft` and `padCenterPreferRight` but you can pass in a string with `left` or `right` before the padStr to use more direct.\n *\n * Defaults to `left`\n *\n * @category String Padding\n */\n\nexport function padCenter(\n str: string,\n length: number,\n prefer: 'left' | 'right' = 'left',\n padStr = BLANK_SPACE,\n): string {\n const midStrLength = length - str.length;\n\n if (midStrLength > 0) {\n const padLeftAmount =\n prefer === 'left'\n ? Math.ceil(midStrLength / 2)\n : Math.floor(midStrLength / 2);\n\n const padRightAmount =\n prefer === 'left'\n ? Math.floor(midStrLength / 2)\n : Math.ceil(midStrLength / 2);\n\n return (\n padLeft('', padLeftAmount, padStr) +\n str +\n padRight('', padRightAmount, padStr)\n );\n } else {\n return str;\n }\n}\n\n/**\n * It tries to pad equally on both sides in an attempt to center your text. However if it can't the extra character will be added to the left side\n *\n * @category String Padding\n */\n\nexport function padCenterPreferLeft(\n str: string,\n length: number,\n padStr = BLANK_SPACE,\n): string {\n return padCenter(str, length, 'left', padStr);\n}\n\n/**\n * It tries to pad equally, but if it can't the extra character will be added to the right side\n *\n * @category String Padding\n */\n\nexport function padCenterPreferRight(\n str: string,\n length: number,\n padStr = BLANK_SPACE,\n): string {\n return padCenter(str, length, 'right', padStr);\n}\n","import { padCenterPreferRight, padRight } from '../padding-utils';\nimport stringWidth from 'string-width';\nimport { splitGraphemes } from '../strings';\n\nexport class ASCIITableUtils {\n public static centerText(text: string, width: number): string {\n return padCenterPreferRight(text, width, ' ');\n }\n\n public static createSeparator(\n columnWidths: number[],\n character: string = '=',\n ): string {\n const totalWidth =\n columnWidths.reduce((sum, width) => sum + width + 3, 0) - 1;\n\n return `+${padRight('', totalWidth, character)}+`;\n }\n\n public static wrapText(text: string, maxLength: number): string[] {\n const words = text.split(' ');\n const lines: string[] = [];\n let currentLine = '';\n\n for (const word of words) {\n if (stringWidth(currentLine) + stringWidth(word) + 1 <= maxLength) {\n currentLine += (currentLine ? ' ' : '') + word;\n } else {\n if (currentLine) {\n lines.push(currentLine);\n }\n\n if (stringWidth(word) <= maxLength) {\n currentLine = word;\n } else {\n const subWords = ASCIITableUtils.splitWord(word, maxLength);\n lines.push(...subWords.slice(0, -1));\n currentLine = subWords[subWords.length - 1];\n }\n }\n }\n\n if (currentLine) {\n lines.push(currentLine);\n }\n\n return lines;\n }\n\n public static splitWord(word: string, maxLength: number): string[] {\n const graphemes = splitGraphemes(word);\n const subWords: string[] = [];\n let currentSubWord = '';\n\n for (const grapheme of graphemes) {\n if (stringWidth(currentSubWord + grapheme) <= maxLength) {\n currentSubWord += grapheme;\n } else {\n subWords.push(currentSubWord);\n currentSubWord = grapheme;\n }\n }\n\n if (currentSubWord) {\n subWords.push(currentSubWord);\n }\n\n return subWords;\n }\n}\n","import { ASCIITableUtils } from './ascii-table-utils';\nimport stringWidth from 'string-width';\n\ninterface MultiColumnASCIITableOptions {\n tableWidth?: number;\n emptyMessage?: string;\n widthMode?: 'flex' | 'fixed';\n}\n\nexport class MultiColumnASCIITable {\n private headers: string[];\n private rows: string[][];\n private tableWidth: number;\n private emptyMessage: string;\n private widthMode: 'flex' | 'fixed';\n\n constructor(headers: string[], options: MultiColumnASCIITableOptions = {}) {\n this.headers = headers;\n this.rows = [];\n this.tableWidth = options.tableWidth || 80;\n this.emptyMessage = options.emptyMessage || '';\n this.widthMode = options.widthMode || 'flex';\n\n const minTableWidth = this.getMinimumWidth();\n\n if (this.tableWidth < minTableWidth) {\n throw new Error(\n `Table width must be at least ${minTableWidth} to accommodate the headers.`,\n );\n }\n }\n\n public getMinimumWidth(): number {\n return this.headers.length * 4 + 1;\n }\n\n public addRow(row: string[]): void {\n if (row.length !== this.headers.length) {\n throw new Error(\n `Number of values in the row (${row.length}) must match the number of headers (${this.headers.length}).`,\n );\n }\n\n this.rows.push(row);\n }\n\n public toString(options: MultiColumnASCIITableOptions = {}): string {\n const tableWidth = options.tableWidth || this.tableWidth;\n const emptyMessage = options.emptyMessage || this.emptyMessage;\n\n if (this.rows.length === 0) {\n const emptyTableWidth = Math.min(tableWidth, 40);\n\n const separator = '+' + '-'.repeat(emptyTableWidth - 2) + '+';\n const emptyMessageLines = ASCIITableUtils.wrapText(\n emptyMessage,\n emptyTableWidth - 4,\n );\n\n const emptyRows = emptyMessageLines.map((line) => {\n const paddingLeft = ' '.repeat(\n Math.floor((emptyTableWidth - stringWidth(line) - 4) / 2),\n );\n\n const paddingRight = ' '.repeat(\n Math.ceil((emptyTableWidth - stringWidth(line) - 4) / 2),\n );\n\n return `| ${paddingLeft}${line}${paddingRight} |`;\n });\n\n if (emptyRows.length === 0) {\n emptyRows.push(`| ${' '.repeat(emptyTableWidth - 4)} |`);\n }\n\n return [separator, ...emptyRows, separator].join('\\n');\n }\n\n const columnWidths = this.calculateColumnWidths(options);\n\n const headerSeparator = ASCIITableUtils.createSeparator(columnWidths);\n const rowSeparator = ASCIITableUtils.createSeparator(columnWidths, '-');\n let tableString = headerSeparator + '\\n';\n\n const header = this.renderRow(this.headers, columnWidths);\n tableString += header + '\\n' + rowSeparator + '\\n';\n\n const rows = this.rows.map((row) => {\n return this.renderRow(row, columnWidths);\n });\n\n tableString += rows.join('\\n' + rowSeparator + '\\n');\n tableString += '\\n' + headerSeparator;\n\n return tableString;\n }\n\n public calculateColumnWidths(\n options: MultiColumnASCIITableOptions = {},\n ): number[] {\n const tableWidth = options.tableWidth || this.tableWidth;\n const widthMode = options.widthMode || this.widthMode;\n\n const numColumns = this.headers.length;\n\n if (widthMode === 'fixed') {\n const availableWidth = tableWidth - (numColumns + 1) * 3 + 1;\n const columnWidth = Math.floor(availableWidth / numColumns);\n const extraWidth = availableWidth % numColumns;\n const columnWidths = new Array(numColumns).fill(columnWidth);\n\n // if there is any remaining width (extraWidth), we distribute it evenly among the columns starting from the first column.\n for (let i = 0; i < extraWidth; i++) {\n columnWidths[i] += 1;\n }\n\n return columnWidths as number[];\n }\n\n const availableWidth = tableWidth - (numColumns + 1) * 3 + 1;\n const maxColumnWidth = Math.floor(availableWidth / numColumns);\n const totalContentWidth = this.headers.reduce(\n (sum, header) => sum + stringWidth(header),\n 0,\n );\n\n if (availableWidth >= totalContentWidth) {\n const remainingWidth = availableWidth - totalContentWidth;\n const extraCharWidth = Math.floor(remainingWidth / numColumns);\n const extraCharRemainder = remainingWidth % numColumns;\n\n const columnWidths = this.headers.map((header, index) => {\n const extraWidth = index < extraCharRemainder ? 1 : 0;\n return stringWidth(header) + extraCharWidth + extraWidth;\n });\n\n return columnWidths;\n } else {\n const columnWidths = this.headers.map(() => maxColumnWidth);\n\n return columnWidths;\n }\n }\n\n private renderRow(row: string[], columnWidths: number[]): string {\n const wrappedCells = row.map((value, index) => {\n const wrappedLines = ASCIITableUtils.wrapText(value, columnWidths[index]);\n\n return wrappedLines\n .map((line) => line.padEnd(columnWidths[index]))\n .join('\\n');\n });\n\n const maxLines = Math.max(\n ...wrappedCells.map((cell) => cell.split('\\n').length),\n );\n\n const paddedRows = [];\n\n for (let i = 0; i < maxLines; i++) {\n const rowLine = wrappedCells.map((cell, index) => {\n const cellLines = cell.split('\\n');\n const cellLine = cellLines[i] || '';\n const padding = ' '.repeat(columnWidths[index] - stringWidth(cellLine));\n\n return ' ' + cellLine + padding + ' ';\n });\n\n paddedRows.push('|' + rowLine.join('|') + '|');\n }\n\n return paddedRows.join('\\n');\n }\n}\n","import { isString } from '../strings';\nimport { padRight } from '../padding-utils';\nimport { MultiColumnASCIITable } from './multi-column-ascii-table';\nimport { ASCIITableUtils } from './ascii-table-utils';\nimport stringWidth from 'string-width';\nimport { clamp } from '../clamp';\n\nexport type TableRowValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | KeyValueASCIITable\n | MultiColumnASCIITable\n | NestedKeyValueEntry[];\n\ntype TableRow = TableRowRegular | TableRowOwn;\n\ninterface TableRowRegular {\n kind: 'regular';\n key: string;\n value: TableRowValue;\n}\n\ninterface TableRowOwn {\n kind: 'own';\n key: string;\n value: string | NestedKeyValueEntry[];\n}\n\nexport interface NestedKeyValueEntry {\n key: string;\n value: string | KeyValueASCIITable | NestedKeyValueEntry[];\n}\n\ninterface KeyValueASCIITableOptions {\n tableWidth?: number;\n autoAdjustWidthWhenPossible?: boolean;\n emptyMessage?: string;\n}\n\nexport class KeyValueASCIITable {\n public readonly tableWidth: number;\n private emptyMessage: string;\n private autoAdjustWidthWhenPossible: boolean = true;\n\n private rows: TableRow[] = [];\n\n constructor(options: KeyValueASCIITableOptions = {}) {\n const minTableWidth = this.getMinimumWidth();\n\n if (options.tableWidth && options.tableWidth < minTableWidth) {\n throw new Error(\n `Table width must be at least ${minTableWidth} to accommodate the table structure.`,\n );\n }\n\n this.tableWidth = options.tableWidth || 80;\n this.autoAdjustWidthWhenPossible =\n options.autoAdjustWidthWhenPossible ?? true;\n this.emptyMessage = options.emptyMessage || '';\n }\n\n public getMinimumWidth(): number {\n // The minimum width for the KeyValueASCIITable is 9 characters:\n // - 2 character for the '| ' at the start\n // - 1 character for the minimum key column width\n // - 3 character for the ' | ' separating the key and value columns\n // - 1 character for the minimum value column width\n // - 2 character for the ' |' at the end\n\n return 9;\n }\n\n /**\n * Adds key and value to the table but placing the value on its own row.\n *\n * @param key\n * @param value\n */\n\n public addValueOnSeparateRow(key: string, value: string): void {\n const row: TableRow = { kind: 'own', key, value };\n\n this.rows.push(row);\n }\n\n /**\n * Adds key and value to the table.\n *\n * If provided value is an instance of ASCIITable or MultiColumnASCIITable, it will be rendered as a nested table on its own row for readability.\n *\n * @param key\n * @param value\n */\n\n public addRow(key: string, value: TableRowValue): void {\n const row: TableRow = { kind: 'regular', key, value };\n\n this.rows.push(row);\n }\n\n public toString(options: KeyValueASCIITableOptions = {}): string {\n const tableWidth = options.tableWidth || this.tableWidth;\n const canAutoAdjustWidthWhenPossible =\n options.autoAdjustWidthWhenPossible ?? this.autoAdjustWidthWhenPossible;\n\n const emptyMessage = options.emptyMessage || this.emptyMessage;\n\n if (this.rows.length === 0) {\n const emptyTableWidth = Math.min(tableWidth, 40);\n\n const separator = '+' + '-'.repeat(emptyTableWidth - 2) + '+';\n const emptyMessageLines = ASCIITableUtils.wrapText(\n emptyMessage,\n emptyTableWidth - 4,\n );\n\n const emptyRows = emptyMessageLines.map((line) => {\n const paddingLeft = padRight(\n '',\n Math.floor((emptyTableWidth - stringWidth(line) - 4) / 2),\n ' ',\n );\n\n const paddingRight = padRight(\n '',\n Math.ceil((emptyTableWidth - stringWidth(line) - 4) / 2),\n ' ',\n );\n\n return `| ${paddingLeft}${line}${paddingRight} |`;\n });\n\n if (emptyRows.length === 0) {\n emptyRows.push(`| ${' '.repeat(emptyTableWidth - 4)} |`);\n }\n\n return [separator, ...emptyRows, separator].join('\\n');\n }\n\n const columnWidths = this.calculateColumnWidths(options);\n\n const headerSeparator = ASCIITableUtils.createSeparator(columnWidths);\n const rowSeparator = ASCIITableUtils.createSeparator(columnWidths, '-');\n\n let tableString = headerSeparator + '\\n';\n\n for (const [rowIndex, row] of this.rows.entries()) {\n const { kind, key, value } = row;\n\n if (\n kind === 'own' ||\n value instanceof KeyValueASCIITable ||\n value instanceof MultiColumnASCIITable ||\n Array.isArray(value)\n ) {\n const keyString = ASCIITableUtils.centerText(\n key,\n columnWidths[0] + columnWidths[1] + 3,\n );\n\n tableString += `| ${keyString} |\\n`;\n tableString += rowSeparator + '\\n';\n\n let valueString = '';\n\n if (value instanceof KeyValueASCIITable) {\n valueString = this.formatValue(\n value,\n tableWidth - 4,\n canAutoAdjustWidthWhenPossible,\n '',\n );\n } else if (value instanceof MultiColumnASCIITable) {\n valueString = this.formatValue(\n value,\n tableWidth - 4,\n canAutoAdjustWidthWhenPossible,\n '',\n );\n } else if (Array.isArray(value)) {\n valueString = this.formatValue(\n value,\n tableWidth - 4,\n canAutoAdjustWidthWhenPossible,\n '',\n );\n } else if (row.kind === 'own') {\n valueString = this.formatTableRowOnOwnRow(\n value as string,\n tableWidth - 4,\n tableWidth,\n );\n }\n\n const valueLines = valueString.split('\\n');\n const paddedValueLines = valueLines.map((line) => {\n const padding = padRight('', tableWidth - stringWidth(line) - 4, ' ');\n\n return `| ${line}${padding} |`;\n });\n\n tableString += paddedValueLines.join('\\n') + '\\n';\n tableString += headerSeparator + '\\n';\n } else {\n const keyLines = ASCIITableUtils.wrapText(key, columnWidths[0]);\n\n const valueLines = ASCIITableUtils.wrapText(\n this.formatValue(\n value,\n columnWidths[1],\n canAutoAdjustWidthWhenPossible,\n '',\n ),\n columnWidths[1],\n );\n\n const maxLines = Math.max(keyLines.length, valueLines.length);\n\n for (let i = 0; i < maxLines; i++) {\n const keyLine = keyLines[i] || '';\n const valueLine = valueLines[i] || '';\n\n const keyPadding = ' '.repeat(columnWidths[0] - stringWidth(keyLine));\n\n const valuePadding = ' '.repeat(\n columnWidths[1] - stringWidth(valueLine),\n );\n\n tableString += `| ${keyLine}${keyPadding} | ${valueLine}${valuePadding} |\\n`;\n\n if (i === maxLines - 1) {\n if (rowIndex === this.rows.length - 1) {\n tableString += headerSeparator + '\\n';\n } else {\n tableString += rowSeparator + '\\n';\n }\n }\n }\n }\n }\n\n return tableString.trim();\n }\n\n private calculateColumnWidths(\n options: KeyValueASCIITableOptions = {},\n ): number[] {\n const tableWidth = options.tableWidth || this.tableWidth;\n const canAutoAdjustWidthWhenPossible =\n options.autoAdjustWidthWhenPossible ?? this.autoAdjustWidthWhenPossible;\n\n const columnWidths: number[] = [0, 0];\n\n for (const row of this.rows) {\n const { key, value } = row;\n\n const keyWidth = stringWidth(key);\n const maxKeyWidth = Math.floor((tableWidth - 7) / 2);\n\n if (keyWidth > columnWidths[0]) {\n columnWidths[0] = Math.min(keyWidth, maxKeyWidth);\n columnWidths[1] = Math.max(0, tableWidth - columnWidths[0] - 7);\n }\n\n if (typeof value === 'string') {\n const valueWidth = Math.max(\n ...value.split('\\n').map((line) => stringWidth(line)),\n );\n\n if (valueWidth > columnWidths[1]) {\n columnWidths[1] = Math.min(\n valueWidth,\n tableWidth - columnWidths[0] - 7,\n );\n\n columnWidths[0] = Math.max(0, tableWidth - columnWidths[1] - 7);\n }\n } else if (row.kind === 'own') {\n let valueWidth = 0;\n\n if (isString(value)) {\n valueWidth = Math.max(\n ...value.split('\\n').map((line) => stringWidth(line)),\n );\n }\n\n if (valueWidth > columnWidths[1]) {\n columnWidths[1] = Math.min(\n valueWidth,\n tableWidth - columnWidths[0] - 7,\n );\n\n columnWidths[0] = Math.max(0, tableWidth - columnWidths[1] - 7);\n }\n } else if (value instanceof KeyValueASCIITable) {\n // Update column widths based on the nested table\n let nestedTableColumnWidths: number[] = [];\n\n if (canAutoAdjustWidthWhenPossible) {\n const minWidth = value.getMinimumWidth();\n\n const availableWidth = tableWidth - columnWidths[0] - 7;\n const adjustedWidth = clamp(availableWidth, minWidth, availableWidth);\n\n nestedTableColumnWidths = value.calculateColumnWidths({\n tableWidth: adjustedWidth,\n });\n } else {\n nestedTableColumnWidths = value.calculateColumnWidths();\n }\n\n const nestedTableWidth =\n nestedTableColumnWidths.reduce((sum, width) => sum + width, 0) +\n nestedTableColumnWidths.length * 3 -\n 1;\n\n const availableWidth = tableWidth - columnWidths[0] - 7;\n\n if (nestedTableWidth > availableWidth) {\n columnWidths[1] = availableWidth;\n } else {\n columnWidths[1] = Math.max(columnWidths[1], nestedTableWidth);\n }\n } else if (value instanceof MultiColumnASCIITable) {\n // Update column widths based on the nested multi-column table\n let nestedTableColumnWidths: number[] = [];\n\n if (canAutoAdjustWidthWhenPossible) {\n const minWidth = value.getMinimumWidth();\n\n const availableWidth = tableWidth - columnWidths[0] - 7;\n const adjustedWidth = clamp(availableWidth, minWidth, availableWidth);\n\n nestedTableColumnWidths = value.calculateColumnWidths({\n tableWidth: adjustedWidth,\n });\n } else {\n nestedTableColumnWidths = value.calculateColumnWidths();\n }\n\n const nestedTableWidth =\n nestedTableColumnWidths.reduce((sum, width) => sum + width, 0) +\n nestedTableColumnWidths.length * 3 -\n 1;\n\n const availableWidth = tableWidth - columnWidths[0] - 7;\n\n if (nestedTableWidth > availableWidth) {\n columnWidths[1] = availableWidth;\n } else {\n columnWidths[1] = Math.max(columnWidths[1], nestedTableWidth);\n }\n } else if (Array.isArray(value)) {\n for (const nestedCell of value) {\n const nestedKeyWidth = stringWidth(nestedCell.key);\n const maxNestedKeyWidth = Math.floor((tableWidth - 7) / 2);\n\n if (nestedKeyWidth > columnWidths[0]) {\n columnWidths[0] = Math.min(nestedKeyWidth, maxNestedKeyWidth);\n columnWidths[1] = Math.max(0, tableWidth - columnWidths[0] - 7);\n }\n\n if (typeof nestedCell.value === 'string') {\n const nestedValueWidth = Math.max(\n ...nestedCell.value.split('\\n').map((line) => stringWidth(line)),\n );\n\n if (nestedValueWidth > columnWidths[1]) {\n columnWidths[1] = Math.min(\n nestedValueWidth,\n tableWidth - columnWidths[0] - 7,\n );\n columnWidths[0] = Math.max(0, tableWidth - columnWidths[1] - 7);\n }\n }\n }\n }\n }\n\n return columnWidths;\n }\n\n private formatValue(\n value:\n | string\n | number\n | boolean\n | null\n | undefined\n | KeyValueASCIITable\n | MultiColumnASCIITable\n | NestedKeyValueEntry[],\n cellWidth: number,\n canAutoAdjustWidthWhenPossible: boolean,\n indent = '',\n ): string {\n if (typeof value === 'string') {\n return value;\n } else if (typeof value === 'number') {\n return String(value);\n } else if (typeof value === 'boolean') {\n return String(value);\n } else if (value === null) {\n return 'null';\n } else if (value === undefined) {\n return 'undefined';\n } else if (value instanceof KeyValueASCIITable) {\n let nestedTableLines: string[];\n\n if (canAutoAdjustWidthWhenPossible) {\n const minWidth = value.getMinimumWidth();\n\n const adjustedWidth = clamp(cellWidth, minWidth, cellWidth);\n\n nestedTableLines = value\n .toString({ tableWidth: adjustedWidth })\n .split('\\n');\n } else {\n nestedTableLines = value.toString().split('\\n');\n }\n\n const indentedLines = nestedTableLines.map((line) => `${indent}${line}`);\n\n return indentedLines.join('\\n');\n } else if (value instanceof MultiColumnASCIITable) {\n let nestedTableLines: string[];\n\n if (canAutoAdjustWidthWhenPossible) {\n const minWidth = value.getMinimumWidth();\n\n const adjustedWidth = clamp(cellWidth, minWidth, cellWidth);\n nestedTableLines = value\n .toString({ tableWidth: adjustedWidth })\n .split('\\n');\n } else {\n nestedTableLines = value.toString().split('\\n');\n }\n\n const indentedLines = nestedTableLines.map((line) => `${indent}${line}`);\n\n return indentedLines.join('\\n');\n } else if (Array.isArray(value)) {\n const nestedValueLines: string[] = [];\n\n for (const { key, value: nestedValue } of value) {\n const formattedKey = `${indent}${key}:`;\n const formattedValue = this.formatValue(\n nestedValue,\n cellWidth - indent.length - stringWidth(key) - 2,\n canAutoAdjustWidthWhenPossible,\n `${indent}`,\n );\n\n const wrappedSpacer = padRight('', 4, ' ');\n\n const wrappedValue = formattedValue\n .split('\\n')\n .map((line) => `${indent}${wrappedSpacer}${line}`);\n\n nestedValueLines.push(formattedKey);\n nestedValueLines.push(...wrappedValue);\n nestedValueLines.push('');\n }\n\n return nestedValueLines.slice(0, -1).join('\\n');\n } else {\n throw new TypeError('Invalid value type provided');\n }\n }\n\n private formatTableRowOnOwnRow(\n value: string,\n width: number,\n maxRowLength: number,\n ): string {\n const lines = value.split('\\n');\n\n const paddedLines = lines.map((line) => {\n const wrappedLines = ASCIITableUtils.wrapText(line, maxRowLength - 4);\n\n return wrappedLines\n .map((wrappedLine) => {\n const padding = padRight(\n '',\n width - stringWidth(wrappedLine) - 2,\n ' ',\n );\n\n return `${wrappedLine}${padding}`;\n })\n .join('\\n');\n });\n\n return paddedLines.join('\\n');\n }\n}\n","export function clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(value, max));\n}\n\n/**\n * Clamps a value to a minimum, returning a default if the value is not finite or is undefined/null.\n *\n * Useful for config/settings validation where you want to:\n * - Enforce a minimum value\n * - Handle invalid inputs (Infinity, NaN, undefined, null) gracefully\n *\n * @param value - The value to clamp (can be undefined or null)\n * @param min - The minimum allowed value\n * @param defaultValue - The default to return if value is not finite or is undefined/null\n * @returns The clamped value, or defaultValue if value is not finite/undefined/null\n *\n * @example\n * ```typescript\n * finiteClampMin(5000, 1000, 3000) // 5000 (value > min)\n * finiteClampMin(500, 1000, 3000) // 1000 (enforces min)\n * finiteClampMin(Infinity, 1000, 3000) // 3000 (not finite, use default)\n * finiteClampMin(NaN, 1000, 3000) // 3000 (not finite, use default)\n * finiteClampMin(undefined, 1000, 3000) // 3000 (undefined, use default)\n * finiteClampMin(null, 1000, 3000) // 3000 (null, use default)\n * ```\n */\nexport function finiteClampMin(\n value: number | undefined | null,\n min: number,\n defaultValue: number,\n): number {\n if (value === null || value === undefined || !Number.isFinite(value)) {\n return defaultValue;\n }\n\n return Math.max(value, min);\n}\n","import type { NestedKeyValueEntry } from './ascii-tables/key-value-ascii-table';\nimport { KeyValueASCIITable } from './ascii-tables/key-value-ascii-table';\n\nfunction safeStringify(value: unknown): string {\n if (value === null || value === undefined) {\n return String(value);\n }\n\n switch (typeof value) {\n case 'string':\n return value;\n case 'number':\n case 'boolean':\n case 'bigint':\n return String(value);\n case 'object':\n return JSON.stringify(value);\n case 'function':\n return '[Function]';\n case 'symbol':\n return value.toString();\n default:\n // This should never happen, but satisfy the linter\n return String(value as string | number | boolean);\n }\n}\n\nexport function errorToString(error: unknown, maxRowLength = 80): string {\n const table = errorToASCIITable(error, maxRowLength);\n\n return table.toString();\n}\n\nfunction errorToASCIITable(\n error: unknown,\n maxRowLength: number,\n): KeyValueASCIITable {\n const table = new KeyValueASCIITable({\n tableWidth: maxRowLength,\n autoAdjustWidthWhenPossible: true,\n });\n\n if (error && typeof error === 'object') {\n const err = error as Record<string, unknown>;\n table.addRow('Key', 'Value');\n\n if (err['message']) {\n table.addRow('Message', safeStringify(err['message']));\n }\n\n if (err['name']) {\n table.addRow('Name', safeStringify(err['name']));\n }\n\n if (err['code']) {\n table.addRow('Code', safeStringify(err['code']));\n }\n\n if (err['errno']) {\n table.addRow('Errno', safeStringify(err['errno']));\n }\n\n // other conventional that might be used to enhance the error object\n if (err['errPrefix']) {\n table.addRow('Prefix', safeStringify(err['errPrefix']));\n }\n\n if (err['errType']) {\n table.addRow('errType', safeStringify(err['errType']));\n }\n\n if (err['errCode']) {\n table.addRow('errCode', safeStringify(err['errCode']));\n }\n\n if (err['additionalInfo']) {\n const additionalInfo = err['additionalInfo'] as Record<string, unknown>;\n const sensitiveFieldNames =\n (err['sensitiveFieldNames'] as string[]) || [];\n\n for (const key in additionalInfo) {\n if (sensitiveFieldNames.includes(key)) {\n table.addRow(`AdditionalInfo.${key}`, '***');\n } else {\n const value = additionalInfo[key];\n\n table.addRow(\n `AdditionalInfo.${key}`,\n stringifyValue(value, table, maxRowLength),\n );\n }\n }\n }\n\n if (err['stack']) {\n table.addValueOnSeparateRow('Stack', safeStringify(err['stack']));\n }\n }\n\n return table;\n}\n\nfunction stringifyValue(\n value: unknown,\n table: KeyValueASCIITable,\n maxRowLength: number,\n): string | KeyValueASCIITable | NestedKeyValueEntry[] {\n if (typeof value === 'string') {\n return value;\n } else if (Array.isArray(value)) {\n // Handle arrays differently\n return value\n .map((item) => {\n const result = stringifyValue(item, table, maxRowLength);\n // Convert complex types to strings for joining\n if (typeof result === 'string') {\n return result;\n } else if (result instanceof KeyValueASCIITable) {\n return result.toString();\n } else {\n return JSON.stringify(result);\n }\n })\n .join(', ');\n } else if (typeof value === 'object' && value !== null) {\n if (value instanceof Error) {\n return errorToASCIITable(value, maxRowLength - 4);\n } else {\n // Handle objects differently\n const entries: NestedKeyValueEntry[] = Object.entries(value).map(\n ([key, val]) => ({\n key,\n value: stringifyValue(val, table, maxRowLength - 4),\n }),\n );\n\n return entries;\n }\n } else {\n return String(value);\n }\n}\n","// Helper from https://github.com/then/is-promise/tree/master\n// For some reason the @types/is-promise package stopped being picked up on\n\nexport function isPromise(obj: unknown): obj is Promise<unknown> {\n return (\n !!obj &&\n (typeof obj === 'object' || typeof obj === 'function') &&\n // @ts-expect-error - obj is checked to be object/function, then property access works at runtime\n typeof obj['then'] === 'function'\n );\n}\n","export function isFunction(value: unknown): boolean {\n return typeof value === 'function' || value instanceof Function;\n}\n","import { errorToString } from './error-to-string';\nimport { isPromise } from './is-promise';\nimport { isFunction } from './is-function';\nimport { DOUBLE_EOL } from './constants';\n\n/**\n * Safely handles a callback function by catching any errors and reporting them\n * using the global `reportError` event (standard API available in Node.js 15+, Bun, Deno, and browsers).\n * This function can seamlessly handle both synchronous and asynchronous (Promise-based) callback functions.\n *\n * Errors are dispatched as ErrorEvent objects with type 'reportError' via `globalThis.dispatchEvent()`.\n * You can listen for these errors using `globalThis.addEventListener('reportError', handler)`.\n *\n * This function is a \"fire-and-forget\" type of function, meaning it doesn't wait\n * for the callback to complete and doesn't return any result or error. If you need\n * to handle the result or error of the callback, consider using the\n * `safeHandleCallbackAndWait` function instead.\n *\n * @param {string} callbackName - The name of the callback function, used for error reporting.\n * @param {unknown} callback - The callback function to be executed. It can be either a\n * synchronous function or a function that returns a Promise.\n * @param {...unknown[]} args - Additional arguments to pass to the callback function.\n */\n\nexport function safeHandleCallback(\n callbackName: string,\n callback: unknown,\n ...args: unknown[]\n): void {\n const handleError = (error: Error): void => {\n // Dispatch error using the standard reportError event API\n // Available in Node.js 15+, Bun, Deno, and browsers\n if (\n typeof (globalThis as Record<string, unknown>).dispatchEvent ===\n 'function'\n ) {\n (\n globalThis as unknown as {\n dispatchEvent: (event: Event) => void;\n }\n ).dispatchEvent(\n new ErrorEvent('reportError', {\n error: new Error(\n `Error in a callback ${callbackName}: ${DOUBLE_EOL}${errorToString(error)}`,\n ),\n }),\n );\n }\n };\n\n if (isFunction(callback)) {\n try {\n // We need to cast callback to the appropriate function type now\n const result = (callback as (...args: unknown[]) => unknown)(...args);\n\n if (isPromise(result)) {\n // Fire-and-forget async callback\n result.catch((error: unknown) => {\n handleError(error as Error);\n });\n }\n } catch (error) {\n handleError(error as Error);\n }\n } else {\n handleError(\n new Error(`Callback provided for ${callbackName} is not a function`),\n );\n }\n}\n\ninterface CallbackResult<T> {\n success: boolean;\n value?: T;\n error?: Error;\n}\n\n/**\n * Safely handles a callback function by catching any errors and reporting them\n * using the global `reportError` event (standard API available in Node.js 15+, Bun, Deno, and browsers).\n * This function can seamlessly handle both synchronous and asynchronous (Promise-based) callback\n * functions, and it waits for the callback to complete before returning the result or an error.\n *\n * Errors are dispatched as ErrorEvent objects with type 'reportError' via `globalThis.dispatchEvent()`.\n * You can listen for these errors using `globalThis.addEventListener('reportError', handler)`.\n *\n * @param {string} callbackName - The name of the callback function, used for error reporting.\n * @param {unknown} callback - The callback function to be executed. It can be either a\n * synchronous function or a function that returns a Promise.\n * @param {...unknown[]} args - Additional arguments to pass to the callback function.\n * @returns {Promise<CallbackResult<unknown>>} - A promise that resolves with an object containing\n * the success status, value (if any), and error (if any).\n */\n\nexport async function safeHandleCallbackAndWait<T>(\n callbackName: string,\n callback: unknown,\n ...args: unknown[]\n): Promise<CallbackResult<T>> {\n const handleError = (error: Error): CallbackResult<T> => {\n // Dispatch error using the standard reportError event API\n // Available in Node.js 15+, Bun, Deno, and browsers\n if (\n typeof (globalThis as Record<string, unknown>).dispatchEvent ===\n 'function'\n ) {\n (\n globalThis as unknown as {\n dispatchEvent: (event: Event) => void;\n }\n ).dispatchEvent(\n new ErrorEvent('reportError', {\n error: new Error(\n `Error in a callback ${callbackName}: ${DOUBLE_EOL}${errorToString(error)}`,\n ),\n }),\n );\n }\n\n return { success: false, error };\n };\n\n if (isFunction(callback)) {\n try {\n // We need to cast callback to the appropriate function type now\n const result = (callback as (...args: unknown[]) => unknown)(...args);\n\n if (isPromise(result)) {\n // Wait for the async callback to complete\n const value = await (result as Promise<T>);\n\n return { success: true, value };\n } else {\n return { success: true, value: result as T };\n }\n } catch (error) {\n return handleError(error as Error);\n }\n } else {\n return handleError(\n new Error(`Callback provided for ${callbackName} is not a function`),\n );\n }\n}\n","/**\n * Instead of using `EventEmitter`, you could extend `EventEmitterProtected`\n * if you want the emit method to be protected, and allow only your class to emit events.\n *\n * A simplified event emitter implementation that works in both browser and Node.js environments.\n * This provides basic event handling functionality with type safety and memory management.\n */\n\nimport { safeHandleCallback } from './safe-handle-callback';\n\ntype EventCallback<T = unknown> = (data: T) => void | Promise<void>;\n\nexport class EventEmitterProtected {\n private events: Map<string, Set<EventCallback<unknown>>>;\n\n constructor() {\n this.events = new Map();\n }\n\n /**\n * Subscribe to an event\n * @param event The event name to subscribe to\n * @param callback The callback function to be called when the event is emitted\n * @returns A function to unsubscribe from the event\n */\n public on<T = unknown>(\n event: string,\n callback: EventCallback<T>,\n ): () => void {\n if (!this.events.has(event)) {\n this.events.set(event, new Set());\n }\n const callbacks = this.events.get(event);\n\n if (callbacks) {\n callbacks.add(callback as EventCallback<unknown>);\n }\n\n // Return unsubscribe function for cleanup\n return () => {\n const callbacks = this.events.get(event);\n if (callbacks) {\n callbacks.delete(callback as EventCallback<unknown>);\n\n if (callbacks.size === 0) {\n this.events.delete(event);\n }\n }\n };\n }\n\n /**\n * Subscribe to an event once - automatically unsubscribes after first emission\n * @param event The event name to subscribe to\n * @param callback The callback function to be called when the event is emitted\n * @returns A function to unsubscribe from the event before it's called\n */\n public once<T = unknown>(\n event: string,\n callback: EventCallback<T>,\n ): () => void {\n const unsubscribe = this.on(event, (data: T) => {\n unsubscribe();\n return callback(data);\n });\n\n return unsubscribe;\n }\n\n /**\n * Check if a specific callback is registered for an event.\n * Note: For 'once' handlers, this will return true for the wrapper function, not the original callback.\n * This means hasListener will return false when checking for the original callback of a 'once' subscription.\n *\n * @param event The event name to check\n * @param callback The callback function to look for\n * @returns true if the exact callback is registered, false otherwise\n */\n public hasListener<T = unknown>(\n event: string,\n callback: EventCallback<T>,\n ): boolean {\n const callbacks = this.events.get(event);\n return callbacks?.has(callback as EventCallback<unknown>) ?? false;\n }\n\n /**\n * Check if an event has any subscribers\n * @param event The event name to check\n * @returns true if the event has subscribers, false otherwise\n */\n public hasListeners(event: string): boolean {\n const callbacks = this.events.get(event);\n return callbacks !== undefined && callbacks.size > 0;\n }\n\n /**\n * Get the number of subscribers for an event\n * @param event The event name to check\n * @returns The number of subscribers\n */\n public listenerCount(event: string): number {\n const callbacks = this.events.get(event);\n return callbacks ? callbacks.size : 0;\n }\n\n /**\n * Remove all event listeners\n * @param event Optional event name. If not provided, removes all listeners for all events\n */\n public clear(event?: string): void {\n if (event) {\n this.events.delete(event);\n } else {\n this.events.clear();\n }\n }\n\n /**\n * Emit an event with optional data\n * This method is protected to allow only derived classes to trigger events.\n * @param event The event name to emit\n * @param data Optional data to pass to the event handlers\n */\n protected emit<T = unknown>(event: string, data?: T): void {\n const callbacks = this.events.get(event);\n if (callbacks) {\n for (const callback of callbacks) {\n safeHandleCallback(`event handler for ${event}`, callback, data);\n }\n }\n }\n}\n\n/**\n * A class that implements the event emitter pattern with public emit method.\n * This class extends EventEmitterProtected and makes the emit method public.\n *\n * Use this when you want any code with access to the emitter to be able to trigger events.\n * If you want to control who can emit events, extend EventEmitterProtected instead.\n */\n\nexport class EventEmitter extends EventEmitterProtected {\n /**\n * Emit an event with optional data\n * This method is public, allowing any code with access to the emitter to trigger events.\n * @param event The event name to emit\n * @param data Optional data to pass to the event handlers\n */\n\n public emit<T = unknown>(event: string, data?: T): void {\n super.emit(event, data);\n }\n}\n"],"mappings":";AAEO,SAAS,SAAS,OAAiC;AACxD,SAAO,OAAO,UAAU;AAC1B;AA2IO,SAAS,eAAe,MAAwB;AACrD,QAAM,YAAsB,CAAC;AAC7B,MAAI,WAAW;AACf,MAAI,cAAc;AAElB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,OAAO,KAAK,CAAC;AACnB,UAAM,WAAW,KAAK,IAAI,CAAC,KAAK;AAChC,UAAM,OAAO,KAAK,WAAW,CAAC;AAG9B,QACG,QAAQ,OAAU,QAAQ;AAAA,IAC1B,QAAQ,QAAU,QAAQ;AAAA,IAC1B,QAAQ,QAAU,QAAQ;AAAA,IAC1B,QAAQ,SAAU,QAAQ;AAAA,IAC1B,QAAQ,QAAU,QAAQ;AAAA,IAC1B,QAAQ,QAAU,QAAQ,MAC3B;AAEA,kBAAY;AAAA,IACd,WAAW,SAAS,UAAU;AAE5B,qBAAe,WAAW;AAC1B,iBAAW;AAAA,IACb,OAAO;AACL,UAAI,UAAU;AACZ,YAAI,aAAa;AACf,oBAAU,KAAK,cAAc,QAAQ;AACrC,wBAAc;AAAA,QAChB,OAAO;AACL,oBAAU,KAAK,QAAQ;AAAA,QACzB;AAAA,MACF;AACA,iBAAW;AAGX,UACE,QAAQ,YACR,QAAQ,YACR,YAAY,YACZ,YAAY,UACZ;AACA,oBAAY;AACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,MAAI,UAAU;AACZ,QAAI,aAAa;AACf,gBAAU,KAAK,cAAc,QAAQ;AAAA,IACvC,OAAO;AACL,gBAAU,KAAK,QAAQ;AAAA,IACzB;AAAA,EACF;AAEA,SAAO;AACT;;;ACxMO,IAAM,cAAc;AAEpB,IAAM,MAAM;AACZ,IAAM,aAAa,MAAM;AACzB,IAAM,SAAS,IAAI,OAAO,CAAC;AAC3B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AAA;AAAA,EAWO,YACL,OACA,UACS;AACT,UAAM,YAAY,KAAK,OAAO,IAAI,KAAK;AACvC,WAAO,WAAW,IAAI,QAAkC,KAAK;AAAA,EAC/D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,aAAa,OAAwB;AAC1C,UAAM,YAAY,KAAK,OAAO,IAAI,KAAK;AACvC,WAAO,cAAc,UAAa,UAAU,OAAO;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,cAAc,OAAuB;AAC1C,UAAM,YAAY,KAAK,OAAO,IAAI,KAAK;AACvC,WAAO,YAAY,UAAU,OAAO;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAM,OAAsB;AACjC,QAAI,OAAO;AACT,WAAK,OAAO,OAAO,KAAK;AAAA,IAC1B,OAAO;AACL,WAAK,OAAO,MAAM;AAAA,IACpB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQU,KAAkB,OAAe,MAAgB;AACzD,UAAM,YAAY,KAAK,OAAO,IAAI,KAAK;AACvC,QAAI,WAAW;AACb,iBAAW,YAAY,WAAW;AAChC,2BAAmB,qBAAqB,KAAK,IAAI,UAAU,IAAI;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AACF;AAUO,IAAM,eAAN,cAA2B,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ/C,KAAkB,OAAe,MAAgB;AACtD,UAAM,KAAK,OAAO,IAAI;AAAA,EACxB;AACF;","names":["stringWidth","availableWidth","stringWidth","stringWidth","availableWidth","callbacks"]}
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/lib/id-helpers.ts
31
+ var id_helpers_exports = {};
32
+ __export(id_helpers_exports, {
33
+ IDENTIFIER_TYPES: () => IDENTIFIER_TYPES,
34
+ IDHelpers: () => IDHelpers,
35
+ emptyID: () => emptyID,
36
+ generateID: () => generateID,
37
+ isEmptyID: () => isEmptyID,
38
+ validateID: () => validateID
39
+ });
40
+ module.exports = __toCommonJS(id_helpers_exports);
41
+ var import_bson_objectid = __toESM(require("bson-objectid"), 1);
42
+ var import_uuid = require("uuid");
43
+ var import_ulid = require("ulid");
44
+
45
+ // src/lib/unix-time-helpers.ts
46
+ function convertMSToUnix(value) {
47
+ return Math.floor(value / 1e3);
48
+ }
49
+
50
+ // src/lib/id-helpers.ts
51
+ var IDENTIFIER_TYPES = ["objectID", "uuid4", "uuid7", "ulid"];
52
+ function assertIdentifierType(type) {
53
+ if (!IDENTIFIER_TYPES.includes(type)) {
54
+ throw new TypeError(
55
+ `Invalid ID type given: "${type}". Expected one of: ${IDENTIFIER_TYPES.join(", ")}`
56
+ );
57
+ }
58
+ }
59
+ function generateID(type, seedTime) {
60
+ assertIdentifierType(type);
61
+ if (seedTime !== void 0 && (!Number.isFinite(seedTime) || seedTime < 0)) {
62
+ throw new TypeError(
63
+ `seedTime must be a non-negative finite number (milliseconds), got: ${seedTime}`
64
+ );
65
+ }
66
+ if (type === "objectID") {
67
+ if (seedTime !== void 0) {
68
+ const unixTime = convertMSToUnix(seedTime);
69
+ return new import_bson_objectid.default(unixTime).toHexString();
70
+ } else {
71
+ return new import_bson_objectid.default().toHexString();
72
+ }
73
+ } else if (type === "uuid4") {
74
+ return (0, import_uuid.v4)();
75
+ } else if (type === "uuid7") {
76
+ if (seedTime !== void 0) {
77
+ return (0, import_uuid.v7)({ msecs: seedTime });
78
+ } else {
79
+ return (0, import_uuid.v7)();
80
+ }
81
+ } else if (type === "ulid") {
82
+ if (seedTime !== void 0) {
83
+ return (0, import_ulid.ulid)(seedTime);
84
+ } else {
85
+ return (0, import_ulid.ulid)();
86
+ }
87
+ } else {
88
+ throw new TypeError(`Unhandled identifier type: "${type}"`);
89
+ }
90
+ }
91
+ function validateID(type, id) {
92
+ assertIdentifierType(type);
93
+ if (typeof id !== "string") {
94
+ return false;
95
+ }
96
+ if (type === "objectID") {
97
+ if (id.match(/^[0-9a-fA-F]{24}$/)) {
98
+ return true;
99
+ } else {
100
+ return false;
101
+ }
102
+ } else if (type === "uuid4" || type === "uuid7") {
103
+ if (isEmptyID(type, id)) {
104
+ return true;
105
+ }
106
+ const isValid = (0, import_uuid.validate)(id);
107
+ if (!isValid) {
108
+ return false;
109
+ }
110
+ const version = (0, import_uuid.version)(id);
111
+ if (type === "uuid4" && version === 4) {
112
+ return true;
113
+ } else if (type === "uuid7" && version === 7) {
114
+ return true;
115
+ } else {
116
+ return false;
117
+ }
118
+ } else if (type === "ulid") {
119
+ if (id.match(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)) {
120
+ return true;
121
+ } else {
122
+ return false;
123
+ }
124
+ } else {
125
+ throw new TypeError(`Unhandled identifier type: "${type}"`);
126
+ }
127
+ }
128
+ function emptyID(type) {
129
+ assertIdentifierType(type);
130
+ if (type === "objectID") {
131
+ return "0".repeat(24);
132
+ } else if (type === "uuid4" || type === "uuid7") {
133
+ return "00000000-0000-0000-0000-000000000000";
134
+ } else if (type === "ulid") {
135
+ return "0".repeat(26);
136
+ } else {
137
+ throw new TypeError(`Unhandled identifier type: "${type}"`);
138
+ }
139
+ }
140
+ function isEmptyID(type, id) {
141
+ assertIdentifierType(type);
142
+ if (typeof id !== "string") {
143
+ return false;
144
+ }
145
+ return emptyID(type) === id;
146
+ }
147
+ var IDHelpers = class {
148
+ _type;
149
+ /**
150
+ * Gets the identifier type this helper is configured for.
151
+ */
152
+ get type() {
153
+ return this._type;
154
+ }
155
+ /**
156
+ * Creates a new ID helper for the specified type.
157
+ * @param type - The identifier type to use for all operations
158
+ * @throws {TypeError} If an invalid type is provided
159
+ */
160
+ constructor(type) {
161
+ assertIdentifierType(type);
162
+ this._type = type;
163
+ }
164
+ /**
165
+ * Generates a new identifier using the configured type.
166
+ * @param seedTime - Optional timestamp in milliseconds to seed the ID with
167
+ * @returns A unique identifier string
168
+ */
169
+ generateID(seedTime) {
170
+ return generateID(this._type, seedTime);
171
+ }
172
+ /**
173
+ * Validates an identifier against the configured type.
174
+ * @param id - The identifier string to validate
175
+ * @returns `true` if valid, `false` otherwise
176
+ */
177
+ validateID(id) {
178
+ return validateID(this._type, id);
179
+ }
180
+ /**
181
+ * Returns an empty identifier for the configured type.
182
+ * @returns An empty identifier string
183
+ */
184
+ emptyID() {
185
+ return emptyID(this._type);
186
+ }
187
+ /**
188
+ * Checks if an identifier is empty for the configured type.
189
+ * @param id - The identifier string to check
190
+ * @returns `true` if empty, `false` otherwise
191
+ */
192
+ isEmptyID(id) {
193
+ return isEmptyID(this._type, id);
194
+ }
195
+ };
196
+ // Annotate the CommonJS export names for ESM import in node:
197
+ 0 && (module.exports = {
198
+ IDENTIFIER_TYPES,
199
+ IDHelpers,
200
+ emptyID,
201
+ generateID,
202
+ isEmptyID,
203
+ validateID
204
+ });
205
+ //# sourceMappingURL=id-helpers.cjs.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAqB;AACrB,kBAKO;AACP,kBAAqB;;;AC2Cd,SAAS,gBAAgB,OAAuB;AACrD,SAAO,KAAK,MAAM,QAAQ,GAAI;AAChC;;;ADVO,IAAM,mBAAmB,CAAC,YAAY,SAAS,SAAS,MAAM;AAErE,SAAS,qBAAqB,MAA+C;AAC3E,MAAI,CAAC,iBAAiB,SAAS,IAAsB,GAAG;AACtD,UAAM,IAAI;AAAA,MACR,2BAA2B,IAAc,uBAAuB,iBAAiB,KAAK,IAAI,CAAC;AAAA,IAC7F;AAAA,EACF;AACF;AA+BO,SAAS,WAAW,MAAsB,UAA2B;AAC1E,uBAAqB,IAAI;AAEzB,MAA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;AACvB,WAAO,QAAQ,KAAK,KAAK;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,UAAU,IAAqB;AACpC,WAAO,UAAU,KAAK,OAAO,EAAE;AAAA,EACjC;AACF;","names":["ObjectID","UUIDv4","UUIDv7","uuidValidate","uuidVersion"]}
@@ -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 };