use-term 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hansm7
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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,174 @@
1
+ # use-term 🚀
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/use-term.svg?style=flat-rounded&color=blue)](https://www.npmjs.com/package/use-term)
4
+ [![License](https://img.shields.io/npm/l/use-term.svg?style=flat-rounded&color=green)](https://github.com/hansm7/use-term/blob/main/LICENSE)
5
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg?style=flat-rounded)](https://www.npmjs.com/package/use-term)
6
+ [![NodeJS Version](https://img.shields.io/badge/node-%3E%3D%2012.0.0-blue.svg?style=flat-rounded)](https://nodejs.org/)
7
+
8
+ A **zero-dependency**, ultra-lightweight, and beautiful terminal logging library for Node.js. It features smart context detection (classes, functions, or text), automatic subtle timestamps, beautiful emojis, and colored object inspection.
9
+
10
+ ---
11
+
12
+ ## ✨ Features
13
+
14
+ - 🔋 **Zero Dependencies:** Pure vanilla Node.js using native ANSI color escapes and `util.inspect`. High performance and 100% secure.
15
+ - 🧠 **Smart Context Detection:** Automatically extracts scopes/context names from class instances (`this`), function references, or plain strings.
16
+ - âąī¸ **Automatic Timestamps:** Every line starts with a subtle, gray-colored time stamp `HH:MM:SS` that keeps your logs tidy and organized.
17
+ - 🎨 **Visual Styling:** Beautifully formatted log categories with color-coded tags and emojis:
18
+ - â„šī¸ `INFO` (Cyan)
19
+ - ❌ `ERROR` (Red)
20
+ - ✅ `SUCCESS` (Green)
21
+ - âš ī¸ `WARN` (Yellow)
22
+ - đŸ“Ļ **Rich Object/Data Inspection:** Automatically colorizes and formats nested metadata, objects, and arrays.
23
+ - 📝 **Title Dividers:** Easily print prominent section headers using the `.title()` function.
24
+ - đŸŽ¯ **TypeScript Ready:** Ships with full `.d.ts` declaration files for autocomplete and TypeScript projects.
25
+
26
+ ---
27
+
28
+ ## đŸ“Ļ Installation
29
+
30
+ Install the package via npm:
31
+
32
+ ```bash
33
+ npm install use-term
34
+ ```
35
+
36
+ ---
37
+
38
+ ## 🚀 Usage
39
+
40
+ Since `use-term` is built with universal Node.js compatibility in mind, it works seamlessly in both modern **ES Modules (ESM)** and legacy **CommonJS** environments out-of-the-box without requiring separate bundles or transpilation.
41
+
42
+ ### 1. Modern ES Modules (ESM) — _Recommended_
43
+
44
+ For modern Node.js environments (projects with `"type": "module"` in `package.json`), TypeScript, Next.js, or Vite:
45
+
46
+ ```javascript
47
+ import term from "use-term";
48
+
49
+ // --- A. Using inside a class (automatically gets class name) ---
50
+ class AuthService {
51
+ login() {
52
+ term.info(this, "Starting login process...");
53
+
54
+ const user = { id: 42, name: "Alex", roles: ["admin", "billing"] };
55
+ term.success(this, "Credentials validated successfully", user);
56
+ }
57
+ }
58
+
59
+ // --- B. Using inside a function (automatically gets function name) ---
60
+ function processPayment() {
61
+ term.warn(processPayment, "Payment gateway is responding slowly", {
62
+ delayMs: 1500,
63
+ });
64
+ term.error(processPayment, "Payment gateway connection timeout", {
65
+ code: "ETIMEDOUT",
66
+ });
67
+ }
68
+
69
+ // --- C. Using custom string scopes ---
70
+ term.info("Server", "Server initialized on port 3000", { env: "production" });
71
+
72
+ // --- D. Visual titles ---
73
+ term.title("Authentication Flow");
74
+ const auth = new AuthService();
75
+ auth.login();
76
+
77
+ term.title("Payment Flow");
78
+ processPayment();
79
+ ```
80
+
81
+ ---
82
+
83
+ ### 2. CommonJS (require)
84
+
85
+ For traditional Node.js applications:
86
+
87
+ ```javascript
88
+ const term = require("use-term");
89
+
90
+ // Easily log with CommonJS:
91
+ term.info("CJS", "Logging using standard require() syntax!");
92
+
93
+ class AuthService {
94
+ login() {
95
+ term.info(this, "Starting login process...");
96
+ const user = { id: 42, name: "Alex", roles: ["admin", "billing"] };
97
+ term.success(this, "Credentials validated successfully", user);
98
+ }
99
+ }
100
+
101
+ term.title("CommonJS Demo");
102
+ const auth = new AuthService();
103
+ auth.login();
104
+ ```
105
+
106
+ ---
107
+
108
+ ## 🎨 Log Outputs Preview
109
+
110
+ When you run your scripts, your terminal will light up with premium, high-visibility, clean styling:
111
+
112
+ ```text
113
+ 14:23:05 â„šī¸ INFO [Server] Server initialized on port 3000
114
+ { env: 'production' }
115
+
116
+ ━━━ AUTHENTICATION FLOW ━━━
117
+ 14:23:05 â„šī¸ INFO [AuthService] Starting login process...
118
+ 14:23:05 ✅ SUCCESS [AuthService] Credentials validated successfully
119
+ { id: 42, name: 'Alex', roles: [ 'admin', 'billing' ] }
120
+
121
+ ━━━ PAYMENT FLOW ━━━
122
+ 14:23:05 âš ī¸ WARN [processPayment] Payment gateway is responding slowly
123
+ { delayMs: 1500 }
124
+ 14:23:05 ❌ ERROR [processPayment] Payment gateway connection timeout
125
+ { code: 'ETIMEDOUT' }
126
+ ```
127
+
128
+ ---
129
+
130
+ ## đŸ› ī¸ API Reference
131
+
132
+ ### `term.info(context, message, [data])`
133
+
134
+ Logs an informational message.
135
+
136
+ - `context` `(any)`: `this` inside a class, a function name, or a plain string.
137
+ - `message` `(string)`: The description text of the log.
138
+ - `data` `(any, optional)`: Any object, array, or metadata to inspect and format below.
139
+
140
+ ### `term.error(context, message, [data])`
141
+
142
+ Logs an error message. Same signature as `info()`.
143
+
144
+ ### `term.success(context, message, [data])`
145
+
146
+ Logs a success message. Same signature as `info()`.
147
+
148
+ ### `term.warn(context, message, [data])`
149
+
150
+ Logs a warning message. Same signature as `info()`.
151
+
152
+ ### `term.title(message)`
153
+
154
+ Prints a highlighted, uppercase section divider to demarcate different stages in your runtime.
155
+
156
+ - `message` `(string)`: The header text.
157
+
158
+ ---
159
+
160
+ ## đŸĻž TypeScript Support
161
+
162
+ Autocompletion works out of the box in VS Code and modern IDEs. If you are using TypeScript:
163
+
164
+ ```typescript
165
+ import term from "use-term";
166
+
167
+ term.info("TypeScript", "Fully typed logger out of the box!");
168
+ ```
169
+
170
+ ---
171
+
172
+ ## 📄 License
173
+
174
+ This project is licensed under the [MIT License](LICENSE).
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "use-term",
3
+ "version": "1.0.0",
4
+ "description": "A zero-dependency, ultra-lightweight, and beautiful terminal logging library for Node.js with smart context detection, colored outputs, and automatic timestamps.",
5
+ "main": "src/term.js",
6
+ "types": "src/term.d.ts",
7
+ "files": [
8
+ "src",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/hansm7/use-term.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/hansm7/use-term/issues"
18
+ },
19
+ "homepage": "https://github.com/hansm7/use-term#readme",
20
+ "keywords": [
21
+ "logger",
22
+ "terminal",
23
+ "console",
24
+ "color",
25
+ "ansi",
26
+ "beautiful",
27
+ "zero-dependency",
28
+ "context",
29
+ "lightweight",
30
+ "term-logger",
31
+ "success",
32
+ "info",
33
+ "error",
34
+ "warn"
35
+ ],
36
+ "author": "hansm7",
37
+ "license": "MIT",
38
+ "engines": {
39
+ "node": ">=12.0.0"
40
+ }
41
+ }
package/src/term.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * A beautiful, simple, and dependency-free terminal logger for Node.js.
3
+ */
4
+ declare class Term {
5
+ /**
6
+ * Logs an informational message.
7
+ * @param context The context of the log (e.g. `this`, a class instance, a function reference, or a string).
8
+ * @param msg The message to log.
9
+ * @param data Optional metadata or object to inspect.
10
+ */
11
+ info(context: any, msg: string, data?: any): void;
12
+
13
+ /**
14
+ * Logs an error message.
15
+ * @param context The context of the log (e.g. `this`, a class instance, a function reference, or a string).
16
+ * @param msg The message to log.
17
+ * @param data Optional metadata or object to inspect.
18
+ */
19
+ error(context: any, msg: string, data?: any): void;
20
+
21
+ /**
22
+ * Logs a success message.
23
+ * @param context The context of the log (e.g. `this`, a class instance, a function reference, or a string).
24
+ * @param msg The message to log.
25
+ * @param data Optional metadata or object to inspect.
26
+ */
27
+ success(context: any, msg: string, data?: any): void;
28
+
29
+ /**
30
+ * Logs a warning message.
31
+ * @param context The context of the log (e.g. `this`, a class instance, a function reference, or a string).
32
+ * @param msg The message to log.
33
+ * @param data Optional metadata or object to inspect.
34
+ */
35
+ warn(context: any, msg: string, data?: any): void;
36
+
37
+ /**
38
+ * Prints a bold, beautifully stylized title separator in the console.
39
+ * @param msg The section title to display.
40
+ */
41
+ title(msg: string): void;
42
+ }
43
+
44
+ declare const term: Term;
45
+ export = term;
package/src/term.js ADDED
@@ -0,0 +1,66 @@
1
+ const util = require('util');
2
+
3
+ const COLORS = {
4
+ info: '\x1b[36m',
5
+ error: '\x1b[31m',
6
+ success: '\x1b[32m',
7
+ warn: '\x1b[33m',
8
+ blue: '\x1b[34m',
9
+ gray: '\x1b[90m',
10
+ magenta: '\x1b[35m',
11
+ reset: '\x1b[0m',
12
+ bold: '\x1b[1m'
13
+ };
14
+
15
+ class Term {
16
+ _timestamp() {
17
+ const now = new Date();
18
+ const time = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}`;
19
+ return `${COLORS.gray}${time}${COLORS.reset}`;
20
+ }
21
+
22
+ _getContextName(ctx) {
23
+ if (!ctx) return 'App';
24
+ if (typeof ctx === 'string') return ctx;
25
+ if (typeof ctx === 'function') return ctx.name || 'AnonymousFn';
26
+ if (typeof ctx === 'object' && ctx.constructor) return ctx.constructor.name;
27
+ return 'Unknown';
28
+ }
29
+
30
+ _log(type, color, icon, context, msg, data) {
31
+ const ctxName = this._getContextName(context);
32
+ const timestamp = this._timestamp();
33
+ const tag = `${color}${icon} ${type}${COLORS.reset}`;
34
+ const scope = `${COLORS.blue}[${ctxName}]${COLORS.reset}`;
35
+
36
+ console.log(`${timestamp} ${tag} ${scope} ${msg}`);
37
+
38
+ if (data !== undefined && data !== null) {
39
+ const formatted = util.inspect(data, { colors: true, depth: null });
40
+ const indented = formatted.split('\n').map(l => l).join('\n');
41
+ console.log(indented);
42
+ }
43
+ }
44
+
45
+ info(context, msg, data) {
46
+ this._log('INFO', COLORS.info, 'â„šī¸ ', context, msg, data);
47
+ }
48
+
49
+ error(context, msg, data) {
50
+ this._log('ERROR', COLORS.error, '❌', context, msg, data);
51
+ }
52
+
53
+ success(context, msg, data) {
54
+ this._log('SUCCESS', COLORS.success, '✅', context, msg, data);
55
+ }
56
+
57
+ warn(context, msg, data) {
58
+ this._log('WARN', COLORS.warn, 'âš ī¸ ', context, msg, data);
59
+ }
60
+
61
+ title(msg) {
62
+ console.log(`\n${COLORS.magenta}${COLORS.bold}━━━ ${msg.toUpperCase()} ━━━${COLORS.reset}`);
63
+ }
64
+ }
65
+
66
+ module.exports = new Term();