toolbox-x 1.0.0

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 (190) hide show
  1. package/LICENSE +201 -0
  2. package/dist/Color-B3mgF9Dh.d.cts +486 -0
  3. package/dist/Color-D38Xrw65.d.mts +486 -0
  4. package/dist/Stylog-Df7eq3-j.d.cts +519 -0
  5. package/dist/Stylog-jvlLcMQq.d.mts +519 -0
  6. package/dist/array-DvW0zIu6.d.mts +130 -0
  7. package/dist/array-rUnEVisO.d.cts +130 -0
  8. package/dist/basics-D_eSv0cu.cjs +132 -0
  9. package/dist/basics-Dp_aEK81.mjs +115 -0
  10. package/dist/basics-WEYWlnRO.d.cts +95 -0
  11. package/dist/basics-uBSfkBEI.d.mts +95 -0
  12. package/dist/case-BWIt8Ash.mjs +449 -0
  13. package/dist/case-C-S-b5YP.d.cts +327 -0
  14. package/dist/case-CS8Ii3A7.cjs +526 -0
  15. package/dist/case-CybASFPD.d.mts +327 -0
  16. package/dist/change-case.cjs +32 -0
  17. package/dist/change-case.d.cts +18 -0
  18. package/dist/change-case.d.mts +18 -0
  19. package/dist/change-case.mjs +19 -0
  20. package/dist/colors.cjs +574 -0
  21. package/dist/colors.d.cts +355 -0
  22. package/dist/colors.d.mts +355 -0
  23. package/dist/colors.mjs +547 -0
  24. package/dist/constants-2gAw23_7.mjs +144 -0
  25. package/dist/constants-B34K0QPi.d.cts +21 -0
  26. package/dist/constants-BIBDKY1u.cjs +924 -0
  27. package/dist/constants-BWT-810U.cjs +158 -0
  28. package/dist/constants-BwbHnXlM.mjs +662 -0
  29. package/dist/constants-BxN9l5el.cjs +74 -0
  30. package/dist/constants-CLS_bgKD.d.mts +847 -0
  31. package/dist/constants-D73iFu8g.mjs +171 -0
  32. package/dist/constants-DAfRxaa8.mjs +62 -0
  33. package/dist/constants-DQYeCjlx.cjs +207 -0
  34. package/dist/constants-Deeie-iH.d.mts +21 -0
  35. package/dist/constants-DpTG9RP6.d.mts +29 -0
  36. package/dist/constants-DqwnkJ_d.cjs +740 -0
  37. package/dist/constants-DvRUY_FY.cjs +150 -0
  38. package/dist/constants-VcRtQu0K.d.cts +29 -0
  39. package/dist/constants-X5hm1UtB.mjs +912 -0
  40. package/dist/constants-eNd-iYsV.mjs +134 -0
  41. package/dist/constants-qm8FafmD.d.cts +847 -0
  42. package/dist/constants.cjs +415 -0
  43. package/dist/constants.d.cts +184 -0
  44. package/dist/constants.d.mts +184 -0
  45. package/dist/constants.mjs +378 -0
  46. package/dist/convert-BOCgUv2D.cjs +252 -0
  47. package/dist/convert-Bn4jFomQ.mjs +169 -0
  48. package/dist/convert-BrzlG-m_.cjs +475 -0
  49. package/dist/convert-DhaUoPVU.mjs +368 -0
  50. package/dist/converter-1P90_RcP.d.mts +402 -0
  51. package/dist/converter-CmkcAppi.d.cts +402 -0
  52. package/dist/converter.cjs +780 -0
  53. package/dist/converter.d.cts +29 -0
  54. package/dist/converter.d.mts +29 -0
  55. package/dist/converter.mjs +771 -0
  56. package/dist/countries-CIpmtEzV.cjs +1469 -0
  57. package/dist/countries-Cy0xiqS3.mjs +1463 -0
  58. package/dist/css-colors-Bx947Ng3.d.cts +179 -0
  59. package/dist/css-colors-CXCDqQbG.cjs +186 -0
  60. package/dist/css-colors-CXTp1vvy.d.mts +179 -0
  61. package/dist/css-colors-DfUW3nTR.mjs +180 -0
  62. package/dist/date.cjs +332 -0
  63. package/dist/date.d.cts +213 -0
  64. package/dist/date.d.mts +213 -0
  65. package/dist/date.mjs +298 -0
  66. package/dist/dom.cjs +461 -0
  67. package/dist/dom.d.cts +228 -0
  68. package/dist/dom.d.mts +228 -0
  69. package/dist/dom.mjs +429 -0
  70. package/dist/form-BMFVGUrN.d.mts +118 -0
  71. package/dist/form-DRFbryvK.d.cts +118 -0
  72. package/dist/guards-3kaUX66g.mjs +157 -0
  73. package/dist/guards-C8gkvIHb.cjs +240 -0
  74. package/dist/guards-DdyU4h4o.mjs +110 -0
  75. package/dist/guards-Efhp1mNy.cjs +151 -0
  76. package/dist/guards.cjs +172 -0
  77. package/dist/guards.d.cts +399 -0
  78. package/dist/guards.d.mts +399 -0
  79. package/dist/guards.mjs +75 -0
  80. package/dist/hash-B6JPEyAz.d.mts +131 -0
  81. package/dist/hash-NTpeKYB_.d.cts +131 -0
  82. package/dist/hash.cjs +2126 -0
  83. package/dist/hash.d.cts +1239 -0
  84. package/dist/hash.d.mts +1239 -0
  85. package/dist/hash.mjs +2095 -0
  86. package/dist/http-status-BAZdtr7-.d.mts +65 -0
  87. package/dist/http-status-U_3MtoGb.d.cts +65 -0
  88. package/dist/http-status.cjs +173 -0
  89. package/dist/http-status.d.cts +142 -0
  90. package/dist/http-status.d.mts +142 -0
  91. package/dist/http-status.mjs +171 -0
  92. package/dist/index.cjs +2551 -0
  93. package/dist/index.d.cts +1493 -0
  94. package/dist/index.d.mts +1493 -0
  95. package/dist/index.mjs +2357 -0
  96. package/dist/object-B0TV3eHx.d.mts +8052 -0
  97. package/dist/object-Blq0Amdv.d.cts +8052 -0
  98. package/dist/objectify-CDs0Fbr1.mjs +417 -0
  99. package/dist/objectify-DIJ-OBmo.cjs +524 -0
  100. package/dist/paginator.cjs +245 -0
  101. package/dist/paginator.d.cts +144 -0
  102. package/dist/paginator.d.mts +144 -0
  103. package/dist/paginator.mjs +243 -0
  104. package/dist/parse-2ubxXZRp.cjs +211 -0
  105. package/dist/parse-N7g942uy.mjs +164 -0
  106. package/dist/pluralizer-BjMIc6uT.d.mts +42 -0
  107. package/dist/pluralizer-Cb6ZmrDl.d.cts +42 -0
  108. package/dist/pluralizer.cjs +678 -0
  109. package/dist/pluralizer.d.cts +152 -0
  110. package/dist/pluralizer.d.mts +152 -0
  111. package/dist/pluralizer.mjs +676 -0
  112. package/dist/primitives-B26uZolQ.cjs +228 -0
  113. package/dist/primitives-KsFUp3kQ.mjs +144 -0
  114. package/dist/specials-D48_IZbd.d.mts +108 -0
  115. package/dist/specials-DzLr1ZgU.cjs +477 -0
  116. package/dist/specials-LVONlKbQ.d.cts +108 -0
  117. package/dist/specials-uhDuRg8H.mjs +292 -0
  118. package/dist/string-CBAbxaG1.d.mts +258 -0
  119. package/dist/string-CsNsm_65.d.cts +258 -0
  120. package/dist/stylog.cjs +621 -0
  121. package/dist/stylog.d.cts +49 -0
  122. package/dist/stylog.d.mts +49 -0
  123. package/dist/stylog.mjs +614 -0
  124. package/dist/timezone-B2OYK6Fh.mjs +5589 -0
  125. package/dist/timezone-Beh9IGpw.cjs +5625 -0
  126. package/dist/types/array.cjs +16 -0
  127. package/dist/types/array.d.cts +18 -0
  128. package/dist/types/array.d.mts +18 -0
  129. package/dist/types/array.mjs +17 -0
  130. package/dist/types/colors.cjs +16 -0
  131. package/dist/types/colors.d.cts +18 -0
  132. package/dist/types/colors.d.mts +18 -0
  133. package/dist/types/colors.mjs +17 -0
  134. package/dist/types/converter.cjs +16 -0
  135. package/dist/types/converter.d.cts +18 -0
  136. package/dist/types/converter.d.mts +18 -0
  137. package/dist/types/converter.mjs +17 -0
  138. package/dist/types/form.cjs +16 -0
  139. package/dist/types/form.d.cts +18 -0
  140. package/dist/types/form.d.mts +18 -0
  141. package/dist/types/form.mjs +17 -0
  142. package/dist/types/hash.cjs +16 -0
  143. package/dist/types/hash.d.cts +18 -0
  144. package/dist/types/hash.d.mts +18 -0
  145. package/dist/types/hash.mjs +17 -0
  146. package/dist/types/http-status.cjs +16 -0
  147. package/dist/types/http-status.d.cts +18 -0
  148. package/dist/types/http-status.d.mts +18 -0
  149. package/dist/types/http-status.mjs +17 -0
  150. package/dist/types/index.cjs +16 -0
  151. package/dist/types/index.d.cts +18 -0
  152. package/dist/types/index.d.mts +18 -0
  153. package/dist/types/index.mjs +17 -0
  154. package/dist/types/number.cjs +16 -0
  155. package/dist/types/number.d.cts +18 -0
  156. package/dist/types/number.d.mts +18 -0
  157. package/dist/types/number.mjs +17 -0
  158. package/dist/types/object.cjs +16 -0
  159. package/dist/types/object.d.cts +18 -0
  160. package/dist/types/object.d.mts +18 -0
  161. package/dist/types/object.mjs +17 -0
  162. package/dist/types/pluralizer.cjs +16 -0
  163. package/dist/types/pluralizer.d.cts +18 -0
  164. package/dist/types/pluralizer.d.mts +18 -0
  165. package/dist/types/pluralizer.mjs +17 -0
  166. package/dist/types/string.cjs +16 -0
  167. package/dist/types/string.d.cts +18 -0
  168. package/dist/types/string.d.mts +18 -0
  169. package/dist/types/string.mjs +17 -0
  170. package/dist/types/stylog.cjs +16 -0
  171. package/dist/types/stylog.d.cts +18 -0
  172. package/dist/types/stylog.d.mts +18 -0
  173. package/dist/types/stylog.mjs +17 -0
  174. package/dist/types/utils.cjs +16 -0
  175. package/dist/types/utils.d.cts +18 -0
  176. package/dist/types/utils.d.mts +18 -0
  177. package/dist/types/utils.mjs +17 -0
  178. package/dist/types/verbalizer.cjs +16 -0
  179. package/dist/types/verbalizer.d.cts +30 -0
  180. package/dist/types/verbalizer.d.mts +30 -0
  181. package/dist/types/verbalizer.mjs +17 -0
  182. package/dist/utilities-CLUmdQeV.cjs +140 -0
  183. package/dist/utilities-m5yFKqLd.mjs +105 -0
  184. package/dist/utils-ClW9LA6f.mjs +449 -0
  185. package/dist/utils-DLFRgXUC.cjs +568 -0
  186. package/dist/verbalizer.cjs +998 -0
  187. package/dist/verbalizer.d.cts +148 -0
  188. package/dist/verbalizer.d.mts +148 -0
  189. package/dist/verbalizer.mjs +996 -0
  190. package/package.json +249 -0
