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,107 @@
1
+ declare function isString(value: unknown): value is string;
2
+ /**
3
+ * Converts a string or an array of strings to Pascal Case.
4
+ *
5
+ * This function takes an input string or an array of strings, each potentially containing hyphens,
6
+ * and converts them to Pascal Case. It removes any characters that are not letters or numbers,
7
+ * capitalizes the first letter of each substring, and ensures the rest of the substring
8
+ * is in lowercase. Finally, it concatenates all these substrings to produce a Pascal Case
9
+ * output.
10
+ *
11
+ * @param {string | string[]} input - The input string or array of strings to be converted to Pascal Case.
12
+ * @returns {string} The converted string in Pascal Case.
13
+ *
14
+ * Examples:
15
+ * toPascalCase("hello-world-123!$") will return "HelloWorld123"
16
+ * toPascalCase(["hello", "world-123!$"]) will return "HelloWorld123"
17
+ */
18
+ declare function toPascalCase(input: string | string[]): string;
19
+ /**
20
+ * Converts a string or an array of strings to Camel Case.
21
+ *
22
+ * This function takes an input string or an array of strings, each potentially containing hyphens,
23
+ * and converts them to Camel Case. It removes any characters that are not letters or numbers,
24
+ * capitalizes the first letter of each substring after the first one, and ensures the rest of the substring
25
+ * is in lowercase. For the first substring, it ensures the entire substring is in lowercase.
26
+ * Finally, it concatenates all these substrings to produce a Camel Case output.
27
+ *
28
+ * @param {string | string[]} input - The input string or array of strings to be converted to Camel Case.
29
+ * @returns {string} The converted string in Camel Case.
30
+ *
31
+ * Examples:
32
+ * toCamelCase("hello-world-123!$") will return "helloWorld123"
33
+ * toCamelCase(["hello", "world-123!$"]) will return "helloWorld123"
34
+ */
35
+ declare function toCamelCase(input: string | string[]): string;
36
+ /**
37
+ * This method converts a string or an array of strings to camel case,
38
+ * but if starting with a leading hyphen, it will convert to Pascal case.
39
+ */
40
+ declare function toCamelCaseWithPascalOverride(input: string | string[]): string;
41
+ /**
42
+ * Converts a string or an array of strings to constant case.
43
+ *
44
+ * The function takes a string or an array of strings, where each string can be separated by a '-',
45
+ * and converts them into a constant case format (all uppercase with underscores between words).
46
+ * It first cleans the input by removing non-alphanumeric characters (except for hyphens), splits the
47
+ * string into parts on hyphens, and then joins these parts with underscores, converting the entire
48
+ * result to uppercase.
49
+ *
50
+ * @param {string | string[]} input - The input string or array of strings to be converted.
51
+ * @returns {string} The converted string in constant case.
52
+ *
53
+ * Example:
54
+ * toConstantCase("hello-world") will return "HELLO_WORLD"
55
+ * toConstantCase(["hello", "world"]) will return "HELLO_WORLD"
56
+ */
57
+ declare function toConstantCase(input: string | string[]): string;
58
+ declare function splitGraphemes(text: string): string[];
59
+ declare function skipTrailingNewLines(str: string): string;
60
+ /**
61
+ * Filters a string to include only specified characters, optionally replacing disallowed characters.
62
+ *
63
+ * @param str - The input string to be filtered.
64
+ * @param list - An array of allowed characters.
65
+ * @param caseInsensitive - Optional. If true, the filtering is case-insensitive. Default is false.
66
+ * @param replacementChar - Optional. Character to replace disallowed characters. If empty, disallowed characters are removed. Default is ''.
67
+ * @returns A new string containing only the allowed characters from the input string, with disallowed characters optionally replaced.
68
+ *
69
+ * @example
70
+ * // Case-sensitive usage, removing disallowed characters
71
+ * characterAllowedOnly("Hello123!", ["H", "e", "l", "o"]);
72
+ * // Returns: "Hello"
73
+ *
74
+ * @example
75
+ * // Case-insensitive usage, removing disallowed characters
76
+ * characterAllowedOnly("Hello123!", ["h", "E", "L", "O"], true);
77
+ * // Returns: "Hello"
78
+ *
79
+ * @example
80
+ * // Using replacement character
81
+ * characterAllowedOnly("Hello123!", ["H", "e", "l", "o"], false, "-");
82
+ * // Returns: "Hello---"
83
+ */
84
+ declare function characterAllowedOnly(str: string, list: string[], caseInsensitive?: boolean, replacementChar?: string): string;
85
+ /**
86
+ * Will remove the matching first character from a string
87
+ * @param str
88
+ * @param char
89
+ * @returns
90
+ */
91
+ declare function chopBeginningCharacter(str: string, char: string): string;
92
+ /**
93
+ * Will remove the matching last character from the string
94
+ * @param str
95
+ * @param char
96
+ * @returns
97
+ */
98
+ declare function chopEndingCharacter(str: string, char: string): string;
99
+ /**
100
+ * Will remove the matching character, from the beginning and/or end of the string if matching
101
+ * @param str
102
+ * @param char
103
+ * @returns
104
+ */
105
+ declare function chopBothBeginningAndEndingCharacters(str: string, char: string): string;
106
+
107
+ export { characterAllowedOnly, chopBeginningCharacter, chopBothBeginningAndEndingCharacters, chopEndingCharacter, isString, skipTrailingNewLines, splitGraphemes, toCamelCase, toCamelCaseWithPascalOverride, toConstantCase, toPascalCase };
@@ -0,0 +1,149 @@
1
+ // src/lib/arrays.ts
2
+ function removeEmptyStringsFromArray(array) {
3
+ const newArray = [];
4
+ for (let item of array) {
5
+ item = item.trim();
6
+ if (item.length > 0) {
7
+ newArray.push(item);
8
+ }
9
+ }
10
+ return newArray;
11
+ }
12
+
13
+ // src/lib/strings.ts
14
+ function isString(value) {
15
+ return typeof value === "string";
16
+ }
17
+ function toPascalCase(input) {
18
+ const inputArray = Array.isArray(input) ? input : [input];
19
+ const parts = [];
20
+ for (const item of inputArray) {
21
+ const cleanedItem = item.replace(/[^a-zA-Z0-9-]/g, "");
22
+ parts.push(...removeEmptyStringsFromArray(cleanedItem.split("-")));
23
+ }
24
+ return parts.map(
25
+ (subString) => subString.charAt(0).toUpperCase() + subString.slice(1).toLowerCase()
26
+ ).join("");
27
+ }
28
+ function toCamelCase(input) {
29
+ const inputArray = Array.isArray(input) ? input : [input];
30
+ const parts = [];
31
+ for (const item of inputArray) {
32
+ const cleanedItem = item.replace(/[^a-zA-Z0-9-]/g, "");
33
+ parts.push(...removeEmptyStringsFromArray(cleanedItem.split("-")));
34
+ }
35
+ return parts.map(
36
+ (subString, index) => index === 0 ? subString.toLowerCase() : subString.charAt(0).toUpperCase() + subString.slice(1).toLowerCase()
37
+ ).join("");
38
+ }
39
+ function toCamelCaseWithPascalOverride(input) {
40
+ if (isString(input) && input.startsWith("-")) {
41
+ return toPascalCase(input);
42
+ } else if (Array.isArray(input) && input.length > 0 && input[0].startsWith("-")) {
43
+ return toPascalCase(input);
44
+ } else {
45
+ return toCamelCase(input);
46
+ }
47
+ }
48
+ function toConstantCase(input) {
49
+ const inputArray = Array.isArray(input) ? input : [input];
50
+ let parts = [];
51
+ for (const item of inputArray) {
52
+ const cleanedItem = item.replace(/[^a-zA-Z0-9-]/g, "");
53
+ parts.push(...cleanedItem.split("-"));
54
+ }
55
+ parts = removeEmptyStringsFromArray(parts);
56
+ return parts.join("_").toUpperCase();
57
+ }
58
+ function splitGraphemes(text) {
59
+ const graphemes = [];
60
+ let grapheme = "";
61
+ let zwjSequence = "";
62
+ for (let i = 0; i < text.length; i++) {
63
+ const char = text[i];
64
+ const nextChar = text[i + 1] || "";
65
+ const code = char.charCodeAt(0);
66
+ if (code >= 768 && code <= 879 || // Combining Diacritical Marks
67
+ code >= 6832 && code <= 6911 || // Combining Diacritical Marks Extended
68
+ code >= 7616 && code <= 7679 || // Combining Diacritical Marks Supplement
69
+ code >= 65056 && code <= 65071 || // Combining Half Marks
70
+ code >= 3633 && code <= 3642 || // Thai combining marks
71
+ code >= 3655 && code <= 3662) {
72
+ grapheme += char;
73
+ } else if (char === "\u200D") {
74
+ zwjSequence += grapheme + char;
75
+ grapheme = "";
76
+ } else {
77
+ if (grapheme) {
78
+ if (zwjSequence) {
79
+ graphemes.push(zwjSequence + grapheme);
80
+ zwjSequence = "";
81
+ } else {
82
+ graphemes.push(grapheme);
83
+ }
84
+ }
85
+ grapheme = char;
86
+ if (char >= "\uD800" && char <= "\uDBFF" && nextChar >= "\uDC00" && nextChar <= "\uDFFF") {
87
+ grapheme += nextChar;
88
+ i++;
89
+ }
90
+ }
91
+ }
92
+ if (grapheme) {
93
+ if (zwjSequence) {
94
+ graphemes.push(zwjSequence + grapheme);
95
+ } else {
96
+ graphemes.push(grapheme);
97
+ }
98
+ }
99
+ return graphemes;
100
+ }
101
+ function skipTrailingNewLines(str) {
102
+ return str.replace(/\n+$/, "");
103
+ }
104
+ function characterAllowedOnly(str, list, caseInsensitive = false, replacementChar = "") {
105
+ let newStr = "";
106
+ if (caseInsensitive) {
107
+ list = Array.from(new Set(list.map((item) => item.toLowerCase())));
108
+ }
109
+ const processedStr = caseInsensitive ? str.toLowerCase() : str;
110
+ for (const c of processedStr) {
111
+ if (list.includes(c)) {
112
+ newStr += c;
113
+ } else if (replacementChar !== "") {
114
+ newStr += replacementChar;
115
+ }
116
+ }
117
+ return newStr;
118
+ }
119
+ function chopBeginningCharacter(str, char) {
120
+ if (str.startsWith(char)) {
121
+ return str.slice(1);
122
+ } else {
123
+ return str;
124
+ }
125
+ }
126
+ function chopEndingCharacter(str, char) {
127
+ if (str.endsWith(char)) {
128
+ return str.slice(0, -1);
129
+ } else {
130
+ return str;
131
+ }
132
+ }
133
+ function chopBothBeginningAndEndingCharacters(str, char) {
134
+ return chopBeginningCharacter(chopEndingCharacter(str, char), char);
135
+ }
136
+ export {
137
+ characterAllowedOnly,
138
+ chopBeginningCharacter,
139
+ chopBothBeginningAndEndingCharacters,
140
+ chopEndingCharacter,
141
+ isString,
142
+ skipTrailingNewLines,
143
+ splitGraphemes,
144
+ toCamelCase,
145
+ toCamelCaseWithPascalOverride,
146
+ toConstantCase,
147
+ toPascalCase
148
+ };
149
+ //# sourceMappingURL=strings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/arrays.ts","../../src/lib/strings.ts"],"sourcesContent":["import { isString } from './strings';\n\nexport function isArray(value: unknown): value is unknown[] {\n return Array.isArray(value);\n}\n\nexport function removeEmptyStringsFromArray(array: string[]): string[] {\n const newArray: string[] = [];\n\n for (let item of array) {\n item = item.trim();\n\n if (item.length > 0) {\n newArray.push(item);\n }\n }\n\n return newArray;\n}\n\n/**\n * Will take an array and return a new array with a value prepended to each item\n *\n * @param array\n * @param value\n * @returns\n */\n\nexport function prependStringToArrayItems(\n array: string[],\n value: string,\n): string[] {\n const newArray: string[] = [];\n\n for (const item of array) {\n newArray.push(value + item);\n }\n\n return newArray;\n}\n\nexport function isEveryArrayItemAnString(value: unknown): boolean {\n if (Array.isArray(value)) {\n for (const item of value) {\n if (!isString(item)) {\n return false;\n }\n }\n\n return true;\n } else {\n return false;\n }\n}\n\nexport function areArraysEqual<T>(arr1: T[], arr2: T[]): boolean {\n // Check if the arrays are the same length\n if (arr1.length !== arr2.length) {\n return false;\n }\n\n // Check each element in the arrays\n for (const [i, element] of arr1.entries()) {\n if (element !== arr2[i]) {\n return false;\n }\n }\n\n // If all elements are equal\n return true;\n}\n\nexport function pushWithoutDuplicates(array: unknown[], value: unknown): void {\n if (!array.includes(value)) {\n array.push(value);\n }\n}\n","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"],"mappings":";AAMO,SAAS,4BAA4B,OAA2B;AACrE,QAAM,WAAqB,CAAC;AAE5B,WAAS,QAAQ,OAAO;AACtB,WAAO,KAAK,KAAK;AAEjB,QAAI,KAAK,SAAS,GAAG;AACnB,eAAS,KAAK,IAAI;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;;;AChBO,SAAS,SAAS,OAAiC;AACxD,SAAO,OAAO,UAAU;AAC1B;AAmBO,SAAS,aAAa,OAAkC;AAE7D,QAAM,aAAa,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;AAGxD,QAAM,QAAkB,CAAC;AAEzB,aAAW,QAAQ,YAAY;AAE7B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AAI,IAAI,KAAK,IAAI,CAAC,SAAS,KAAK,YAAY,CAAC,CAAC,CAAC;AAAA,EACnE;AAGA,QAAM,eAAe,kBAAkB,IAAI,YAAY,IAAI;AAE3D,aAAW,KAAK,cAAc;AAC5B,QAAI,KAAK,SAAS,CAAC,GAAG;AACpB,gBAAU;AAAA,IACZ,WAAW,oBAAoB,IAAI;AACjC,gBAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AACT;AAWO,SAAS,uBAAuB,KAAa,MAAsB;AACxE,MAAI,IAAI,WAAW,IAAI,GAAG;AACxB,WAAO,IAAI,MAAM,CAAC;AAAA,EACpB,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAQO,SAAS,oBAAoB,KAAa,MAAsB;AACrE,MAAI,IAAI,SAAS,IAAI,GAAG;AACtB,WAAO,IAAI,MAAM,GAAG,EAAE;AAAA,EACxB,OAAO;AACL,WAAO;AAAA,EACT;AACF;AASO,SAAS,qCACd,KACA,MACQ;AACR,SAAO,uBAAuB,oBAAoB,KAAK,IAAI,GAAG,IAAI;AACpE;","names":[]}
@@ -0,0 +1,254 @@
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/tmp-dir.ts
31
+ var tmp_dir_exports = {};
32
+ __export(tmp_dir_exports, {
33
+ ErrTmpDirCleanupFailedNotEmpty: () => ErrTmpDirCleanupFailedNotEmpty,
34
+ ErrTmpDirCleanupUnexpectedError: () => ErrTmpDirCleanupUnexpectedError,
35
+ ErrTmpDirConfigErrorBaseDirectory: () => ErrTmpDirConfigErrorBaseDirectory,
36
+ ErrTmpDirConfigErrorMaxTries: () => ErrTmpDirConfigErrorMaxTries,
37
+ ErrTmpDirInitializeMaxTriesExceeded: () => ErrTmpDirInitializeMaxTriesExceeded,
38
+ ErrTmpDirNotInitialized: () => ErrTmpDirNotInitialized,
39
+ ErrTmpDirWasCleanedUp: () => ErrTmpDirWasCleanedUp,
40
+ TmpDir: () => TmpDir,
41
+ createTempDir: () => createTempDir
42
+ });
43
+ module.exports = __toCommonJS(tmp_dir_exports);
44
+ var import_path = __toESM(require("path"), 1);
45
+ var import_os = __toESM(require("os"), 1);
46
+ var import_fs = require("fs");
47
+
48
+ // src/lib/is-number.ts
49
+ function isNumber(value) {
50
+ return typeof value === "number" && !isNaN(value);
51
+ }
52
+
53
+ // src/lib/strings.ts
54
+ function isString(value) {
55
+ return typeof value === "string";
56
+ }
57
+
58
+ // src/lib/is-boolean.ts
59
+ function isBoolean(value) {
60
+ return typeof value === "boolean";
61
+ }
62
+
63
+ // src/lib/is-plain-object.ts
64
+ function isPlainObject(value) {
65
+ return typeof value === "object" && value !== null && !Array.isArray(value);
66
+ }
67
+
68
+ // src/lib/tmp-dir.ts
69
+ function randomString(length) {
70
+ const alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
71
+ let result = "";
72
+ const alphabetLength = alphabet.length;
73
+ const randomValues = new Uint32Array(length);
74
+ crypto.getRandomValues(randomValues);
75
+ for (let i = 0; i < length; i++) {
76
+ result += alphabet[randomValues[i] % alphabetLength];
77
+ }
78
+ return result;
79
+ }
80
+ var ErrTmpDirNotInitialized = class extends Error {
81
+ constructor() {
82
+ super("The temporary directory has not been initialized yet.");
83
+ this.name = "ErrTmpDirNotInitialized";
84
+ }
85
+ };
86
+ var ErrTmpDirWasCleanedUp = class extends Error {
87
+ constructor() {
88
+ super("The temporary directory was already cleaned up.");
89
+ this.name = "ErrTmpDirWasCleanedUp";
90
+ }
91
+ };
92
+ var ErrTmpDirConfigErrorBaseDirectory = class extends Error {
93
+ constructor() {
94
+ super(
95
+ "An error occurred with the configuration. `baseDirectory` must be an absolute path."
96
+ );
97
+ this.name = "ErrTmpDirConfigErrorBaseDirectory";
98
+ }
99
+ };
100
+ var ErrTmpDirConfigErrorMaxTries = class extends Error {
101
+ constructor() {
102
+ super(
103
+ "An error occurred with the configuration. `maxTries` must be a positive integer."
104
+ );
105
+ this.name = "ErrTmpDirConfigErrorMaxTries";
106
+ }
107
+ };
108
+ var ErrTmpDirInitializeMaxTriesExceeded = class extends Error {
109
+ constructor() {
110
+ super("Could not create a unique temporary directory, maxTries exceeded.");
111
+ this.name = "ErrTmpDirInitializeMaxTriesExceeded";
112
+ }
113
+ };
114
+ var ErrTmpDirCleanupFailedNotEmpty = class extends Error {
115
+ constructor() {
116
+ super(
117
+ "Cleanup failed. The temporary directory is not empty and `unsafeCleanup` is false."
118
+ );
119
+ this.name = "ErrTmpDirCleanupFailedNotEmpty";
120
+ }
121
+ };
122
+ var ErrTmpDirCleanupUnexpectedError = class extends Error {
123
+ additionalInfo;
124
+ constructor(additionalInfo) {
125
+ super("Cleanup failed due to an unexpected error.");
126
+ this.name = "ErrTmpDirCleanupUnexpectedError";
127
+ this.additionalInfo = additionalInfo;
128
+ }
129
+ };
130
+ var TmpDir = class {
131
+ // internal properties
132
+ isInitialized = false;
133
+ wasCleanedUp = false;
134
+ fullTempDirPath = "";
135
+ // configuration properties
136
+ allowUnsafeCleanup = false;
137
+ baseDirectory = "";
138
+ maxTries = 3;
139
+ prefix = "tmp";
140
+ postfix = "";
141
+ get path() {
142
+ if (this.wasCleanedUp) {
143
+ throw new ErrTmpDirWasCleanedUp();
144
+ } else if (this.isInitialized) {
145
+ return this.fullTempDirPath;
146
+ } else {
147
+ throw new ErrTmpDirNotInitialized();
148
+ }
149
+ }
150
+ constructor(options) {
151
+ if (isPlainObject(options)) {
152
+ if (isBoolean(options.unsafeCleanup)) {
153
+ this.allowUnsafeCleanup = options.unsafeCleanup;
154
+ }
155
+ if (isString(options.baseDirectory)) {
156
+ const baseDirectory = options.baseDirectory.trim();
157
+ if (import_path.default.isAbsolute(baseDirectory)) {
158
+ this.baseDirectory = baseDirectory;
159
+ } else {
160
+ throw new ErrTmpDirConfigErrorBaseDirectory();
161
+ }
162
+ }
163
+ if (isNumber(options.maxTries)) {
164
+ const floored = Math.floor(options.maxTries);
165
+ if (isFinite(floored) && floored > 0) {
166
+ this.maxTries = floored;
167
+ } else {
168
+ throw new ErrTmpDirConfigErrorMaxTries();
169
+ }
170
+ }
171
+ if (isString(options.prefix)) {
172
+ this.prefix = options.prefix;
173
+ }
174
+ if (isString(options.postfix)) {
175
+ this.postfix = options.postfix;
176
+ }
177
+ }
178
+ if (this.baseDirectory.length === 0) {
179
+ this.baseDirectory = import_os.default.tmpdir();
180
+ }
181
+ }
182
+ async initialize() {
183
+ if (!this.isInitialized) {
184
+ let attemptsMade = 0;
185
+ while (attemptsMade < this.maxTries) {
186
+ attemptsMade++;
187
+ const name = this.generateTempDirName();
188
+ const fullPath = import_path.default.join(this.baseDirectory, name);
189
+ let doesPathExist = false;
190
+ try {
191
+ await import_fs.promises.stat(fullPath);
192
+ doesPathExist = true;
193
+ } catch {
194
+ doesPathExist = false;
195
+ }
196
+ if (!doesPathExist) {
197
+ await import_fs.promises.mkdir(fullPath, { recursive: true });
198
+ this.fullTempDirPath = fullPath;
199
+ this.isInitialized = true;
200
+ return;
201
+ }
202
+ }
203
+ throw new ErrTmpDirInitializeMaxTriesExceeded();
204
+ }
205
+ }
206
+ async cleanup() {
207
+ if (this.isInitialized && !this.wasCleanedUp) {
208
+ try {
209
+ await import_fs.promises.rm(this.fullTempDirPath, {
210
+ recursive: this.allowUnsafeCleanup,
211
+ force: this.allowUnsafeCleanup
212
+ });
213
+ this.wasCleanedUp = true;
214
+ } catch (error) {
215
+ if (error instanceof Error) {
216
+ const code = error.code;
217
+ if (code === "ENOTEMPTY" || code === "EFAULT") {
218
+ throw new ErrTmpDirCleanupFailedNotEmpty();
219
+ }
220
+ }
221
+ throw new ErrTmpDirCleanupUnexpectedError({
222
+ originalError: error
223
+ });
224
+ }
225
+ }
226
+ }
227
+ generateTempDirName() {
228
+ return [
229
+ this.prefix.length > 0 ? this.prefix + "-" : "",
230
+ process.pid,
231
+ "-",
232
+ randomString(12),
233
+ this.postfix.length > 0 ? "-" + this.postfix : ""
234
+ ].join("");
235
+ }
236
+ };
237
+ async function createTempDir(options) {
238
+ const tmpDir = new TmpDir(options);
239
+ await tmpDir.initialize();
240
+ return tmpDir;
241
+ }
242
+ // Annotate the CommonJS export names for ESM import in node:
243
+ 0 && (module.exports = {
244
+ ErrTmpDirCleanupFailedNotEmpty,
245
+ ErrTmpDirCleanupUnexpectedError,
246
+ ErrTmpDirConfigErrorBaseDirectory,
247
+ ErrTmpDirConfigErrorMaxTries,
248
+ ErrTmpDirInitializeMaxTriesExceeded,
249
+ ErrTmpDirNotInitialized,
250
+ ErrTmpDirWasCleanedUp,
251
+ TmpDir,
252
+ createTempDir
253
+ });
254
+ //# sourceMappingURL=tmp-dir.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/tmp-dir.ts","../../src/lib/is-number.ts","../../src/lib/strings.ts","../../src/lib/is-boolean.ts","../../src/lib/is-plain-object.ts"],"sourcesContent":["import path from 'path';\nimport os from 'os';\nimport { promises as fs } from 'fs';\nimport { isNumber } from './is-number';\nimport { isString } from './strings';\nimport { isBoolean } from './is-boolean';\nimport { isPlainObject } from './is-plain-object';\n\n// Helper functions\nfunction randomString(length: number): string {\n const alphabet =\n '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n let result = '';\n const alphabetLength = alphabet.length;\n const randomValues = new Uint32Array(length);\n\n // Generate random values\n crypto.getRandomValues(randomValues);\n\n // Use the random values to select characters from the alphabet\n for (let i = 0; i < length; i++) {\n result += alphabet[randomValues[i] % alphabetLength];\n }\n\n return result;\n}\n\n// Error classes\nexport class ErrTmpDirNotInitialized extends Error {\n constructor() {\n super('The temporary directory has not been initialized yet.');\n this.name = 'ErrTmpDirNotInitialized';\n }\n}\n\nexport class ErrTmpDirWasCleanedUp extends Error {\n constructor() {\n super('The temporary directory was already cleaned up.');\n this.name = 'ErrTmpDirWasCleanedUp';\n }\n}\n\nexport class ErrTmpDirConfigErrorBaseDirectory extends Error {\n constructor() {\n super(\n 'An error occurred with the configuration. `baseDirectory` must be an absolute path.',\n );\n this.name = 'ErrTmpDirConfigErrorBaseDirectory';\n }\n}\n\nexport class ErrTmpDirConfigErrorMaxTries extends Error {\n constructor() {\n super(\n 'An error occurred with the configuration. `maxTries` must be a positive integer.',\n );\n this.name = 'ErrTmpDirConfigErrorMaxTries';\n }\n}\n\nexport class ErrTmpDirInitializeMaxTriesExceeded extends Error {\n constructor() {\n super('Could not create a unique temporary directory, maxTries exceeded.');\n this.name = 'ErrTmpDirInitializeMaxTriesExceeded';\n }\n}\n\nexport class ErrTmpDirCleanupFailedNotEmpty extends Error {\n constructor() {\n super(\n 'Cleanup failed. The temporary directory is not empty and `unsafeCleanup` is false.',\n );\n this.name = 'ErrTmpDirCleanupFailedNotEmpty';\n }\n}\n\nexport class ErrTmpDirCleanupUnexpectedError extends Error {\n public additionalInfo: { originalError: Error };\n\n constructor(additionalInfo: { originalError: Error }) {\n super('Cleanup failed due to an unexpected error.');\n this.name = 'ErrTmpDirCleanupUnexpectedError';\n this.additionalInfo = additionalInfo;\n }\n}\n\ninterface TmpDirOptions {\n unsafeCleanup?: boolean; // allow cleaning up a directory that is not empty, default: false\n baseDirectory?: string; // the directory in which the temporary directory should be created, default: os.tmpdir()\n maxTries?: number; // max number of attempts to create a unique directory, default: 3\n prefix?: string; // prefix of the created directory, default: 'tmp'\n postfix?: string; // postfix of the created directory, default: ''\n}\n\n/**\n * Inspired by tmp-promise and tmp-promise with a limited subset of features\n * Was getting an error with the newer versions of `tmp-promise`,\n *\n * TypeError: removeFunction is not a function. (In 'removeFunction(fileOrDirName, next || function() {\n * })', 'removeFunction' is an instance of Object)\n * at _cleanupCallback\n * at fn (node:util:119:27)\n *\n * so decided to create a simpler version with only the features I need and native to typescript and async/await\n * as was not even using everything included and was a wrapper around another library anyways.\n */\n\nexport class TmpDir {\n // internal properties\n private isInitialized = false;\n private wasCleanedUp = false;\n private fullTempDirPath = '';\n\n // configuration properties\n private allowUnsafeCleanup = false;\n private baseDirectory = '';\n private maxTries = 3;\n private prefix = 'tmp';\n private postfix = '';\n\n public get path(): string {\n if (this.wasCleanedUp) {\n throw new ErrTmpDirWasCleanedUp();\n } else if (this.isInitialized) {\n return this.fullTempDirPath;\n } else {\n throw new ErrTmpDirNotInitialized();\n }\n }\n\n constructor(options?: TmpDirOptions) {\n if (isPlainObject(options)) {\n if (isBoolean(options.unsafeCleanup)) {\n this.allowUnsafeCleanup = options.unsafeCleanup;\n }\n\n if (isString(options.baseDirectory)) {\n // trim the baseDirectory just in case\n const baseDirectory = options.baseDirectory.trim();\n\n // check if the baseDirectory is an absolute path\n if (path.isAbsolute(baseDirectory)) {\n this.baseDirectory = baseDirectory;\n } else {\n throw new ErrTmpDirConfigErrorBaseDirectory();\n }\n }\n\n if (isNumber(options.maxTries)) {\n const floored = Math.floor(options.maxTries);\n\n if (isFinite(floored) && floored > 0) {\n this.maxTries = floored;\n } else {\n throw new ErrTmpDirConfigErrorMaxTries();\n }\n }\n\n if (isString(options.prefix)) {\n this.prefix = options.prefix;\n }\n\n if (isString(options.postfix)) {\n this.postfix = options.postfix;\n }\n }\n\n // if the baseDirectory is not set, use the system temp directory\n if (this.baseDirectory.length === 0) {\n this.baseDirectory = os.tmpdir();\n }\n }\n\n public async initialize(): Promise<void> {\n if (!this.isInitialized) {\n let attemptsMade = 0;\n\n // attempt this while the attemptsMade is less than the maxTries\n while (attemptsMade < this.maxTries) {\n attemptsMade++; // increment the attempts made\n\n // generate a temporary directory name\n const name = this.generateTempDirName();\n\n // check if the path exists\n const fullPath = path.join(this.baseDirectory, name);\n\n let doesPathExist = false;\n try {\n await fs.stat(fullPath);\n doesPathExist = true;\n } catch {\n // Path doesn't exist, which is what we want\n doesPathExist = false;\n }\n\n // only proceed if path doesn't exist\n if (!doesPathExist) {\n // create the directory\n await fs.mkdir(fullPath, { recursive: true });\n\n // set isInitialized to true and return\n this.fullTempDirPath = fullPath;\n this.isInitialized = true;\n\n return;\n }\n }\n\n // if the loop completes without finding a unique directory, throw an error\n throw new ErrTmpDirInitializeMaxTriesExceeded();\n }\n }\n\n public async cleanup(): Promise<void> {\n if (this.isInitialized && !this.wasCleanedUp) {\n try {\n await fs.rm(this.fullTempDirPath, {\n recursive: this.allowUnsafeCleanup,\n force: this.allowUnsafeCleanup,\n });\n\n this.wasCleanedUp = true;\n } catch (error) {\n // Check if directory is not empty\n // Different runtimes may return different error codes:\n // - ENOTEMPTY: directory not empty (Node.js)\n // - EFAULT: bad address (Bun when trying to delete non-empty dir without recursive)\n // - ENOENT: doesn't exist (already cleaned up, this shouldn't happen but handle it)\n if (error instanceof Error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === 'ENOTEMPTY' || code === 'EFAULT') {\n throw new ErrTmpDirCleanupFailedNotEmpty();\n }\n }\n\n throw new ErrTmpDirCleanupUnexpectedError({\n originalError: error as Error,\n });\n }\n }\n }\n\n private generateTempDirName(): string {\n return [\n this.prefix.length > 0 ? this.prefix + '-' : '',\n process.pid,\n '-',\n randomString(12),\n this.postfix.length > 0 ? '-' + this.postfix : '',\n ].join('');\n }\n}\n\nexport async function createTempDir(options?: TmpDirOptions): Promise<TmpDir> {\n const tmpDir = new TmpDir(options);\n\n await tmpDir.initialize();\n\n return tmpDir;\n}\n","/**\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","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","/**\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","/**\n * Type guard to check if a value is a plain object (not null, not an array).\n *\n * @param value - Value to check\n * @returns `true` if the value is a plain object, `false` otherwise\n *\n * @example\n * ```typescript\n * isPlainObject({}); // true\n * isPlainObject({ a: 1 }); // true\n * isPlainObject([]); // false\n * isPlainObject(null); // false\n * isPlainObject(undefined); // false\n * isPlainObject('string'); // false\n * isPlainObject(42); // false\n * ```\n */\nexport function isPlainObject(\n value: unknown,\n): value is Record<string, unknown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cAAM,IAAI,gCAAgC;AAAA,UACxC,eAAe;AAAA,QACjB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,sBAA8B;AACpC,WAAO;AAAA,MACL,KAAK,OAAO,SAAS,IAAI,KAAK,SAAS,MAAM;AAAA,MAC7C,QAAQ;AAAA,MACR;AAAA,MACA,aAAa,EAAE;AAAA,MACf,KAAK,QAAQ,SAAS,IAAI,MAAM,KAAK,UAAU;AAAA,IACjD,EAAE,KAAK,EAAE;AAAA,EACX;AACF;AAEA,eAAsB,cAAc,SAA0C;AAC5E,QAAM,SAAS,IAAI,OAAO,OAAO;AAEjC,QAAM,OAAO,WAAW;AAExB,SAAO;AACT;","names":["path","os","fs"]}
@@ -0,0 +1,63 @@
1
+ declare class ErrTmpDirNotInitialized extends Error {
2
+ constructor();
3
+ }
4
+ declare class ErrTmpDirWasCleanedUp extends Error {
5
+ constructor();
6
+ }
7
+ declare class ErrTmpDirConfigErrorBaseDirectory extends Error {
8
+ constructor();
9
+ }
10
+ declare class ErrTmpDirConfigErrorMaxTries extends Error {
11
+ constructor();
12
+ }
13
+ declare class ErrTmpDirInitializeMaxTriesExceeded extends Error {
14
+ constructor();
15
+ }
16
+ declare class ErrTmpDirCleanupFailedNotEmpty extends Error {
17
+ constructor();
18
+ }
19
+ declare class ErrTmpDirCleanupUnexpectedError extends Error {
20
+ additionalInfo: {
21
+ originalError: Error;
22
+ };
23
+ constructor(additionalInfo: {
24
+ originalError: Error;
25
+ });
26
+ }
27
+ interface TmpDirOptions {
28
+ unsafeCleanup?: boolean;
29
+ baseDirectory?: string;
30
+ maxTries?: number;
31
+ prefix?: string;
32
+ postfix?: string;
33
+ }
34
+ /**
35
+ * Inspired by tmp-promise and tmp-promise with a limited subset of features
36
+ * Was getting an error with the newer versions of `tmp-promise`,
37
+ *
38
+ * TypeError: removeFunction is not a function. (In 'removeFunction(fileOrDirName, next || function() {
39
+ * })', 'removeFunction' is an instance of Object)
40
+ * at _cleanupCallback
41
+ * at fn (node:util:119:27)
42
+ *
43
+ * so decided to create a simpler version with only the features I need and native to typescript and async/await
44
+ * as was not even using everything included and was a wrapper around another library anyways.
45
+ */
46
+ declare class TmpDir {
47
+ private isInitialized;
48
+ private wasCleanedUp;
49
+ private fullTempDirPath;
50
+ private allowUnsafeCleanup;
51
+ private baseDirectory;
52
+ private maxTries;
53
+ private prefix;
54
+ private postfix;
55
+ get path(): string;
56
+ constructor(options?: TmpDirOptions);
57
+ initialize(): Promise<void>;
58
+ cleanup(): Promise<void>;
59
+ private generateTempDirName;
60
+ }
61
+ declare function createTempDir(options?: TmpDirOptions): Promise<TmpDir>;
62
+
63
+ export { ErrTmpDirCleanupFailedNotEmpty, ErrTmpDirCleanupUnexpectedError, ErrTmpDirConfigErrorBaseDirectory, ErrTmpDirConfigErrorMaxTries, ErrTmpDirInitializeMaxTriesExceeded, ErrTmpDirNotInitialized, ErrTmpDirWasCleanedUp, TmpDir, createTempDir };