@mourtazag/blah 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.
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mourtazag
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # blah
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
+
5
+ Open-source **browser** console logger with a namespace badge and per-argument colors using `console` `%c` CSS.
6
+
7
+ > **Browser only** — relies on DevTools `%c` styling. Not for Node/terminal output.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @mourtazag/blah
13
+ ```
14
+
15
+ ## Quick start
16
+
17
+ ```ts
18
+ import Blah from '@mourtazag/blah'
19
+
20
+ const logger = new Blah({
21
+ namespace: {
22
+ name: 'App',
23
+ style: { color: 'white', bgColor: '#f97316' },
24
+ },
25
+ argStyles: [
26
+ { color: 'white', bgColor: '#2563eb' },
27
+ { color: 'black', bgColor: '#facc15' },
28
+ ],
29
+ })
30
+
31
+ logger.log('user clicked', 'button#submit')
32
+ logger.warn('slow request', { ms: 420 })
33
+ ```
34
+
35
+ Open DevTools → **Console** to see colored badges.
36
+
37
+ ## Examples
38
+
39
+ ### Console output
40
+
41
+ Each segment gets its own colored badge (namespace + one badge per argument):
42
+
43
+ ![Console example showing styled badges for namespace and log arguments](./docs/images/console-example.png)
44
+
45
+ ### Playground
46
+
47
+ Run `npm run dev` and open http://localhost:3000 to try the interactive demo:
48
+
49
+ ![Playground demo page with HTML, CSS, and JS sections](./docs/images/playground.png)
50
+
51
+ ## Logging controls
52
+
53
+ Mute output globally or per level:
54
+
55
+ ```ts
56
+ const logger = new Blah({
57
+ namespace: { name: 'App' },
58
+ logging: {
59
+ enabled: true,
60
+ log: true,
61
+ info: true,
62
+ warn: false,
63
+ error: true,
64
+ },
65
+ })
66
+ ```
67
+
68
+ **Debug mode** overrides `logging` and always prints:
69
+
70
+ ```ts
71
+ const logger = new Blah({
72
+ namespace: { name: 'App' },
73
+ logging: { enabled: false },
74
+ debug: import.meta.env.DEV,
75
+ })
76
+
77
+ logger.setDebug(true)
78
+ logger.setLogging({ warn: false })
79
+ logger.isEnabled('warn') // false unless debug is on
80
+ ```
81
+
82
+ ## API
83
+
84
+ ### `new Blah(options)`
85
+
86
+ | Option | Type | Description |
87
+ |--------|------|-------------|
88
+ | `namespace` | `NamespaceConfig` | Badge label + optional `style` |
89
+ | `argStyles` | `BadgeStyle[]` | CSS per log argument (by index) |
90
+ | `logging` | `LoggingConfig` | Enable/disable levels |
91
+ | `debug` | `boolean` | Force all levels on |
92
+
93
+ ### Methods
94
+
95
+ - `log(...args)` / `info` / `warn` / `error`
96
+ - `setLogging(config)` — merge logging flags
97
+ - `setDebug(debug)` — toggle debug override
98
+ - `isEnabled(level)` — check if a level would print
99
+
100
+ ### Types (exported)
101
+
102
+ `BadgeStyle`, `NamespaceConfig`, `BlahOptions`, `LoggingConfig`, `LogLevel`
103
+
104
+ ## Local development
105
+
106
+ ```bash
107
+ git clone <your-repo-url>
108
+ cd blah
109
+ npm install
110
+ npm run dev # playground at http://localhost:3000
111
+ npm test
112
+ npm run build:lib # dist/ for npm
113
+ npm pack --dry-run # preview published tarball
114
+ ```
115
+
116
+ Playground lives in `playground/`; the publishable package is `src/` → `dist/`.
117
+
118
+ ## License
119
+
120
+ This project is **open source** under the [MIT License](LICENSE).
121
+
122
+ You may use, copy, modify, and distribute it freely, including in commercial projects, as long as the copyright and license notice are included.
@@ -0,0 +1,51 @@
1
+ /** Colors for one console badge */
2
+ interface BadgeStyle {
3
+ color?: string;
4
+ bgColor?: string;
5
+ }
6
+ interface NamespaceConfig {
7
+ name?: string;
8
+ style?: BadgeStyle;
9
+ }
10
+ type LogLevel = 'log' | 'info' | 'warn' | 'error';
11
+ interface LoggingConfig {
12
+ /** Master switch — when false, nothing is printed */
13
+ enabled?: boolean;
14
+ log?: boolean;
15
+ info?: boolean;
16
+ warn?: boolean;
17
+ error?: boolean;
18
+ }
19
+ interface BlahOptions {
20
+ namespace: NamespaceConfig;
21
+ /** One style per log argument, by index (0 = first value after the namespace badge) */
22
+ argStyles?: BadgeStyle[];
23
+ logging?: LoggingConfig;
24
+ /**
25
+ * When true, prints every level regardless of `logging`.
26
+ * Useful in dev to force output while keeping production logging muted.
27
+ */
28
+ debug?: boolean;
29
+ }
30
+
31
+ declare class Blah {
32
+ private readonly namespace;
33
+ private readonly namespaceStyle;
34
+ /** CSS strings ready for console — built once in the constructor */
35
+ private readonly resolvedArgStyles;
36
+ private logging;
37
+ private debug;
38
+ constructor(options: BlahOptions);
39
+ /** Force all levels on/off, overriding `logging` restrictions */
40
+ setDebug(debug: boolean): void;
41
+ /** Update logging flags (merged with current settings) */
42
+ setLogging(config: LoggingConfig): void;
43
+ isEnabled(level: LogLevel): boolean;
44
+ private print;
45
+ log(...args: unknown[]): void;
46
+ info(...args: unknown[]): void;
47
+ warn(...args: unknown[]): void;
48
+ error(...args: unknown[]): void;
49
+ }
50
+
51
+ export { type BadgeStyle, Blah, type BlahOptions, type LogLevel, type LoggingConfig, type NamespaceConfig, Blah as default };
package/dist/index.js ADDED
@@ -0,0 +1,114 @@
1
+ // src/blah-utils.ts
2
+ var BASE_BADGE = "padding: 2px 4px; margin: 2px; border-radius: 4px; font-weight: bold;";
3
+ var DEFAULT_NAMESPACE_STYLE = {
4
+ color: "white",
5
+ bgColor: "black"
6
+ };
7
+ var DEFAULT_ARG_STYLE = {
8
+ color: "inherit",
9
+ bgColor: "transparent"
10
+ };
11
+ function resolveLogging(config = {}) {
12
+ const enabled = config.enabled ?? true;
13
+ if (!enabled) {
14
+ return { enabled: false, log: false, info: false, warn: false, error: false };
15
+ }
16
+ return {
17
+ enabled: true,
18
+ log: config.log ?? true,
19
+ info: config.info ?? true,
20
+ warn: config.warn ?? true,
21
+ error: config.error ?? true
22
+ };
23
+ }
24
+ function toCss(style, fallback = {}) {
25
+ const color = style.color ?? fallback.color ?? DEFAULT_ARG_STYLE.color;
26
+ const bgColor = style.bgColor ?? fallback.bgColor ?? DEFAULT_ARG_STYLE.bgColor;
27
+ return `${BASE_BADGE} color: ${color}; background-color: ${bgColor};`;
28
+ }
29
+ function formatArg(value) {
30
+ if (typeof value === "string") return value;
31
+ if (typeof value === "object" && value !== null) {
32
+ try {
33
+ return JSON.stringify(value);
34
+ } catch {
35
+ return String(value);
36
+ }
37
+ }
38
+ return String(value);
39
+ }
40
+ function buildConsolePayload(namespace, namespaceStyle, resolvedArgStyles, args) {
41
+ let format = `%c${namespace}`;
42
+ const styles = [namespaceStyle];
43
+ for (const [index, arg] of args.entries()) {
44
+ format += ` %c${formatArg(arg)}`;
45
+ styles.push(resolvedArgStyles[index] ?? toCss({}));
46
+ }
47
+ return [format, ...styles];
48
+ }
49
+
50
+ // src/Blah.ts
51
+ var Blah = class {
52
+ namespace;
53
+ namespaceStyle;
54
+ /** CSS strings ready for console — built once in the constructor */
55
+ resolvedArgStyles;
56
+ logging;
57
+ debug;
58
+ constructor(options) {
59
+ this.namespace = options.namespace.name ?? "Blah";
60
+ this.namespaceStyle = toCss(
61
+ options.namespace.style ?? {},
62
+ DEFAULT_NAMESPACE_STYLE
63
+ );
64
+ this.resolvedArgStyles = (options.argStyles ?? []).map((style) => toCss(style));
65
+ this.logging = resolveLogging(options.logging);
66
+ this.debug = options.debug ?? false;
67
+ }
68
+ /** Force all levels on/off, overriding `logging` restrictions */
69
+ setDebug(debug) {
70
+ this.debug = debug;
71
+ }
72
+ /** Update logging flags (merged with current settings) */
73
+ setLogging(config) {
74
+ this.logging = resolveLogging({
75
+ enabled: config.enabled ?? this.logging.enabled,
76
+ log: config.log ?? this.logging.log,
77
+ info: config.info ?? this.logging.info,
78
+ warn: config.warn ?? this.logging.warn,
79
+ error: config.error ?? this.logging.error
80
+ });
81
+ }
82
+ isEnabled(level) {
83
+ return this.debug || this.logging.enabled && this.logging[level];
84
+ }
85
+ print(method, ...args) {
86
+ if (!this.isEnabled(method)) return;
87
+ console[method](
88
+ ...buildConsolePayload(
89
+ this.namespace,
90
+ this.namespaceStyle,
91
+ this.resolvedArgStyles,
92
+ args
93
+ )
94
+ );
95
+ }
96
+ log(...args) {
97
+ this.print("log", ...args);
98
+ }
99
+ info(...args) {
100
+ this.print("info", ...args);
101
+ }
102
+ warn(...args) {
103
+ this.print("warn", ...args);
104
+ }
105
+ error(...args) {
106
+ this.print("error", ...args);
107
+ }
108
+ };
109
+ var Blah_default = Blah;
110
+ export {
111
+ Blah_default as Blah,
112
+ Blah_default as default
113
+ };
114
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/blah-utils.ts","../src/Blah.ts"],"sourcesContent":["import type { BadgeStyle, LoggingConfig } from './blah-types'\n\nexport const BASE_BADGE =\n 'padding: 2px 4px; margin: 2px; border-radius: 4px; font-weight: bold;'\n\nexport const DEFAULT_NAMESPACE_STYLE: Required<BadgeStyle> = {\n color: 'white',\n bgColor: 'black',\n}\n\nexport const DEFAULT_ARG_STYLE: Required<BadgeStyle> = {\n color: 'inherit',\n bgColor: 'transparent',\n}\n\nexport const DEFAULT_LOGGING: Required<LoggingConfig> = {\n enabled: true,\n log: true,\n info: true,\n warn: true,\n error: true,\n}\n\n/** Resolve logging flags; global `enabled: false` turns off every level */\nexport function resolveLogging(config: LoggingConfig = {}): Required<LoggingConfig> {\n const enabled = config.enabled ?? true\n if (!enabled) {\n return { enabled: false, log: false, info: false, warn: false, error: false }\n }\n return {\n enabled: true,\n log: config.log ?? true,\n info: config.info ?? true,\n warn: config.warn ?? true,\n error: config.error ?? true,\n }\n}\n\n/** Turn { color, bgColor } into a CSS string for console %c */\nexport function toCss(style: BadgeStyle, fallback: BadgeStyle = {}): string {\n const color = style.color ?? fallback.color ?? DEFAULT_ARG_STYLE.color\n const bgColor = style.bgColor ?? fallback.bgColor ?? DEFAULT_ARG_STYLE.bgColor\n return `${BASE_BADGE} color: ${color}; background-color: ${bgColor};`\n}\n\n/** Convert any log value into text for a %c badge */\nexport function formatArg(value: unknown): string {\n if (typeof value === 'string') return value\n if (typeof value === 'object' && value !== null) {\n try {\n return JSON.stringify(value)\n } catch {\n return String(value)\n }\n }\n return String(value)\n}\n\n/** Build the format string + CSS values that console.log expects */\nexport function buildConsolePayload(\n namespace: string,\n namespaceStyle: string,\n resolvedArgStyles: string[],\n args: unknown[],\n): [string, ...string[]] {\n let format = `%c${namespace}`\n const styles: string[] = [namespaceStyle]\n\n for (const [index, arg] of args.entries()) {\n format += ` %c${formatArg(arg)}`\n styles.push(resolvedArgStyles[index] ?? toCss({}))\n }\n\n return [format, ...styles]\n}\n","import type { BlahOptions, LogLevel, LoggingConfig } from './blah-types'\nimport {\n buildConsolePayload,\n DEFAULT_NAMESPACE_STYLE,\n resolveLogging,\n toCss,\n} from './blah-utils'\n\nexport type {\n BadgeStyle,\n BlahOptions,\n LogLevel,\n LoggingConfig,\n NamespaceConfig,\n} from './blah-types'\n\nclass Blah {\n private readonly namespace: string\n private readonly namespaceStyle: string\n /** CSS strings ready for console — built once in the constructor */\n private readonly resolvedArgStyles: string[]\n private logging: Required<LoggingConfig>\n private debug: boolean\n\n constructor(options: BlahOptions) {\n this.namespace = options.namespace.name ?? 'Blah'\n this.namespaceStyle = toCss(\n options.namespace.style ?? {},\n DEFAULT_NAMESPACE_STYLE,\n )\n this.resolvedArgStyles = (options.argStyles ?? []).map(style => toCss(style))\n this.logging = resolveLogging(options.logging)\n this.debug = options.debug ?? false\n }\n\n /** Force all levels on/off, overriding `logging` restrictions */\n setDebug(debug: boolean): void {\n this.debug = debug\n }\n\n /** Update logging flags (merged with current settings) */\n setLogging(config: LoggingConfig): void {\n this.logging = resolveLogging({\n enabled: config.enabled ?? this.logging.enabled,\n log: config.log ?? this.logging.log,\n info: config.info ?? this.logging.info,\n warn: config.warn ?? this.logging.warn,\n error: config.error ?? this.logging.error,\n })\n }\n\n isEnabled(level: LogLevel): boolean {\n return this.debug || (this.logging.enabled && this.logging[level])\n }\n\n private print(method: LogLevel, ...args: unknown[]): void {\n if (!this.isEnabled(method)) return\n\n console[method](\n ...buildConsolePayload(\n this.namespace,\n this.namespaceStyle,\n this.resolvedArgStyles,\n args,\n ),\n )\n }\n\n log(...args: unknown[]): void {\n this.print('log', ...args)\n }\n\n info(...args: unknown[]): void {\n this.print('info', ...args)\n }\n\n warn(...args: unknown[]): void {\n this.print('warn', ...args)\n }\n\n error(...args: unknown[]): void {\n this.print('error', ...args)\n }\n}\n\nexport default Blah\n"],"mappings":";AAEO,IAAM,aACX;AAEK,IAAM,0BAAgD;AAAA,EAC3D,OAAO;AAAA,EACP,SAAS;AACX;AAEO,IAAM,oBAA0C;AAAA,EACrD,OAAO;AAAA,EACP,SAAS;AACX;AAWO,SAAS,eAAe,SAAwB,CAAC,GAA4B;AAClF,QAAM,UAAU,OAAO,WAAW;AAClC,MAAI,CAAC,SAAS;AACZ,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 "name": "@mourtazag/blah",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "version": "1.0.0",
7
+ "description": "Styled browser console logger with namespace badges and per-argument colors",
8
+ "type": "module",
9
+ "sideEffects": false,
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ }
20
+ },
21
+ "scripts": {
22
+ "dev": "vite",
23
+ "build": "npm run build:lib && npm run build:playground",
24
+ "build:lib": "tsup",
25
+ "build:playground": "vite build",
26
+ "preview": "vite preview",
27
+ "typecheck": "tsc --noEmit",
28
+ "format": "prettier --write .",
29
+ "format:check": "prettier --check .",
30
+ "test": "vitest run",
31
+ "test:watch": "vitest",
32
+ "screenshots": "node scripts/capture-screenshots.mjs",
33
+ "prepublishOnly": "npm test && npm run build:lib"
34
+ },
35
+ "keywords": [
36
+ "console",
37
+ "logger",
38
+ "browser",
39
+ "debug",
40
+ "typescript"
41
+ ],
42
+ "author": "mourtazag",
43
+ "license": "MIT",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/mourtazag/blah.git"
47
+ },
48
+ "bugs": {
49
+ "url": "https://github.com/mourtazag/blah/issues"
50
+ },
51
+ "homepage": "https://github.com/mourtazag/blah#readme",
52
+ "devDependencies": {
53
+ "playwright": "^1.60.0",
54
+ "prettier": "^3.8.3",
55
+ "tsup": "^8.5.1",
56
+ "typescript": "^6.0.3",
57
+ "vite": "^6.3.5",
58
+ "vitest": "^4.1.7"
59
+ }
60
+ }