@@ -0,0 +1,621 @@
1
+ /**
2
+ * Copyright 2026 - present Nazmul Hassan
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
18
+ const require_primitives = require('./primitives-B26uZolQ.cjs');
19
+ const require_css_colors = require('./css-colors-CXCDqQbG.cjs');
20
+ const require_guards = require('./guards-C8gkvIHb.cjs');
21
+ const require_convert = require('./convert-BrzlG-m_.cjs');
22
+ const require_specials = require('./specials-DzLr1ZgU.cjs');
23
+
24
+ //#region src/stylog/console.log.ts
25
+ /**
26
+ * {@link Console.log} wrapper to avoid linting issues.
27
+ * @param data Data to log in the console.
28
+ */
29
+ function _logToConsole(...data) {
30
+ console.log(data);
31
+ }
32
+
33
+ //#endregion
34
+ //#region src/stylog/constants.ts
35
+ /** ANSI styles for non-color text effects */
36
+ const ANSI_TEXT_STYLES = /* @__PURE__ */ Object.freeze({
37
+ bold: ["\x1B[1m", "\x1B[22m"],
38
+ bolder: ["\x1B[1m", "\x1B[22m"],
39
+ dim: ["\x1B[2m", "\x1B[22m"],
40
+ italic: ["\x1B[3m", "\x1B[23m"],
41
+ underline: ["\x1B[4m", "\x1B[24m"],
42
+ strikethrough: ["\x1B[9m", "\x1B[29m"],
43
+ inverse: ["\x1B[7m", "\x1B[27m"]
44
+ });
45
+ /** Browser CSS equivalents */
46
+ const CSS_TEXT_STYLES = /* @__PURE__ */ Object.freeze({
47
+ bold: "font-weight: bold",
48
+ bolder: "font-weight: bolder",
49
+ dim: "opacity: 0.7",
50
+ italic: "font-style: italic",
51
+ underline: "text-decoration: underline",
52
+ strikethrough: "text-decoration: line-through",
53
+ inverse: "filter: invert(1)"
54
+ });
55
+ /** Records of ANSI-16 colors with values */
56
+ const ANSI_16_COLORS = /* @__PURE__ */ Object.freeze({
57
+ black: [30, 39],
58
+ red: [31, 39],
59
+ green: [32, 39],
60
+ yellow: [33, 39],
61
+ blue: [34, 39],
62
+ purple: [35, 39],
63
+ cyan: [36, 39],
64
+ white: [37, 39],
65
+ blackBright: [90, 39],
66
+ redBright: [91, 39],
67
+ greenBright: [92, 39],
68
+ yellowBright: [93, 39],
69
+ blueBright: [94, 39],
70
+ purpleBright: [95, 39],
71
+ cyanBright: [96, 39],
72
+ whiteBright: [97, 39],
73
+ bgBlack: [40, 49],
74
+ bgRed: [41, 49],
75
+ bgGreen: [42, 49],
76
+ bgYellow: [43, 49],
77
+ bgBlue: [44, 49],
78
+ bgPurple: [45, 49],
79
+ bgCyan: [46, 49],
80
+ bgWhite: [47, 49],
81
+ bgBlackBright: [100, 49],
82
+ bgRedBright: [101, 49],
83
+ bgGreenBright: [102, 49],
84
+ bgYellowBright: [103, 49],
85
+ bgBlueBright: [104, 49],
86
+ bgPurpleBright: [105, 49],
87
+ bgCyanBright: [106, 49],
88
+ bgWhiteBright: [107, 49]
89
+ });
90
+ /** Browser CSS equivalents for ANSI 16 colors */
91
+ const CSS_16_COLORS = /* @__PURE__ */ Object.freeze({
92
+ black: "#000000",
93
+ red: "#800000",
94
+ green: "#008000",
95
+ yellow: "#808000",
96
+ blue: "#000080",
97
+ purple: "#800080",
98
+ cyan: "#008080",
99
+ white: "#c0c0c0",
100
+ blackBright: "#808080",
101
+ redBright: "#ff0000",
102
+ greenBright: "#00ff00",
103
+ yellowBright: "#ffff00",
104
+ blueBright: "#0000ff",
105
+ purpleBright: "#ff00ff",
106
+ cyanBright: "#00ffff",
107
+ whiteBright: "#ffffff",
108
+ bgBlack: "#000000",
109
+ bgRed: "#800000",
110
+ bgGreen: "#008000",
111
+ bgYellow: "#808000",
112
+ bgBlue: "#000080",
113
+ bgPurple: "#800080",
114
+ bgCyan: "#008080",
115
+ bgWhite: "#c0c0c0",
116
+ bgBlackBright: "#808080",
117
+ bgRedBright: "#ff0000",
118
+ bgGreenBright: "#00ff00",
119
+ bgYellowBright: "#ffff00",
120
+ bgBlueBright: "#0000ff",
121
+ bgPurpleBright: "#ff00ff",
122
+ bgCyanBright: "#00ffff",
123
+ bgWhiteBright: "#ffffff"
124
+ });
125
+
126
+ //#endregion
127
+ //#region src/stylog/helpers.ts
128
+ /**
129
+ * * Extract the CSS color name from a background-prefixed style key.
130
+ *
131
+ * @param bgColor Style key starting with `bg` (e.g. `"bgRed"`).
132
+ * @returns Extracted CSS color name.
133
+ */
134
+ function _extractColorName(bgColor) {
135
+ return bgColor.slice(2).toLowerCase();
136
+ }
137
+ /** * Check if a string represents a valid `AnsiSequence`. */
138
+ function _isAnsiSequence(seq) {
139
+ return require_specials.isArrayOfType(seq, require_primitives.isString) && seq?.length === 2 && (seq[0].startsWith("\x1B[48") || seq[0].startsWith("\x1B[38")) && (seq[1].startsWith("\x1B[49") || seq[1].startsWith("\x1B[39"));
140
+ }
141
+ /** * Check if a value represents a valid `Ansi16Value`. */
142
+ function _isAnsi16ColorValue(value) {
143
+ return require_specials.isArrayOfType(value, require_primitives.isNumber) && value?.length === 2 && value[0] >= 30 && value[0] <= 107 && (value[1] === 39 || value[1] === 49);
144
+ }
145
+ /** * Check if a value represents a valid `CSS16Color` against `Ansi16Value`. */
146
+ function _isCSS16Color(value) {
147
+ return value?.startsWith("css-") && value?.replace("css-", "") in CSS_16_COLORS;
148
+ }
149
+ /**
150
+ * * Convert a `CSS16Color` value in `Hex6` format
151
+ *
152
+ * @param value `CSS16Color` value to convert
153
+ * @returns Converted `CSS16Color` value in `Hex6` format
154
+ */
155
+ function _css16ToHex(value) {
156
+ return CSS_16_COLORS?.[value?.replace("css-", "")];
157
+ }
158
+
159
+ //#endregion
160
+ //#region src/stylog/utils.ts
161
+ /**
162
+ * * Detects color support level of the current terminal/shell.
163
+ * @returns `0 = none`, `1 = basic (16 colors)`, `2 = 256 colors`, `3 = truecolor`
164
+ */
165
+ function detectColorSupport() {
166
+ if ("NO_COLOR" in process.env) return 0;
167
+ if ("FORCE_COLOR" in process.env) return 3;
168
+ if (!process.stdout.isTTY) return 0;
169
+ const term = process.env.TERM ?? process.env.COLORTERM ?? "";
170
+ if (term === "dumb") return 0;
171
+ if (/\b256(color)?\b/i.test(term)) return 2;
172
+ if (/\btruecolor\b|\b24bit\b/i.test(term)) return 3;
173
+ return 1;
174
+ }
175
+ /**
176
+ * * Convert `RGB` color components into an `ANSI` escape code sequence.
177
+ *
178
+ * @param r Red component (`0-255`).
179
+ * @param g Green component (`0-255`).
180
+ * @param b Blue component (`0-255`).
181
+ * @param isBg Whether the color should be applied as background (`true`) or foreground (`false`). Defaults to `false`.
182
+ * @returns Tuple containing the opening and closing `ANSI` escape sequences.
183
+ */
184
+ function rgbToAnsi(r, g, b, isBg = false) {
185
+ return [`\x1b[${isBg ? 48 : 38};2;${r};${g};${b}m`, `\x1b[${isBg ? 49 : 39}m`];
186
+ }
187
+ /**
188
+ * * Convert a HEX color into an `ANSI` escape code sequence.
189
+ *
190
+ * @param hex HEX color string. e.g. `#000000`
191
+ * @param isBg Whether the color should be applied as background (`true`) or foreground (`false`). Defaults to `false`.
192
+ * @returns Tuple containing the opening and closing `ANSI` escape sequences.
193
+ */
194
+ function hexToAnsi(hex, isBg = false) {
195
+ return rgbToAnsi(...(require_convert.convertHexToRgb(hex).match(/\d+/g) || []).map(parseFloat), isBg);
196
+ }
197
+ /** * Check if a string represents `bgColor` with valid CSS color name. */
198
+ function isBGColor(value) {
199
+ return value?.startsWith("bg") && require_guards.isCSSColor(value.slice(2).toLowerCase());
200
+ }
201
+ /** * Check if a string represent `TextStyle` used in `LogStyler`. */
202
+ function isTextStyle(value) {
203
+ return value in CSS_TEXT_STYLES || value in ANSI_TEXT_STYLES;
204
+ }
205
+
206
+ //#endregion
207
+ //#region src/stylog/Stylog.ts
208
+ /**
209
+ * @class Utility class for styling console log output with `ANSI` (`Node.js`) or `CSS` (Browser).
210
+ *
211
+ * @remarks
212
+ * - Allows chaining of style methods or initializing with predefined styles.
213
+ * - For fluent, chainable styling with zero configuration use {@link https://toolbox.nazmul-nhb.dev/docs/utilities/misc/stylog Stylog} (`LogStyler` chainable wrapper).
214
+ *
215
+ * @example
216
+ * const styled = new LogStyler(['red', 'bold']);
217
+ * styled.log('Hello World');
218
+ *
219
+ * const logger = new LogStyler();
220
+ * logger.style('blue', 'dim', 'bold').log('Hello Blue');
221
+ * logger.style('blue', 'dim', 'bold').toANSI('Hello Blue');
222
+ * logger.style('blue', 'dim', 'bold').toCSS('Hello Blue');
223
+ */
224
+ var LogStyler = class LogStyler {
225
+ #styles;
226
+ /**
227
+ * * Creates a new `LogStyler` instance.
228
+ *
229
+ * @param styles - Optional array of initial styles to apply (e.g., ['red', 'bold']). Defaults to an empty array.
230
+ *
231
+ * @example
232
+ * const styled = new LogStyler(['red', 'bold']);
233
+ * styled.log('Hello World');
234
+ *
235
+ * const logger = new LogStyler();
236
+ * logger.style('blue', 'dim', 'bold').log('Hello Blue');
237
+ * logger.style('blue', 'dim', 'bold').toANSI('Hello Blue');
238
+ * logger.style('blue', 'dim', 'bold').toCSS('Hello Blue');
239
+ */
240
+ constructor(styles = []) {
241
+ this.#styles = styles;
242
+ }
243
+ #applyStyles(...style) {
244
+ return createStylogProxy(new LogStyler([...this.#styles, ...style]));
245
+ }
246
+ /**
247
+ * * Chain multiple styles to the input.
248
+ *
249
+ * @param style - One or more styles to apply (color, background, or text style).
250
+ * @returns A new StylogChain instance with the additional styles applied.
251
+ *
252
+ * @remarks
253
+ * - When chaining similar styles, only the last one(s) takes effect.
254
+ * - All colors applied through `style()` method are `truecolor` in form, to apply `ANSI-16` colors, use `ansi16()` method.
255
+ *
256
+ * @example
257
+ * // Single style
258
+ * Stylog.style('red').log('Red text');
259
+ * Stylog.style('red').toANSI('Red text');
260
+ * Stylog.style('red').toCSS('Red text');
261
+ *
262
+ * @example
263
+ * // Multiple styles at once
264
+ * Stylog.style('red', 'bold', 'underline').log('Red bold underlined text');
265
+ * Stylog.style('red', 'bold', 'underline').toANSI('Red bold underlined text');
266
+ * Stylog.style('red', 'bold', 'underline').toCSS('Red bold underlined text');
267
+ *
268
+ * @example
269
+ * // Mixed foreground and background
270
+ * Stylog.style('white', 'bgBlue').log('White text on blue background');
271
+ * Stylog.style('white', 'bgBlue').toANSI('White text on blue background');
272
+ * Stylog.style('white', 'bgBlue').toCSS('White text on blue background');
273
+ *
274
+ * @example
275
+ * // Building on existing styles
276
+ * const errorStyle = Stylog.style('red', 'bold');
277
+ * errorStyle.style('underline').log('Red bold underlined error');
278
+ * errorStyle.style('underline').toANSI('Red bold underlined error');
279
+ * errorStyle.style('underline').toCSS('Red bold underlined error');
280
+ */
281
+ style(...style) {
282
+ return this.#applyStyles(...style);
283
+ }
284
+ /**
285
+ * * Apply ANSI 16-color styling to the text.
286
+ *
287
+ * @param color - ANSI 16-color name (e.g., 'red', 'cyanBright', 'bgRed').
288
+ * @returns A new `StylogChain` instance with the `ANSI 16-color` style applied.
289
+ *
290
+ * @remarks
291
+ * - Only one argument (color) can be passed on a single call.
292
+ * - Color applied through `ansi16()` method is `truecolor` in form, to apply `truecolor` colors, use `style()` method.
293
+ *
294
+ * @example
295
+ * // Basic usage
296
+ * Stylog.ansi16('red').log('Error message');
297
+ *
298
+ * @example
299
+ * // Chaining with other styles
300
+ * Stylog.ansi16('redBright').bold.italic.log('Bright red bold italic');
301
+ * Stylog.ansi16('redBright').bold.italic.toANSI('Bright red bold italic');
302
+ * Stylog.ansi16('redBright').bold.italic.toCSS('Bright red bold italic');
303
+ *
304
+ * @example
305
+ * // Background colors
306
+ * Stylog.ansi16('bgRed').log('Red background');
307
+ * Stylog.ansi16('bgRed').toANSI('Red background');
308
+ * Stylog.ansi16('bgRed').toCSS('Red background');
309
+ */
310
+ ansi16(color) {
311
+ return this.#applyStyles(ANSI_16_COLORS[color], `css-${color}`);
312
+ }
313
+ /**
314
+ * * Returns styled tuple `[format, cssList]` for Browser.
315
+ *
316
+ * @remarks
317
+ * - This method is specifically designed for browser environments and returns a tuple containing the formatted string with `%c` placeholder and an array of CSS styles (`string[]`).
318
+ * - Use this when you need direct access to the CSS styling for custom browser output.
319
+ * - If you want to format with ANSI escape codes, consider using {@link https://toolbox.nazmul-nhb.dev/docs/classes/LogStyler#toansiinput-stringify toANSI} method.
320
+ *
321
+ * @param input - Input to style before printing in the shell.
322
+ * @param stringify - Whether to apply `JSON.stringify()` before styling. Defaults to `false`.
323
+ * @returns Tuple `[format, cssList]` where:
324
+ * - `format`: String with `%c` placeholder for CSS styling
325
+ * - `cssList`: Array of CSS style strings
326
+ *
327
+ * @example
328
+ * // Basic usage in browser
329
+ * const styler = new LogStyler(['red', 'bold']);
330
+ * const [format, cssList] = styler.toCSS('Error message');
331
+ * // format: "%cError message"
332
+ * // cssList: ["color: #FF0000", "font-weight: bold"]
333
+ *
334
+ * @example
335
+ * // Custom browser output handling
336
+ * const styled = new LogStyler(['blue', 'bgYellow', 'italic']);
337
+ * const [format, styles] = styled.toCSS('Warning', true);
338
+ *
339
+ * // Use with custom logging function
340
+ * function customLog(formatted: string, styles: string[]) {
341
+ * const styleString = styles.join('; ');
342
+ * console.log(formatted, styleString);
343
+ * }
344
+ * customLog(format, styles);
345
+ *
346
+ * @example
347
+ * // With object stringification
348
+ * const dataOutput = new LogStyler(['green']).toCSS({ id: 123 }, true);
349
+ * // format: "%c{\"id\":123}"
350
+ * // cssList: ["color: #008000"]
351
+ */
352
+ toCSS(input, stringify = false) {
353
+ const stringified = stringify === true ? JSON.stringify(input) : `${input}`;
354
+ const cssList = [];
355
+ for (const style of this.#styles) if (require_primitives.isString(style)) {
356
+ if (isTextStyle(style)) cssList.push(CSS_TEXT_STYLES[style]);
357
+ else if (isBGColor(style)) {
358
+ const color = require_css_colors.CSS_COLORS[_extractColorName(style)];
359
+ cssList.push(`background: ${color}`);
360
+ } else if (require_guards.isCSSColor(style)) {
361
+ const color = require_css_colors.CSS_COLORS[style];
362
+ cssList.push(`color: ${color}`);
363
+ } else if (this.#isValidHexOrRGB(style)) if (style.startsWith("bg-")) cssList.push(`background: ${style?.replace("bg-", "")}`);
364
+ else cssList.push(`color: ${style}`);
365
+ else if (_isCSS16Color(style)) {
366
+ const color = _css16ToHex(style);
367
+ const colorValue = style.startsWith("css-bg") ? `background: ${color}` : `color: ${color}`;
368
+ cssList.push(colorValue);
369
+ }
370
+ }
371
+ return [`%c${stringified}`, cssList];
372
+ }
373
+ /**
374
+ * * Returns the input as a styled string with ANSI escape codes.
375
+ *
376
+ * @remarks
377
+ * - This method returns ANSI-formatted strings suitable for environments that support ANSI escape codes (terminals, modern browser consoles, etc.).
378
+ * - For unsupported browsers, consider using the {@link https://toolbox.nazmul-nhb.dev/docs/classes/LogStyler#loginput-stringify log} method to print directly or {@link https://toolbox.nazmul-nhb.dev/docs/classes/LogStyler#tocssinput-stringify toCSS} to get styled tuple `[format, cssList]` for Browser.
379
+ *
380
+ * @param input - Input to style before printing in the shell.
381
+ * @param stringify - Whether to apply `JSON.stringify()` before styling. Defaults to `false`.
382
+ * @returns The styled string with ANSI escape codes.
383
+ *
384
+ * @example
385
+ * const styled = new LogStyler(['red', 'bold']);
386
+ * const errorMessage = styled.toANSI('Error occurred, using LogStyler');
387
+ * // Or with Stylog
388
+ * const errorMessage = Stylog.red.bold.toANSI('Error occurred, using Stylog');
389
+ * // Returns: "\x1b[31m\x1b[1mError occurred, using Stylog\xx1b[22m\x1b[39m"
390
+ *
391
+ * @example
392
+ * // Use in console (terminal or modern browser consoles)
393
+ * console.error(errorMessage);
394
+ * console.info(Stylog.red.bold.toANSI('I support ANSI!'));
395
+ */
396
+ toANSI(input, stringify = false) {
397
+ const stringified = stringify === true ? JSON.stringify(input) : `${input}`;
398
+ let openSeq = "", closeSeq = "";
399
+ let fgOpenSeq = "", bgOpenSeq = "";
400
+ const reopenSequences = /* @__PURE__ */ new Map();
401
+ for (const style of this.#styles) if (require_primitives.isString(style)) {
402
+ if (isTextStyle(style)) {
403
+ const [open, close] = ANSI_TEXT_STYLES[style];
404
+ openSeq += open;
405
+ closeSeq = close + closeSeq;
406
+ reopenSequences.set(close, (reopenSequences.get(close) ?? "") + open);
407
+ } else if (isBGColor(style)) {
408
+ const hex = require_css_colors.CSS_COLORS[_extractColorName(style)];
409
+ const [open, close] = hexToAnsi(hex, true);
410
+ openSeq += open;
411
+ closeSeq = close + closeSeq;
412
+ bgOpenSeq = open;
413
+ } else if (require_guards.isCSSColor(style)) {
414
+ const hex = require_css_colors.CSS_COLORS[style];
415
+ const [open, close] = hexToAnsi(hex, false);
416
+ openSeq += open;
417
+ closeSeq = close + closeSeq;
418
+ fgOpenSeq = open;
419
+ }
420
+ } else if (_isAnsiSequence(style)) {
421
+ openSeq += style[0];
422
+ closeSeq = style[1] + closeSeq;
423
+ if (style[1] === "\x1B[49m") bgOpenSeq = style[0];
424
+ else if (style[1] === "\x1B[39m") fgOpenSeq = style[0];
425
+ } else if (_isAnsi16ColorValue(style)) {
426
+ const [open, close] = style.map((s) => `\x1b[${s}m`);
427
+ openSeq += open;
428
+ closeSeq = close + closeSeq;
429
+ if (close === "\x1B[49m") bgOpenSeq = open;
430
+ else if (close === "\x1B[39m") fgOpenSeq = open;
431
+ }
432
+ if (!detectColorSupport()) return stringified;
433
+ else {
434
+ let nestedStr = stringified;
435
+ if (nestedStr.includes("\x1B[")) {
436
+ if (fgOpenSeq) nestedStr = nestedStr.replaceAll("\x1B[39m", `\x1b[39m${fgOpenSeq}`);
437
+ if (bgOpenSeq) nestedStr = nestedStr.replaceAll("\x1B[49m", `\x1b[49m${bgOpenSeq}`);
438
+ for (const [close, reopen] of reopenSequences) nestedStr = nestedStr.replaceAll(close, `${close}${reopen}`);
439
+ if (openSeq) nestedStr = nestedStr.replaceAll("\x1B[0m", `\x1b[0m${openSeq}`);
440
+ }
441
+ return openSeq.concat(nestedStr, closeSeq);
442
+ }
443
+ }
444
+ /**
445
+ * * Print styled input to the console.
446
+ *
447
+ * @param input Input to print to the shell/console.
448
+ * @param stringify Whether to apply `JSON.stringify()` before printing. Defaults to `false`.
449
+ */
450
+ log(input, stringify = false) {
451
+ if (require_specials.isBrowser()) {
452
+ const [fmt, cssList] = this.toCSS(input, stringify);
453
+ _logToConsole(fmt, cssList.join(";"));
454
+ } else _logToConsole(this.toANSI(input, stringify));
455
+ }
456
+ #isValidHexOrRGB(color) {
457
+ const pure = color?.replace("bg-", "");
458
+ return require_guards.isHex6(pure) || require_guards.isRGB(pure);
459
+ }
460
+ #sanitizeHex(code) {
461
+ return code?.trim()?.startsWith("#") ? code?.trim() : `#${code?.trim()}`;
462
+ }
463
+ #handleHex(code, isBg = false) {
464
+ const sanitized = this.#sanitizeHex(code);
465
+ if (!require_guards.isHex6(sanitized)) return this.#applyStyles();
466
+ const ansi = hexToAnsi(sanitized, isBg);
467
+ return this.#applyStyles(isBg ? `bg-${sanitized}` : sanitized, ansi);
468
+ }
469
+ /**
470
+ * * Apply a HEX color to the text foreground.
471
+ *
472
+ * @param code - HEX color string (e.g., `'#4682B4'` or `'4682B4'`).
473
+ * @returns A new `StylogChain` instance with the HEX color applied.
474
+ *
475
+ * @example
476
+ * // With hash prefix
477
+ * Stylog.hex('#4682B4').log('Steel blue text');
478
+ * Stylog.hex('#4682B4').toANSI('Steel blue text');
479
+ * Stylog.hex('#4682B4').toCSS('Steel blue text');
480
+ *
481
+ * @example
482
+ * // Without hash prefix
483
+ * Stylog.hex('4682B4').log('Steel blue text');
484
+ * Stylog.hex('4682B4').toANSI('Steel blue text');
485
+ * Stylog.hex('4682B4').toCSS('Steel blue text');
486
+ *
487
+ * @example
488
+ * // Chaining with other styles
489
+ * Stylog.hex('#FF0000').bold.log('Red bold text');
490
+ * Stylog.hex('#FF0000').bold.toANSI('Red bold text');
491
+ * Stylog.hex('#FF0000').bold.toCSS('Red bold text');
492
+ */
493
+ hex(code) {
494
+ return this.#handleHex(code, false);
495
+ }
496
+ /**
497
+ * * Apply a HEX color to the text background.
498
+ *
499
+ * @param code - HEX color string (e.g., `'#4682B4'` or `'4682B4'`).
500
+ * @returns A new StylogChain instance with the HEX background color applied.
501
+ *
502
+ * @example
503
+ * // With hash prefix
504
+ * Stylog.bgHex('#4682B4').log('Steel blue background');
505
+ * Stylog.bgHex('#4682B4').toANSI('Steel blue background');
506
+ * Stylog.bgHex('#4682B4').toCSS('Steel blue background');
507
+ *
508
+ * @example
509
+ * // Without hash prefix
510
+ * Stylog.bgHex('4682B4').log('Steel blue background');
511
+ * Stylog.bgHex('4682B4').toANSI('Steel blue background');
512
+ * Stylog.bgHex('4682B4').toCSS('Steel blue background');
513
+ *
514
+ * @example
515
+ * // Chaining with foreground color
516
+ * Stylog.white.bgHex('#000000').log('White text on black background');
517
+ * Stylog.white.bgHex('#000000').toANSI('White text on black background');
518
+ * Stylog.white.bgHex('#000000').toCSS('White text on black background');
519
+ */
520
+ bgHex(code) {
521
+ return this.#handleHex(code, true);
522
+ }
523
+ #extractColorValues(code) {
524
+ return ((code?.trim())?.match(/[\d.]+%?/g) || []).map(parseFloat);
525
+ }
526
+ #isValidRGB(...value) {
527
+ return value.every(require_guards._isValidRGBComponent);
528
+ }
529
+ #handleRGB(code, green, blue, isBg = false) {
530
+ if (require_primitives.isString(code)) {
531
+ const rgb = this.#extractColorValues(code);
532
+ if (this.#isValidRGB(...rgb)) return this.#applyStyles(rgbToAnsi(...rgb, isBg), isBg ? `bg-rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})` : `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`);
533
+ else return this.#applyStyles();
534
+ } else if (require_primitives.isNumber(code) && require_primitives.isNumber(green) && require_primitives.isNumber(blue)) if (this.#isValidRGB(code, green, blue)) return this.#applyStyles(rgbToAnsi(code, green, blue, isBg), isBg ? `bg-rgb(${code}, ${green}, ${blue})` : `rgb(${code}, ${green}, ${blue})`);
535
+ else return this.#applyStyles();
536
+ else return this.#applyStyles();
537
+ }
538
+ /** * Apply an RGB color to the text foreground using string or individual components. */
539
+ rgb(code, green, blue) {
540
+ return this.#handleRGB(code, green, blue, false);
541
+ }
542
+ /** * Apply an RGB color to the text background using string or individual components. */
543
+ bgRGB(code, green, blue) {
544
+ return this.#handleRGB(code, green, blue, true);
545
+ }
546
+ #isValidHSL(h, s, l) {
547
+ return require_guards._isValidHue(h) && require_guards._isValidPercentage(s) && require_guards._isValidPercentage(l);
548
+ }
549
+ #handleHSL(code, saturation, lightness, isBg = false) {
550
+ if (require_primitives.isString(code)) {
551
+ const hsl = this.#extractColorValues(code);
552
+ if (this.#isValidHSL(...hsl)) return this.#handleRGB(require_convert.convertHslToRgb(...hsl), void 0, void 0, isBg);
553
+ else return this.#applyStyles();
554
+ } else if (require_primitives.isNumber(code) && require_primitives.isNumber(saturation) && require_primitives.isNumber(lightness)) if (this.#isValidHSL(code, saturation, lightness)) return this.#handleRGB(require_convert.convertHslToRgb(code, saturation, lightness), void 0, void 0, isBg);
555
+ else return this.#applyStyles();
556
+ else return this.#applyStyles();
557
+ }
558
+ /** * Apply an HSL color to the text foreground using string or individual components. */
559
+ hsl(code, saturation, lightness) {
560
+ return this.#handleHSL(code, saturation, lightness, false);
561
+ }
562
+ /** * Apply an HSL color to the text background using string or individual components. */
563
+ bgHSL(code, saturation, lightness) {
564
+ return this.#handleHSL(code, saturation, lightness, true);
565
+ }
566
+ };
567
+ /**
568
+ * * Create a proxied instance of `LogStyler` that supports dynamic style chaining.
569
+ *
570
+ * @param styler Base `LogStyler` instance.
571
+ * @returns Proxied `LogStyler` instance with dynamic chaining support (`StylogChain`).
572
+ */
573
+ function createStylogProxy(styler) {
574
+ return new Proxy(styler, { get(target, prop) {
575
+ if (prop in target) {
576
+ const value = target[prop];
577
+ if (typeof value === "function") return value.bind(target);
578
+ else return value;
579
+ }
580
+ if (require_guards.isCSSColor(prop) || isBGColor(prop) || isTextStyle(prop)) return createStylogProxy(target.style(prop));
581
+ } });
582
+ }
583
+ /**
584
+ * * Styled console logger with chainable, type-safe color and text effects for both `Node.js` (`ANSI true-color`) and browsers (`CSS` via `%c`).
585
+ *
586
+ * @remarks
587
+ * - Chain any mix of foreground colors (e.g. `green`), background colors (e.g. `bgBlue`), and text styles (e.g. `bold`, `italic`, `underline`).
588
+ * - In browsers, styles are applied using `CSS`; in `Node.js`, `ANSI` escape codes are used.
589
+ * - When multiple styles of the same category are chained, the last one wins.
590
+ * - Use `.log(value, stringify?)` to print; set `stringify` to `true` to serialize with `JSON.stringify`.
591
+ * - If you need custom reusable style configurations, use {@link https://toolbox.nazmul-nhb.dev/docs/classes/LogStyler Stylog} class.
592
+ *
593
+ * @example
594
+ * // Simple color
595
+ * Stylog.green.log('Ready');
596
+ *
597
+ * @example
598
+ * // Foreground + background + effect, with JSON stringification
599
+ * Stylog.green.bgBlue.bold.log({ a: 121 }, true);
600
+ *
601
+ * @example
602
+ * // Reusable base chain
603
+ * const base = Stylog.underline;
604
+ * base.red.log('Error');
605
+ * base.error.log('Error');
606
+ * base.bgYellow.bold.log('Caution');
607
+ *
608
+ * @example
609
+ * // Works in the browser console too
610
+ * Stylog.cornflowerblue.italic.log('Hello from the browser');
611
+ */
612
+ const Stylog = createStylogProxy(new LogStyler());
613
+
614
+ //#endregion
615
+ exports.LogStyler = LogStyler;
616
+ exports.Stylog = Stylog;
617
+ exports.detectColorSupport = detectColorSupport;
618
+ exports.hexToAnsi = hexToAnsi;
619
+ exports.isBGColor = isBGColor;
620
+ exports.isTextStyle = isTextStyle;
621
+ exports.rgbToAnsi = rgbToAnsi;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Copyright 2026 - present Nazmul Hassan
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { _ as Hex } from "./Color-B3mgF9Dh.cjs";
18
+ import { a as AnsiSequence, n as Stylog, o as BGColor, t as LogStyler, u as TextStyle } from "./Stylog-Df7eq3-j.cjs";
19
+
20
+ //#region src/stylog/utils.d.ts
21
+ /**
22
+ * * Detects color support level of the current terminal/shell.
23
+ * @returns `0 = none`, `1 = basic (16 colors)`, `2 = 256 colors`, `3 = truecolor`
24
+ */
25
+ declare function detectColorSupport(): 0 | 1 | 2 | 3;
26
+ /**
27
+ * * Convert `RGB` color components into an `ANSI` escape code sequence.
28
+ *
29
+ * @param r Red component (`0-255`).
30
+ * @param g Green component (`0-255`).
31
+ * @param b Blue component (`0-255`).
32
+ * @param isBg Whether the color should be applied as background (`true`) or foreground (`false`). Defaults to `false`.
33
+ * @returns Tuple containing the opening and closing `ANSI` escape sequences.
34
+ */
35
+ declare function rgbToAnsi(r: number, g: number, b: number, isBg?: boolean): AnsiSequence;
36
+ /**
37
+ * * Convert a HEX color into an `ANSI` escape code sequence.
38
+ *
39
+ * @param hex HEX color string. e.g. `#000000`
40
+ * @param isBg Whether the color should be applied as background (`true`) or foreground (`false`). Defaults to `false`.
41
+ * @returns Tuple containing the opening and closing `ANSI` escape sequences.
42
+ */
43
+ declare function hexToAnsi(hex: Hex, isBg?: boolean): AnsiSequence;
44
+ /** * Check if a string represents `bgColor` with valid CSS color name. */
45
+ declare function isBGColor(value: string): value is BGColor;
46
+ /** * Check if a string represent `TextStyle` used in `LogStyler`. */
47
+ declare function isTextStyle(value: string): value is TextStyle;
48
+ //#endregion
49
+ export { LogStyler, Stylog, detectColorSupport, hexToAnsi, isBGColor, isTextStyle, rgbToAnsi };