@jacob-z/chalk 0.1.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.
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # custom-chalk
2
+
3
+ Browser console coloring utilities — a modular, type-safe rewrite of `@alita/chalk`.
4
+
5
+ ## Features
6
+
7
+ - `%c` CSS tuple formatters for browser DevTools console output
8
+ - 8 foreground colors: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`
9
+ - 8 background colors: `bgBlack`, `bgRed`, `bgGreen`, `bgYellow`, `bgBlue`, `bgMagenta`, `bgCyan`, `bgWhite`
10
+ - `bold()` text formatting
11
+ - `add()` for merging multiple formatted tuples
12
+ - Debug-gated logger methods: `log`, `wait`, `error`, `warn`, `ready`, `info`, `event`, `debug`
13
+ - `hello(title, version)` version banner
14
+ - `image(url)` console image
15
+ - `createChalk(options?)` factory for dependency injection and custom colors
16
+ - Zero runtime dependencies, fully tree-shakeable
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ pnpm add custom-chalk
22
+ ```
23
+
24
+ ## Basic Usage
25
+
26
+ Color formatters return `console.log`-ready tuples:
27
+
28
+ ```ts
29
+ import chalk from 'custom-chalk'
30
+
31
+ chalk.red('text')
32
+ // → ['%ctext', 'color:#FF0000']
33
+
34
+ chalk.bgRed('text')
35
+ // → ['%ctext', 'padding: 2px 4px; border-radius: 3px; color: #fff; font-weight: bold; background:#FF0000;']
36
+
37
+ chalk.bold('text')
38
+ // → ['%ctext', 'font-weight: bold;']
39
+
40
+ chalk.add(chalk.red('a'), chalk.blue('b'))
41
+ // → [' %ca %cb', 'color:#FF0000', 'color:#0000FF']
42
+ ```
43
+
44
+ Use with `console.log` spread:
45
+
46
+ ```ts
47
+ console.log(...chalk.red('colored text'))
48
+ console.log(...chalk.add(chalk.red('error:'), chalk.bold(' not found')))
49
+ ```
50
+
51
+ ## Debug Logging
52
+
53
+ Logger methods only print when debugging is enabled. By default they read `globalThis.alitadebug`:
54
+
55
+ ```ts
56
+ globalThis.alitadebug = true
57
+
58
+ chalk.ready('server started') // prints [Ready] in green
59
+ chalk.error('failed') // prints [Error] in red
60
+ ```
61
+
62
+ For tests or controlled environments, use the factory:
63
+
64
+ ```ts
65
+ import { createChalk } from 'custom-chalk'
66
+
67
+ const chalk = createChalk({ console, isDebug: () => true })
68
+ chalk.info('loaded')
69
+ ```
70
+
71
+ ## Logger Methods
72
+
73
+ | Method | Label | Color | Console Method |
74
+ | ------- | -------- | ------- | --------------- |
75
+ | `log` | `[Log]` | black | `console.log` |
76
+ | `wait` | `[Wait]` | cyan | `console.log` |
77
+ | `error` | `[Error]`| red | `console.error` |
78
+ | `warn` | `[Warn]` | yellow | `console.warn` |
79
+ | `ready` | `[Ready]`| green | `console.log` |
80
+ | `info` | `[Info]` | blue | `console.info` |
81
+ | `event` | `[Event]`| magenta | `console.log` |
82
+ | `debug` | `[Debug]`| gray | `console.debug` |
83
+
84
+ If a console method is unavailable, the logger falls back to `console.log`.
85
+
86
+ ## Custom Colors
87
+
88
+ ```ts
89
+ import { createChalk } from 'custom-chalk'
90
+
91
+ const chalk = createChalk({
92
+ colors: { brand: '#123456' },
93
+ })
94
+
95
+ chalk.color('brand', 'Brand text') // → ['%cBrand text', 'color:#123456']
96
+ chalk.bgColor('brand', 'Brand block') // → background with custom color
97
+ ```
98
+
99
+ ## Custom Log Levels
100
+
101
+ ```ts
102
+ const chalk = createChalk({
103
+ isDebug: true,
104
+ colors: { trace: '#123456' },
105
+ logLevels: [
106
+ { name: 'trace', label: 'Trace', color: 'trace', method: 'debug' },
107
+ ],
108
+ })
109
+
110
+ chalk.trace('details') // → [Trace] in custom color via console.debug
111
+ ```
112
+
113
+ ## Banner & Image
114
+
115
+ ```ts
116
+ chalk.hello('MyApp', '1.0.0') // styled title + version banner
117
+ chalk.image('https://example.com/logo.png') // console CSS background image
118
+ ```
119
+
120
+ ## Architecture
121
+
122
+ ```
123
+ src/
124
+ types.ts → All public & internal types
125
+ colors.ts → Color map, CSS generation (pure functions)
126
+ format.ts → %c format helpers, add(), bold()
127
+ logger.ts → Debug-gated logger factory
128
+ banner.ts → hello(), image()
129
+ create.ts → createChalk() factory
130
+ index.ts → Default instance + re-exports
131
+ ```
132
+
133
+ Design principles vs the original `@alita/chalk`:
134
+
135
+ - **No `window` dependency** — uses `globalThis` with fallback
136
+ - **No global cache** — no `window.chalk` mutation
137
+ - **No module-level side effects** — factory pattern, pure functions
138
+ - **No `any` / `@ts-ignore`** — strict TypeScript throughout
139
+ - **Modular & extensible** — custom colors, custom log levels, injected console
140
+
141
+ ## License
142
+
143
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,220 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ //#region src/colors.ts
4
+ const DEFAULT_COLORS = {
5
+ black: "#000000",
6
+ red: "#FF0000",
7
+ green: "#008000",
8
+ yellow: "#FFFF00",
9
+ blue: "#0000FF",
10
+ magenta: "#FF00FF",
11
+ cyan: "#00FFFF",
12
+ white: "#FFFFFF",
13
+ gray: "#808080"
14
+ };
15
+ function createColorMap(customColors = {}) {
16
+ return {
17
+ ...DEFAULT_COLORS,
18
+ ...customColors
19
+ };
20
+ }
21
+ function resolveColor(colors, name) {
22
+ const color$2 = colors[name];
23
+ if (color$2 === void 0) throw new Error(`Unknown chalk color: ${name}`);
24
+ return color$2;
25
+ }
26
+ function getForegroundStyle(colors, name) {
27
+ return `color:${resolveColor(colors, name)}`;
28
+ }
29
+ function getBackgroundStyle(colors, name) {
30
+ return `padding: 2px 4px; border-radius: 3px; color: ${name === "white" ? "#000" : "#fff"}; font-weight: bold; background:${resolveColor(colors, name)};`;
31
+ }
32
+
33
+ //#endregion
34
+ //#region src/banner.ts
35
+ function createBannerMethods(consoleLike, isDebug) {
36
+ return {
37
+ hello(title, version) {
38
+ if (!isDebug()) return;
39
+ consoleLike.log(`%c ${title} %c V${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;", "padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;");
40
+ },
41
+ image(url) {
42
+ if (!url) return;
43
+ if (!isDebug()) return;
44
+ consoleLike.log("%c ", `font-size: 1px; padding: 100px 100px; background: url(${url}) no-repeat center / contain; color: transparent;`);
45
+ }
46
+ };
47
+ }
48
+
49
+ //#endregion
50
+ //#region src/format.ts
51
+ function formatText(text, style) {
52
+ return [`%c${text}`, style];
53
+ }
54
+ function color$1(colors, name, text) {
55
+ return formatText(text, getForegroundStyle(colors, name));
56
+ }
57
+ function bgColor$1(colors, name, text) {
58
+ return formatText(text, getBackgroundStyle(colors, name));
59
+ }
60
+ function bold(text) {
61
+ return formatText(text, "font-weight: bold;");
62
+ }
63
+ function add(...items) {
64
+ if (items.length === 0) return ["%c", ""];
65
+ return [items.map((item) => ` ${item[0]}`).join(""), ...items.flatMap(([, ...itemStyles]) => itemStyles)];
66
+ }
67
+
68
+ //#endregion
69
+ //#region src/logger.ts
70
+ const DEFAULT_LOG_LEVELS = [
71
+ {
72
+ name: "log",
73
+ label: "Log",
74
+ color: "black",
75
+ method: "log"
76
+ },
77
+ {
78
+ name: "wait",
79
+ label: "Wait",
80
+ color: "cyan",
81
+ method: "log"
82
+ },
83
+ {
84
+ name: "error",
85
+ label: "Error",
86
+ color: "red",
87
+ method: "error"
88
+ },
89
+ {
90
+ name: "warn",
91
+ label: "Warn",
92
+ color: "yellow",
93
+ method: "warn"
94
+ },
95
+ {
96
+ name: "ready",
97
+ label: "Ready",
98
+ color: "green",
99
+ method: "log"
100
+ },
101
+ {
102
+ name: "info",
103
+ label: "Info",
104
+ color: "blue",
105
+ method: "info"
106
+ },
107
+ {
108
+ name: "event",
109
+ label: "Event",
110
+ color: "magenta",
111
+ method: "log"
112
+ },
113
+ {
114
+ name: "debug",
115
+ label: "Debug",
116
+ color: "gray",
117
+ method: "debug"
118
+ }
119
+ ];
120
+ function getConsoleMethod(consoleLike, method) {
121
+ return consoleLike[method] ?? consoleLike.log;
122
+ }
123
+ function createLogMethod(consoleLike, colors, isDebug, level) {
124
+ return (message, ...args) => {
125
+ if (!isDebug()) return;
126
+ const method = getConsoleMethod(consoleLike, level.method);
127
+ const labelStyle = `${getForegroundStyle(colors, level.color)};font-weight: bold;`;
128
+ const messageStyle = getForegroundStyle(colors, level.color);
129
+ method(`%c[${level.label}]%c ${message}`, labelStyle, messageStyle, ...args);
130
+ };
131
+ }
132
+ function createLoggerMethods(options) {
133
+ const levels = options.logLevels ?? DEFAULT_LOG_LEVELS;
134
+ return Object.fromEntries(levels.map((level) => [level.name, createLogMethod(options.console, options.colors, options.isDebug, level)]));
135
+ }
136
+
137
+ //#endregion
138
+ //#region src/create.ts
139
+ const noopConsole = { log: () => {} };
140
+ function readGlobalDebugFlag() {
141
+ return Object.prototype.hasOwnProperty.call(globalThis, "alitadebug") && Boolean(globalThis.alitadebug);
142
+ }
143
+ function resolveConsole(consoleLike) {
144
+ return consoleLike ?? globalThis.console ?? noopConsole;
145
+ }
146
+ function resolveDebugPredicate(isDebug) {
147
+ if (typeof isDebug === "function") return isDebug;
148
+ if (typeof isDebug === "boolean") return () => isDebug;
149
+ return readGlobalDebugFlag;
150
+ }
151
+ function createChalk(options = {}) {
152
+ const consoleLike = resolveConsole(options.console);
153
+ const colors = createColorMap(options.colors);
154
+ const isDebug = resolveDebugPredicate(options.isDebug);
155
+ const banner = createBannerMethods(consoleLike, isDebug);
156
+ const loggers = createLoggerMethods({
157
+ console: consoleLike,
158
+ colors,
159
+ isDebug,
160
+ logLevels: options.logLevels
161
+ });
162
+ return {
163
+ add,
164
+ bold,
165
+ ...banner,
166
+ black: (text) => color$1(colors, "black", text),
167
+ red: (text) => color$1(colors, "red", text),
168
+ green: (text) => color$1(colors, "green", text),
169
+ yellow: (text) => color$1(colors, "yellow", text),
170
+ blue: (text) => color$1(colors, "blue", text),
171
+ magenta: (text) => color$1(colors, "magenta", text),
172
+ cyan: (text) => color$1(colors, "cyan", text),
173
+ white: (text) => color$1(colors, "white", text),
174
+ bgBlack: (text) => bgColor$1(colors, "black", text),
175
+ bgRed: (text) => bgColor$1(colors, "red", text),
176
+ bgGreen: (text) => bgColor$1(colors, "green", text),
177
+ bgYellow: (text) => bgColor$1(colors, "yellow", text),
178
+ bgBlue: (text) => bgColor$1(colors, "blue", text),
179
+ bgMagenta: (text) => bgColor$1(colors, "magenta", text),
180
+ bgCyan: (text) => bgColor$1(colors, "cyan", text),
181
+ bgWhite: (text) => bgColor$1(colors, "white", text),
182
+ color: (name, text) => color$1(colors, name, text),
183
+ bgColor: (name, text) => bgColor$1(colors, name, text),
184
+ log: loggers.log,
185
+ wait: loggers.wait,
186
+ error: loggers.error,
187
+ warn: loggers.warn,
188
+ ready: loggers.ready,
189
+ info: loggers.info,
190
+ event: loggers.event,
191
+ debug: loggers.debug
192
+ };
193
+ }
194
+
195
+ //#endregion
196
+ //#region src/index.ts
197
+ const defaultColors = createColorMap();
198
+ const chalk = createChalk();
199
+ function color(name, text) {
200
+ return color$1(defaultColors, name, text);
201
+ }
202
+ function bgColor(name, text) {
203
+ return bgColor$1(defaultColors, name, text);
204
+ }
205
+ var src_default = chalk;
206
+
207
+ //#endregion
208
+ exports.DEFAULT_COLORS = DEFAULT_COLORS;
209
+ exports.add = add;
210
+ exports.bgColor = bgColor;
211
+ exports.bold = bold;
212
+ exports.chalk = chalk;
213
+ exports.color = color;
214
+ exports.createChalk = createChalk;
215
+ exports.createColorMap = createColorMap;
216
+ exports.default = src_default;
217
+ exports.getBackgroundStyle = getBackgroundStyle;
218
+ exports.getForegroundStyle = getForegroundStyle;
219
+ exports.resolveColor = resolveColor;
220
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["DEFAULT_COLORS: ColorMap","color","color","bgColor","noopConsole: ConsoleLike","color","bgColor","colorWithMap","bgColorWithMap"],"sources":["../src/colors.ts","../src/banner.ts","../src/format.ts","../src/logger.ts","../src/create.ts","../src/index.ts"],"sourcesContent":["import type { ColorMap, CustomColorMap } from './types'\n\nexport const DEFAULT_COLORS: ColorMap = {\n black: '#000000',\n red: '#FF0000',\n green: '#008000',\n yellow: '#FFFF00',\n blue: '#0000FF',\n magenta: '#FF00FF',\n cyan: '#00FFFF',\n white: '#FFFFFF',\n gray: '#808080',\n}\n\nexport type ResolvedColorMap = Readonly<ColorMap & CustomColorMap>\n\nexport function createColorMap(customColors: CustomColorMap = {} as CustomColorMap): ResolvedColorMap {\n return {\n ...DEFAULT_COLORS,\n ...customColors,\n }\n}\n\nexport function resolveColor(colors: Readonly<Record<string, string>>, name: string): string {\n const color = colors[name]\n if (color === undefined)\n throw new Error(`Unknown chalk color: ${name}`)\n return color\n}\n\nexport function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n return `color:${resolveColor(colors, name)}`\n}\n\nexport function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const textColor = name === 'white' ? '#000' : '#fff'\n return `padding: 2px 4px; border-radius: 3px; color: ${textColor}; font-weight: bold; background:${resolveColor(colors, name)};`\n}\n","import type { ConsoleLike, DebugPredicate } from './types'\n\nexport interface BannerMethods {\n hello: (title: string, version: string) => void\n image: (url: string) => void\n}\n\nexport function createBannerMethods(consoleLike: ConsoleLike, isDebug: DebugPredicate): BannerMethods {\n return {\n hello(title: string, version: string): void {\n if (!isDebug())\n return\n consoleLike.log(\n `%c ${title} %c V${version} `,\n 'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;',\n 'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;',\n )\n },\n image(url: string): void {\n if (!url)\n return\n if (!isDebug())\n return\n consoleLike.log(\n '%c ',\n `font-size: 1px; padding: 100px 100px; background: url(${url}) no-repeat center / contain; color: transparent;`,\n )\n },\n }\n}\n","import type { FormattedText } from './types'\nimport { getBackgroundStyle, getForegroundStyle } from './colors'\n\nexport function formatText(text: string, style: string): FormattedText {\n return [`%c${text}`, style]\n}\n\nexport function color(colors: Readonly<Record<string, string>>, name: string, text: string): FormattedText {\n return formatText(text, getForegroundStyle(colors, name))\n}\n\nexport function bgColor(colors: Readonly<Record<string, string>>, name: string, text: string): FormattedText {\n return formatText(text, getBackgroundStyle(colors, name))\n}\n\nexport function bold(text: string): FormattedText {\n return formatText(text, 'font-weight: bold;')\n}\n\nexport function add(...items: readonly FormattedText[]): FormattedText {\n if (items.length === 0)\n return ['%c', '']\n const template = items.map(item => ` ${item[0]}`).join('')\n const styles = items.flatMap(([, ...itemStyles]) => itemStyles)\n return [template, ...styles] as FormattedText\n}\n","import type { ConsoleLike, ConsoleMethodName, DebugPredicate, LogLevelDefinition, LogMethod } from './types'\nimport { getForegroundStyle } from './colors'\n\nexport const DEFAULT_LOG_LEVELS = [\n { name: 'log', label: 'Log', color: 'black', method: 'log' },\n { name: 'wait', label: 'Wait', color: 'cyan', method: 'log' },\n { name: 'error', label: 'Error', color: 'red', method: 'error' },\n { name: 'warn', label: 'Warn', color: 'yellow', method: 'warn' },\n { name: 'ready', label: 'Ready', color: 'green', method: 'log' },\n { name: 'info', label: 'Info', color: 'blue', method: 'info' },\n { name: 'event', label: 'Event', color: 'magenta', method: 'log' },\n { name: 'debug', label: 'Debug', color: 'gray', method: 'debug' },\n] satisfies readonly LogLevelDefinition[]\n\nexport interface CreateLoggerMethodsOptions {\n console: ConsoleLike\n colors: Readonly<Record<string, string>>\n isDebug: DebugPredicate\n logLevels?: readonly LogLevelDefinition[]\n}\n\nfunction getConsoleMethod(consoleLike: ConsoleLike, method: ConsoleMethodName): (...data: unknown[]) => void {\n return consoleLike[method] ?? consoleLike.log\n}\n\nfunction createLogMethod(\n consoleLike: ConsoleLike,\n colors: Readonly<Record<string, string>>,\n isDebug: DebugPredicate,\n level: LogLevelDefinition,\n): LogMethod {\n return (message: string, ...args: unknown[]): void => {\n if (!isDebug())\n return\n const method = getConsoleMethod(consoleLike, level.method)\n const labelStyle = `${getForegroundStyle(colors, level.color)};font-weight: bold;`\n const messageStyle = getForegroundStyle(colors, level.color)\n method(`%c[${level.label}]%c ${message}`, labelStyle, messageStyle, ...args)\n }\n}\n\nexport function createLoggerMethods(options: CreateLoggerMethodsOptions): Record<string, LogMethod> {\n const levels = options.logLevels ?? DEFAULT_LOG_LEVELS\n return Object.fromEntries(\n levels.map(level => [\n level.name,\n createLogMethod(options.console, options.colors, options.isDebug, level),\n ]),\n )\n}\n","import type { ChalkInstance, ConsoleLike, CreateChalkOptions, DebugPredicate } from './types'\nimport { createBannerMethods } from './banner'\nimport { createColorMap } from './colors'\nimport { add, bgColor, bold, color } from './format'\nimport { createLoggerMethods } from './logger'\n\nconst noopConsole: ConsoleLike = {\n log: () => {},\n}\n\nfunction readGlobalDebugFlag(): boolean {\n return Object.prototype.hasOwnProperty.call(globalThis, 'alitadebug')\n && Boolean(globalThis.alitadebug)\n}\n\nfunction resolveConsole(consoleLike: ConsoleLike | undefined): ConsoleLike {\n return consoleLike ?? globalThis.console ?? noopConsole\n}\n\nfunction resolveDebugPredicate(isDebug: CreateChalkOptions['isDebug']): DebugPredicate {\n if (typeof isDebug === 'function')\n return isDebug\n if (typeof isDebug === 'boolean')\n return () => isDebug\n return readGlobalDebugFlag\n}\n\nexport function createChalk(options: CreateChalkOptions = {}): ChalkInstance {\n const consoleLike = resolveConsole(options.console)\n const colors = createColorMap(options.colors)\n const isDebug = resolveDebugPredicate(options.isDebug)\n const banner = createBannerMethods(consoleLike, isDebug)\n const loggers = createLoggerMethods({\n console: consoleLike,\n colors,\n isDebug,\n logLevels: options.logLevels,\n })\n\n return {\n add,\n bold,\n ...banner,\n black: text => color(colors, 'black', text),\n red: text => color(colors, 'red', text),\n green: text => color(colors, 'green', text),\n yellow: text => color(colors, 'yellow', text),\n blue: text => color(colors, 'blue', text),\n magenta: text => color(colors, 'magenta', text),\n cyan: text => color(colors, 'cyan', text),\n white: text => color(colors, 'white', text),\n bgBlack: text => bgColor(colors, 'black', text),\n bgRed: text => bgColor(colors, 'red', text),\n bgGreen: text => bgColor(colors, 'green', text),\n bgYellow: text => bgColor(colors, 'yellow', text),\n bgBlue: text => bgColor(colors, 'blue', text),\n bgMagenta: text => bgColor(colors, 'magenta', text),\n bgCyan: text => bgColor(colors, 'cyan', text),\n bgWhite: text => bgColor(colors, 'white', text),\n color: (name, text) => color(colors, name, text),\n bgColor: (name, text) => bgColor(colors, name, text),\n log: loggers.log,\n wait: loggers.wait,\n error: loggers.error,\n warn: loggers.warn,\n ready: loggers.ready,\n info: loggers.info,\n event: loggers.event,\n debug: loggers.debug,\n }\n}\n","import { createColorMap } from './colors'\nimport { createChalk } from './create'\nimport { add, bgColor as bgColorWithMap, bold, color as colorWithMap } from './format'\n\nconst defaultColors = createColorMap()\n\nexport const chalk = createChalk()\n\nexport { add, bold, createChalk }\nexport { createColorMap, DEFAULT_COLORS, getBackgroundStyle, getForegroundStyle, resolveColor } from './colors'\nexport type {\n ChalkInstance,\n ColorMap,\n ColorName,\n ConsoleLike,\n CreateChalkOptions,\n CustomColorMap,\n FormattedText,\n LogLevelDefinition,\n LogMethod,\n PublicColorName,\n TextFormatter,\n} from './types'\n\nexport function color(name: string, text: string) {\n return colorWithMap(defaultColors, name, text)\n}\n\nexport function bgColor(name: string, text: string) {\n return bgColorWithMap(defaultColors, name, text)\n}\n\nexport default chalk\n"],"mappings":";;;AAEA,MAAaA,iBAA2B;CACtC,OAAO;CACP,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;CACP,MAAM;CACP;AAID,SAAgB,eAAe,eAA+B,EAAE,EAAsC;AACpG,QAAO;EACL,GAAG;EACH,GAAG;EACJ;;AAGH,SAAgB,aAAa,QAA0C,MAAsB;CAC3F,MAAMC,UAAQ,OAAO;AACrB,KAAIA,YAAU,OACZ,OAAM,IAAI,MAAM,wBAAwB,OAAO;AACjD,QAAOA;;AAGT,SAAgB,mBAAmB,QAA0C,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ACd,OAAO,QAAQ;EACf,OAAO,QAAQ;EAChB;;;;;ACjEH,MAAM,gBAAgB,gBAAgB;AAEtC,MAAa,QAAQ,aAAa;AAkBlC,SAAgB,MAAM,MAAc,MAAc;AAChD,QAAOC,QAAa,eAAe,MAAM,KAAK;;AAGhD,SAAgB,QAAQ,MAAc,MAAc;AAClD,QAAOC,UAAe,eAAe,MAAM,KAAK;;AAGlD,kBAAe"}
@@ -0,0 +1,84 @@
1
+ //#region src/types.d.ts
2
+ type ConsoleMethodName = 'log' | 'info' | 'warn' | 'error' | 'debug';
3
+ interface ConsoleLike {
4
+ log: (...data: unknown[]) => void;
5
+ info?: (...data: unknown[]) => void;
6
+ warn?: (...data: unknown[]) => void;
7
+ error?: (...data: unknown[]) => void;
8
+ debug?: (...data: unknown[]) => void;
9
+ }
10
+ type FormattedText = [template: `%c${string}`, ...styles: string[]];
11
+ type ColorName = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray';
12
+ type PublicColorName = Exclude<ColorName, 'gray'>;
13
+ type ColorMap = Readonly<Record<ColorName, string>>;
14
+ type CustomColorMap = Readonly<Record<string, string>>;
15
+ type DebugPredicate = () => boolean;
16
+ interface LogLevelDefinition {
17
+ name: string;
18
+ label: string;
19
+ color: ColorName | string;
20
+ method: ConsoleMethodName;
21
+ }
22
+ interface CreateChalkOptions {
23
+ console?: ConsoleLike;
24
+ isDebug?: boolean | DebugPredicate;
25
+ colors?: CustomColorMap;
26
+ logLevels?: readonly LogLevelDefinition[];
27
+ }
28
+ type TextFormatter = (text: string) => FormattedText;
29
+ type LogMethod = (message: string, ...args: unknown[]) => void;
30
+ interface ChalkInstance {
31
+ add: (...items: readonly FormattedText[]) => FormattedText;
32
+ bold: TextFormatter;
33
+ hello: (title: string, version: string) => void;
34
+ image: (url: string) => void;
35
+ log: LogMethod;
36
+ wait: LogMethod;
37
+ error: LogMethod;
38
+ warn: LogMethod;
39
+ ready: LogMethod;
40
+ info: LogMethod;
41
+ event: LogMethod;
42
+ debug: LogMethod;
43
+ black: TextFormatter;
44
+ red: TextFormatter;
45
+ green: TextFormatter;
46
+ yellow: TextFormatter;
47
+ blue: TextFormatter;
48
+ magenta: TextFormatter;
49
+ cyan: TextFormatter;
50
+ white: TextFormatter;
51
+ bgBlack: TextFormatter;
52
+ bgRed: TextFormatter;
53
+ bgGreen: TextFormatter;
54
+ bgYellow: TextFormatter;
55
+ bgBlue: TextFormatter;
56
+ bgMagenta: TextFormatter;
57
+ bgCyan: TextFormatter;
58
+ bgWhite: TextFormatter;
59
+ color: (name: string, text: string) => FormattedText;
60
+ bgColor: (name: string, text: string) => FormattedText;
61
+ }
62
+ //#endregion
63
+ //#region src/create.d.ts
64
+ declare function createChalk(options?: CreateChalkOptions): ChalkInstance;
65
+ //#endregion
66
+ //#region src/format.d.ts
67
+ declare function bold(text: string): FormattedText;
68
+ declare function add(...items: readonly FormattedText[]): FormattedText;
69
+ //#endregion
70
+ //#region src/colors.d.ts
71
+ declare const DEFAULT_COLORS: ColorMap;
72
+ type ResolvedColorMap = Readonly<ColorMap & CustomColorMap>;
73
+ declare function createColorMap(customColors?: CustomColorMap): ResolvedColorMap;
74
+ declare function resolveColor(colors: Readonly<Record<string, string>>, name: string): string;
75
+ declare function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string;
76
+ declare function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string;
77
+ //#endregion
78
+ //#region src/index.d.ts
79
+ declare const chalk: ChalkInstance;
80
+ declare function color(name: string, text: string): FormattedText;
81
+ declare function bgColor(name: string, text: string): FormattedText;
82
+ //#endregion
83
+ export { type ChalkInstance, type ColorMap, type ColorName, type ConsoleLike, type CreateChalkOptions, type CustomColorMap, DEFAULT_COLORS, type FormattedText, type LogLevelDefinition, type LogMethod, type PublicColorName, type TextFormatter, add, bgColor, bold, chalk, chalk as default, color, createChalk, createColorMap, getBackgroundStyle, getForegroundStyle, resolveColor };
84
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,84 @@
1
+ //#region src/types.d.ts
2
+ type ConsoleMethodName = 'log' | 'info' | 'warn' | 'error' | 'debug';
3
+ interface ConsoleLike {
4
+ log: (...data: unknown[]) => void;
5
+ info?: (...data: unknown[]) => void;
6
+ warn?: (...data: unknown[]) => void;
7
+ error?: (...data: unknown[]) => void;
8
+ debug?: (...data: unknown[]) => void;
9
+ }
10
+ type FormattedText = [template: `%c${string}`, ...styles: string[]];
11
+ type ColorName = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray';
12
+ type PublicColorName = Exclude<ColorName, 'gray'>;
13
+ type ColorMap = Readonly<Record<ColorName, string>>;
14
+ type CustomColorMap = Readonly<Record<string, string>>;
15
+ type DebugPredicate = () => boolean;
16
+ interface LogLevelDefinition {
17
+ name: string;
18
+ label: string;
19
+ color: ColorName | string;
20
+ method: ConsoleMethodName;
21
+ }
22
+ interface CreateChalkOptions {
23
+ console?: ConsoleLike;
24
+ isDebug?: boolean | DebugPredicate;
25
+ colors?: CustomColorMap;
26
+ logLevels?: readonly LogLevelDefinition[];
27
+ }
28
+ type TextFormatter = (text: string) => FormattedText;
29
+ type LogMethod = (message: string, ...args: unknown[]) => void;
30
+ interface ChalkInstance {
31
+ add: (...items: readonly FormattedText[]) => FormattedText;
32
+ bold: TextFormatter;
33
+ hello: (title: string, version: string) => void;
34
+ image: (url: string) => void;
35
+ log: LogMethod;
36
+ wait: LogMethod;
37
+ error: LogMethod;
38
+ warn: LogMethod;
39
+ ready: LogMethod;
40
+ info: LogMethod;
41
+ event: LogMethod;
42
+ debug: LogMethod;
43
+ black: TextFormatter;
44
+ red: TextFormatter;
45
+ green: TextFormatter;
46
+ yellow: TextFormatter;
47
+ blue: TextFormatter;
48
+ magenta: TextFormatter;
49
+ cyan: TextFormatter;
50
+ white: TextFormatter;
51
+ bgBlack: TextFormatter;
52
+ bgRed: TextFormatter;
53
+ bgGreen: TextFormatter;
54
+ bgYellow: TextFormatter;
55
+ bgBlue: TextFormatter;
56
+ bgMagenta: TextFormatter;
57
+ bgCyan: TextFormatter;
58
+ bgWhite: TextFormatter;
59
+ color: (name: string, text: string) => FormattedText;
60
+ bgColor: (name: string, text: string) => FormattedText;
61
+ }
62
+ //#endregion
63
+ //#region src/create.d.ts
64
+ declare function createChalk(options?: CreateChalkOptions): ChalkInstance;
65
+ //#endregion
66
+ //#region src/format.d.ts
67
+ declare function bold(text: string): FormattedText;
68
+ declare function add(...items: readonly FormattedText[]): FormattedText;
69
+ //#endregion
70
+ //#region src/colors.d.ts
71
+ declare const DEFAULT_COLORS: ColorMap;
72
+ type ResolvedColorMap = Readonly<ColorMap & CustomColorMap>;
73
+ declare function createColorMap(customColors?: CustomColorMap): ResolvedColorMap;
74
+ declare function resolveColor(colors: Readonly<Record<string, string>>, name: string): string;
75
+ declare function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string;
76
+ declare function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string;
77
+ //#endregion
78
+ //#region src/index.d.ts
79
+ declare const chalk: ChalkInstance;
80
+ declare function color(name: string, text: string): FormattedText;
81
+ declare function bgColor(name: string, text: string): FormattedText;
82
+ //#endregion
83
+ export { type ChalkInstance, type ColorMap, type ColorName, type ConsoleLike, type CreateChalkOptions, type CustomColorMap, DEFAULT_COLORS, type FormattedText, type LogLevelDefinition, type LogMethod, type PublicColorName, type TextFormatter, add, bgColor, bold, chalk, chalk as default, color, createChalk, createColorMap, getBackgroundStyle, getForegroundStyle, resolveColor };
84
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,207 @@
1
+ //#region src/colors.ts
2
+ const DEFAULT_COLORS = {
3
+ black: "#000000",
4
+ red: "#FF0000",
5
+ green: "#008000",
6
+ yellow: "#FFFF00",
7
+ blue: "#0000FF",
8
+ magenta: "#FF00FF",
9
+ cyan: "#00FFFF",
10
+ white: "#FFFFFF",
11
+ gray: "#808080"
12
+ };
13
+ function createColorMap(customColors = {}) {
14
+ return {
15
+ ...DEFAULT_COLORS,
16
+ ...customColors
17
+ };
18
+ }
19
+ function resolveColor(colors, name) {
20
+ const color$2 = colors[name];
21
+ if (color$2 === void 0) throw new Error(`Unknown chalk color: ${name}`);
22
+ return color$2;
23
+ }
24
+ function getForegroundStyle(colors, name) {
25
+ return `color:${resolveColor(colors, name)}`;
26
+ }
27
+ function getBackgroundStyle(colors, name) {
28
+ return `padding: 2px 4px; border-radius: 3px; color: ${name === "white" ? "#000" : "#fff"}; font-weight: bold; background:${resolveColor(colors, name)};`;
29
+ }
30
+
31
+ //#endregion
32
+ //#region src/banner.ts
33
+ function createBannerMethods(consoleLike, isDebug) {
34
+ return {
35
+ hello(title, version) {
36
+ if (!isDebug()) return;
37
+ consoleLike.log(`%c ${title} %c V${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;", "padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;");
38
+ },
39
+ image(url) {
40
+ if (!url) return;
41
+ if (!isDebug()) return;
42
+ consoleLike.log("%c ", `font-size: 1px; padding: 100px 100px; background: url(${url}) no-repeat center / contain; color: transparent;`);
43
+ }
44
+ };
45
+ }
46
+
47
+ //#endregion
48
+ //#region src/format.ts
49
+ function formatText(text, style) {
50
+ return [`%c${text}`, style];
51
+ }
52
+ function color$1(colors, name, text) {
53
+ return formatText(text, getForegroundStyle(colors, name));
54
+ }
55
+ function bgColor$1(colors, name, text) {
56
+ return formatText(text, getBackgroundStyle(colors, name));
57
+ }
58
+ function bold(text) {
59
+ return formatText(text, "font-weight: bold;");
60
+ }
61
+ function add(...items) {
62
+ if (items.length === 0) return ["%c", ""];
63
+ return [items.map((item) => ` ${item[0]}`).join(""), ...items.flatMap(([, ...itemStyles]) => itemStyles)];
64
+ }
65
+
66
+ //#endregion
67
+ //#region src/logger.ts
68
+ const DEFAULT_LOG_LEVELS = [
69
+ {
70
+ name: "log",
71
+ label: "Log",
72
+ color: "black",
73
+ method: "log"
74
+ },
75
+ {
76
+ name: "wait",
77
+ label: "Wait",
78
+ color: "cyan",
79
+ method: "log"
80
+ },
81
+ {
82
+ name: "error",
83
+ label: "Error",
84
+ color: "red",
85
+ method: "error"
86
+ },
87
+ {
88
+ name: "warn",
89
+ label: "Warn",
90
+ color: "yellow",
91
+ method: "warn"
92
+ },
93
+ {
94
+ name: "ready",
95
+ label: "Ready",
96
+ color: "green",
97
+ method: "log"
98
+ },
99
+ {
100
+ name: "info",
101
+ label: "Info",
102
+ color: "blue",
103
+ method: "info"
104
+ },
105
+ {
106
+ name: "event",
107
+ label: "Event",
108
+ color: "magenta",
109
+ method: "log"
110
+ },
111
+ {
112
+ name: "debug",
113
+ label: "Debug",
114
+ color: "gray",
115
+ method: "debug"
116
+ }
117
+ ];
118
+ function getConsoleMethod(consoleLike, method) {
119
+ return consoleLike[method] ?? consoleLike.log;
120
+ }
121
+ function createLogMethod(consoleLike, colors, isDebug, level) {
122
+ return (message, ...args) => {
123
+ if (!isDebug()) return;
124
+ const method = getConsoleMethod(consoleLike, level.method);
125
+ const labelStyle = `${getForegroundStyle(colors, level.color)};font-weight: bold;`;
126
+ const messageStyle = getForegroundStyle(colors, level.color);
127
+ method(`%c[${level.label}]%c ${message}`, labelStyle, messageStyle, ...args);
128
+ };
129
+ }
130
+ function createLoggerMethods(options) {
131
+ const levels = options.logLevels ?? DEFAULT_LOG_LEVELS;
132
+ return Object.fromEntries(levels.map((level) => [level.name, createLogMethod(options.console, options.colors, options.isDebug, level)]));
133
+ }
134
+
135
+ //#endregion
136
+ //#region src/create.ts
137
+ const noopConsole = { log: () => {} };
138
+ function readGlobalDebugFlag() {
139
+ return Object.prototype.hasOwnProperty.call(globalThis, "alitadebug") && Boolean(globalThis.alitadebug);
140
+ }
141
+ function resolveConsole(consoleLike) {
142
+ return consoleLike ?? globalThis.console ?? noopConsole;
143
+ }
144
+ function resolveDebugPredicate(isDebug) {
145
+ if (typeof isDebug === "function") return isDebug;
146
+ if (typeof isDebug === "boolean") return () => isDebug;
147
+ return readGlobalDebugFlag;
148
+ }
149
+ function createChalk(options = {}) {
150
+ const consoleLike = resolveConsole(options.console);
151
+ const colors = createColorMap(options.colors);
152
+ const isDebug = resolveDebugPredicate(options.isDebug);
153
+ const banner = createBannerMethods(consoleLike, isDebug);
154
+ const loggers = createLoggerMethods({
155
+ console: consoleLike,
156
+ colors,
157
+ isDebug,
158
+ logLevels: options.logLevels
159
+ });
160
+ return {
161
+ add,
162
+ bold,
163
+ ...banner,
164
+ black: (text) => color$1(colors, "black", text),
165
+ red: (text) => color$1(colors, "red", text),
166
+ green: (text) => color$1(colors, "green", text),
167
+ yellow: (text) => color$1(colors, "yellow", text),
168
+ blue: (text) => color$1(colors, "blue", text),
169
+ magenta: (text) => color$1(colors, "magenta", text),
170
+ cyan: (text) => color$1(colors, "cyan", text),
171
+ white: (text) => color$1(colors, "white", text),
172
+ bgBlack: (text) => bgColor$1(colors, "black", text),
173
+ bgRed: (text) => bgColor$1(colors, "red", text),
174
+ bgGreen: (text) => bgColor$1(colors, "green", text),
175
+ bgYellow: (text) => bgColor$1(colors, "yellow", text),
176
+ bgBlue: (text) => bgColor$1(colors, "blue", text),
177
+ bgMagenta: (text) => bgColor$1(colors, "magenta", text),
178
+ bgCyan: (text) => bgColor$1(colors, "cyan", text),
179
+ bgWhite: (text) => bgColor$1(colors, "white", text),
180
+ color: (name, text) => color$1(colors, name, text),
181
+ bgColor: (name, text) => bgColor$1(colors, name, text),
182
+ log: loggers.log,
183
+ wait: loggers.wait,
184
+ error: loggers.error,
185
+ warn: loggers.warn,
186
+ ready: loggers.ready,
187
+ info: loggers.info,
188
+ event: loggers.event,
189
+ debug: loggers.debug
190
+ };
191
+ }
192
+
193
+ //#endregion
194
+ //#region src/index.ts
195
+ const defaultColors = createColorMap();
196
+ const chalk = createChalk();
197
+ function color(name, text) {
198
+ return color$1(defaultColors, name, text);
199
+ }
200
+ function bgColor(name, text) {
201
+ return bgColor$1(defaultColors, name, text);
202
+ }
203
+ var src_default = chalk;
204
+
205
+ //#endregion
206
+ export { DEFAULT_COLORS, add, bgColor, bold, chalk, color, createChalk, createColorMap, src_default as default, getBackgroundStyle, getForegroundStyle, resolveColor };
207
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["DEFAULT_COLORS: ColorMap","color","color","bgColor","noopConsole: ConsoleLike","color","bgColor","colorWithMap","bgColorWithMap"],"sources":["../src/colors.ts","../src/banner.ts","../src/format.ts","../src/logger.ts","../src/create.ts","../src/index.ts"],"sourcesContent":["import type { ColorMap, CustomColorMap } from './types'\n\nexport const DEFAULT_COLORS: ColorMap = {\n black: '#000000',\n red: '#FF0000',\n green: '#008000',\n yellow: '#FFFF00',\n blue: '#0000FF',\n magenta: '#FF00FF',\n cyan: '#00FFFF',\n white: '#FFFFFF',\n gray: '#808080',\n}\n\nexport type ResolvedColorMap = Readonly<ColorMap & CustomColorMap>\n\nexport function createColorMap(customColors: CustomColorMap = {} as CustomColorMap): ResolvedColorMap {\n return {\n ...DEFAULT_COLORS,\n ...customColors,\n }\n}\n\nexport function resolveColor(colors: Readonly<Record<string, string>>, name: string): string {\n const color = colors[name]\n if (color === undefined)\n throw new Error(`Unknown chalk color: ${name}`)\n return color\n}\n\nexport function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n return `color:${resolveColor(colors, name)}`\n}\n\nexport function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const textColor = name === 'white' ? '#000' : '#fff'\n return `padding: 2px 4px; border-radius: 3px; color: ${textColor}; font-weight: bold; background:${resolveColor(colors, name)};`\n}\n","import type { ConsoleLike, DebugPredicate } from './types'\n\nexport interface BannerMethods {\n hello: (title: string, version: string) => void\n image: (url: string) => void\n}\n\nexport function createBannerMethods(consoleLike: ConsoleLike, isDebug: DebugPredicate): BannerMethods {\n return {\n hello(title: string, version: string): void {\n if (!isDebug())\n return\n consoleLike.log(\n `%c ${title} %c V${version} `,\n 'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;',\n 'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;',\n )\n },\n image(url: string): void {\n if (!url)\n return\n if (!isDebug())\n return\n consoleLike.log(\n '%c ',\n `font-size: 1px; padding: 100px 100px; background: url(${url}) no-repeat center / contain; color: transparent;`,\n )\n },\n }\n}\n","import type { FormattedText } from './types'\nimport { getBackgroundStyle, getForegroundStyle } from './colors'\n\nexport function formatText(text: string, style: string): FormattedText {\n return [`%c${text}`, style]\n}\n\nexport function color(colors: Readonly<Record<string, string>>, name: string, text: string): FormattedText {\n return formatText(text, getForegroundStyle(colors, name))\n}\n\nexport function bgColor(colors: Readonly<Record<string, string>>, name: string, text: string): FormattedText {\n return formatText(text, getBackgroundStyle(colors, name))\n}\n\nexport function bold(text: string): FormattedText {\n return formatText(text, 'font-weight: bold;')\n}\n\nexport function add(...items: readonly FormattedText[]): FormattedText {\n if (items.length === 0)\n return ['%c', '']\n const template = items.map(item => ` ${item[0]}`).join('')\n const styles = items.flatMap(([, ...itemStyles]) => itemStyles)\n return [template, ...styles] as FormattedText\n}\n","import type { ConsoleLike, ConsoleMethodName, DebugPredicate, LogLevelDefinition, LogMethod } from './types'\nimport { getForegroundStyle } from './colors'\n\nexport const DEFAULT_LOG_LEVELS = [\n { name: 'log', label: 'Log', color: 'black', method: 'log' },\n { name: 'wait', label: 'Wait', color: 'cyan', method: 'log' },\n { name: 'error', label: 'Error', color: 'red', method: 'error' },\n { name: 'warn', label: 'Warn', color: 'yellow', method: 'warn' },\n { name: 'ready', label: 'Ready', color: 'green', method: 'log' },\n { name: 'info', label: 'Info', color: 'blue', method: 'info' },\n { name: 'event', label: 'Event', color: 'magenta', method: 'log' },\n { name: 'debug', label: 'Debug', color: 'gray', method: 'debug' },\n] satisfies readonly LogLevelDefinition[]\n\nexport interface CreateLoggerMethodsOptions {\n console: ConsoleLike\n colors: Readonly<Record<string, string>>\n isDebug: DebugPredicate\n logLevels?: readonly LogLevelDefinition[]\n}\n\nfunction getConsoleMethod(consoleLike: ConsoleLike, method: ConsoleMethodName): (...data: unknown[]) => void {\n return consoleLike[method] ?? consoleLike.log\n}\n\nfunction createLogMethod(\n consoleLike: ConsoleLike,\n colors: Readonly<Record<string, string>>,\n isDebug: DebugPredicate,\n level: LogLevelDefinition,\n): LogMethod {\n return (message: string, ...args: unknown[]): void => {\n if (!isDebug())\n return\n const method = getConsoleMethod(consoleLike, level.method)\n const labelStyle = `${getForegroundStyle(colors, level.color)};font-weight: bold;`\n const messageStyle = getForegroundStyle(colors, level.color)\n method(`%c[${level.label}]%c ${message}`, labelStyle, messageStyle, ...args)\n }\n}\n\nexport function createLoggerMethods(options: CreateLoggerMethodsOptions): Record<string, LogMethod> {\n const levels = options.logLevels ?? DEFAULT_LOG_LEVELS\n return Object.fromEntries(\n levels.map(level => [\n level.name,\n createLogMethod(options.console, options.colors, options.isDebug, level),\n ]),\n )\n}\n","import type { ChalkInstance, ConsoleLike, CreateChalkOptions, DebugPredicate } from './types'\nimport { createBannerMethods } from './banner'\nimport { createColorMap } from './colors'\nimport { add, bgColor, bold, color } from './format'\nimport { createLoggerMethods } from './logger'\n\nconst noopConsole: ConsoleLike = {\n log: () => {},\n}\n\nfunction readGlobalDebugFlag(): boolean {\n return Object.prototype.hasOwnProperty.call(globalThis, 'alitadebug')\n && Boolean(globalThis.alitadebug)\n}\n\nfunction resolveConsole(consoleLike: ConsoleLike | undefined): ConsoleLike {\n return consoleLike ?? globalThis.console ?? noopConsole\n}\n\nfunction resolveDebugPredicate(isDebug: CreateChalkOptions['isDebug']): DebugPredicate {\n if (typeof isDebug === 'function')\n return isDebug\n if (typeof isDebug === 'boolean')\n return () => isDebug\n return readGlobalDebugFlag\n}\n\nexport function createChalk(options: CreateChalkOptions = {}): ChalkInstance {\n const consoleLike = resolveConsole(options.console)\n const colors = createColorMap(options.colors)\n const isDebug = resolveDebugPredicate(options.isDebug)\n const banner = createBannerMethods(consoleLike, isDebug)\n const loggers = createLoggerMethods({\n console: consoleLike,\n colors,\n isDebug,\n logLevels: options.logLevels,\n })\n\n return {\n add,\n bold,\n ...banner,\n black: text => color(colors, 'black', text),\n red: text => color(colors, 'red', text),\n green: text => color(colors, 'green', text),\n yellow: text => color(colors, 'yellow', text),\n blue: text => color(colors, 'blue', text),\n magenta: text => color(colors, 'magenta', text),\n cyan: text => color(colors, 'cyan', text),\n white: text => color(colors, 'white', text),\n bgBlack: text => bgColor(colors, 'black', text),\n bgRed: text => bgColor(colors, 'red', text),\n bgGreen: text => bgColor(colors, 'green', text),\n bgYellow: text => bgColor(colors, 'yellow', text),\n bgBlue: text => bgColor(colors, 'blue', text),\n bgMagenta: text => bgColor(colors, 'magenta', text),\n bgCyan: text => bgColor(colors, 'cyan', text),\n bgWhite: text => bgColor(colors, 'white', text),\n color: (name, text) => color(colors, name, text),\n bgColor: (name, text) => bgColor(colors, name, text),\n log: loggers.log,\n wait: loggers.wait,\n error: loggers.error,\n warn: loggers.warn,\n ready: loggers.ready,\n info: loggers.info,\n event: loggers.event,\n debug: loggers.debug,\n }\n}\n","import { createColorMap } from './colors'\nimport { createChalk } from './create'\nimport { add, bgColor as bgColorWithMap, bold, color as colorWithMap } from './format'\n\nconst defaultColors = createColorMap()\n\nexport const chalk = createChalk()\n\nexport { add, bold, createChalk }\nexport { createColorMap, DEFAULT_COLORS, getBackgroundStyle, getForegroundStyle, resolveColor } from './colors'\nexport type {\n ChalkInstance,\n ColorMap,\n ColorName,\n ConsoleLike,\n CreateChalkOptions,\n CustomColorMap,\n FormattedText,\n LogLevelDefinition,\n LogMethod,\n PublicColorName,\n TextFormatter,\n} from './types'\n\nexport function color(name: string, text: string) {\n return colorWithMap(defaultColors, name, text)\n}\n\nexport function bgColor(name: string, text: string) {\n return bgColorWithMap(defaultColors, name, text)\n}\n\nexport default chalk\n"],"mappings":";AAEA,MAAaA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;EAC7C,YAAW,SAAQA,UAAQ,QAAQ,WAAW,KAAK;EACnD,SAAQ,SAAQA,UAAQ,QAAQ,QAAQ,KAAK;EAC7C,UAAS,SAAQA,UAAQ,QAAQ,SAAS,KAAK;EAC/C,QAAQ,MAAM,SAASD,QAAM,QAAQ,MAAM,KAAK;EAChD,UAAU,MAAM,SAASC,UAAQ,QAAQ,MAAM,KAAK;EACpD,KAAK,QAAQ;EACb,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,OAAO,QAAQ;EAChB;;;;;ACjEH,MAAM,gBAAgB,gBAAgB;AAEtC,MAAa,QAAQ,aAAa;AAkBlC,SAAgB,MAAM,MAAc,MAAc;AAChD,QAAOC,QAAa,eAAe,MAAM,KAAK;;AAGhD,SAAgB,QAAQ,MAAc,MAAc;AAClD,QAAOC,UAAe,eAAe,MAAM,KAAK;;AAGlD,kBAAe"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@jacob-z/chalk",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "description": "Browser console coloring utilities compatible with alita/chalk behavior.",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.mts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.mjs",
17
+ "types": "./dist/index.d.mts",
18
+ "files": [
19
+ "README.md",
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsdown",
24
+ "dev": "tsdown --watch",
25
+ "lint": "eslint .",
26
+ "lint:fix": "eslint . --fix",
27
+ "test": "vitest run",
28
+ "test:watch": "vitest",
29
+ "typecheck": "tsc --noEmit",
30
+ "verify": "pnpm run typecheck && pnpm run test && pnpm run lint && pnpm run build"
31
+ },
32
+ "devDependencies": {
33
+ "@antfu/eslint-config": "^6.0.0",
34
+ "eslint": "^9.0.0",
35
+ "tsdown": "^0.17.0",
36
+ "typescript": "^5.9.0",
37
+ "vitest": "^4.0.0"
38
+ }
39
+ }