@leostacowski/pkgs 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -14
- package/modules/index.js +7 -1
- package/modules/logger/README.md +239 -0
- package/modules/logger/index.js +0 -3
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -1,35 +1,74 @@
|
|
|
1
1
|
# @leostacowski/pkgs
|
|
2
2
|
|
|
3
|
-
_"It's ugly but it's mine"
|
|
3
|
+
_"It's ugly but it's mine."_
|
|
4
4
|
|
|
5
5
|
\- _Me describing my code._
|
|
6
6
|
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Motivation](#motivation)
|
|
10
|
+
- [Requirements](#requirements)
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Usage](#usage)
|
|
13
|
+
- [Modules](#modules)
|
|
14
|
+
- [@leostacowski/pkgs/logger](#leostacowskipkgslogger)
|
|
15
|
+
|
|
7
16
|
## Motivation
|
|
8
17
|
|
|
9
|
-
After
|
|
18
|
+
After repeatedly starting things from scratch for a long time:
|
|
10
19
|
|
|
11
20
|
```text
|
|
12
21
|
I decided to finally create a centralized repo for my scripts.
|
|
13
22
|
```
|
|
14
23
|
|
|
15
|
-
This decision was directly inspired by Eskil Steenberg's talk: "_[You should finish your software](https://youtu.be/EGLoKbBn-VI?si=uFVlbKIcRolcOzCy)_"
|
|
24
|
+
This decision was directly inspired by Eskil Steenberg's talk: "_[You should finish your software](https://youtu.be/EGLoKbBn-VI?si=uFVlbKIcRolcOzCy)_".
|
|
16
25
|
|
|
17
|
-
If you are using any of these
|
|
26
|
+
If you are using any of these modules and something is breaking, or if you have a suggestion, please [open an issue](https://github.com/leostacowski/pkgs/issues/).
|
|
18
27
|
|
|
19
|
-
|
|
20
|
-
2. Have any suggestions.
|
|
28
|
+
I intend to keep adding stuff to this repo as long as I continue to reinvent the wheel!
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
## Requirements
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
- [Opening an Issue](https://github.com/leostacowski/pkgs/issues/).
|
|
32
|
+
`node >= 22.12.0` is a _safe choice_, but let me know your luck on older releases.
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm i @leostacowski/pkgs
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
Everything begins at the `@leostacowski/pkgs` package:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import pkgs from '@leostacowski/pkgs'
|
|
46
|
+
// or
|
|
47
|
+
const pkgs = require('@leostacowski/pkgs').default
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Then import what you need:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
import { ModuleX } from '@leostacowski/pkgs'
|
|
54
|
+
// or
|
|
55
|
+
const { ModuleX } = require('@leostacowski/pkgs')
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or import a specific module and ignore the rest:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import ModuleY from '@leostacowski/pkgs/ModuleY'
|
|
62
|
+
// or
|
|
63
|
+
const ModuleY = require('@leostacowski/pkgs/ModuleY')
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For usage details on each module, refer to [Modules](#modules).
|
|
28
67
|
|
|
29
|
-
##
|
|
68
|
+
## Modules
|
|
30
69
|
|
|
31
|
-
### @leostacowski/pkgs/
|
|
70
|
+
### @leostacowski/pkgs/logger
|
|
32
71
|
|
|
33
|
-
|
|
72
|
+
A simple logger that supports aliases, types, colors and other knobs.
|
|
34
73
|
|
|
35
|
-
Check
|
|
74
|
+
Check its [README.md](https://github.com/leostacowski/pkgs/blob/main/modules/logger/README.md) for details.
|
package/modules/index.js
CHANGED
package/modules/logger/README.md
CHANGED
|
@@ -1 +1,240 @@
|
|
|
1
1
|
# @leostacowski/pkgs/logger
|
|
2
|
+
|
|
3
|
+
Simple Logger that supports aliases, types, colors and other knobs.
|
|
4
|
+
|
|
5
|
+
> For the main package `@leostacowski/pkgs`: See the [main README.md](/README.md).
|
|
6
|
+
|
|
7
|
+
# Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Usage](#usage)
|
|
10
|
+
- [Import](#import)
|
|
11
|
+
- [Options](#options)
|
|
12
|
+
- [_prefix_: `string`](#prefix-string)
|
|
13
|
+
- [_group_: `boolean`](#group-boolean)
|
|
14
|
+
- [_colors_: `boolean`](#colors-boolean)
|
|
15
|
+
- [_text_color_: `string`](#text_color-string)
|
|
16
|
+
- [_level_: `number`](#level-number)
|
|
17
|
+
- [Types](#types)
|
|
18
|
+
- [Examples](#examples)
|
|
19
|
+
- [Basic](#basic)
|
|
20
|
+
- [Prefix](#prefix)
|
|
21
|
+
- [Same Line](#same-line)
|
|
22
|
+
- [Level Filtering](#level-filtering)
|
|
23
|
+
|
|
24
|
+
# Usage
|
|
25
|
+
|
|
26
|
+
## Import
|
|
27
|
+
|
|
28
|
+
From `@leostacowski/pkgs`:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import { Logger } from '@leostacowski/pkgs'
|
|
32
|
+
// or
|
|
33
|
+
const { Logger } = require('@leostacowski/pkgs')
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or straight from the source:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import Logger from '@leostacowski/pkgs/logger'
|
|
40
|
+
// or
|
|
41
|
+
const Logger = require('@leostacowski/pkgs/logger')
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Options
|
|
45
|
+
|
|
46
|
+
When calling `Logger()`, you can customize your instance. Here are the defaults:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
const logger = Logger({
|
|
50
|
+
prefix: '',
|
|
51
|
+
group: true,
|
|
52
|
+
colors: true,
|
|
53
|
+
text_color: '',
|
|
54
|
+
level: 0,
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Alternatively, pass a single `string` argument, and set just `prefix`:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
const logger = Logger('My prefix 😉')
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
You could just ignore everything:
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
const logger = Logger()
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### _prefix_: `string`
|
|
71
|
+
|
|
72
|
+
Defines a value to append to the output prefix.
|
|
73
|
+
|
|
74
|
+
### _group_: `boolean`
|
|
75
|
+
|
|
76
|
+
Toggles the use of [group](https://nodejs.org/api/console.html#consolegrouplabel) and [groupEnd](https://nodejs.org/api/console.html#consolegroupend).
|
|
77
|
+
|
|
78
|
+
If `true`, uses [_prefix_](#prefix-string) as the group label.
|
|
79
|
+
|
|
80
|
+
### _colors_: `boolean`
|
|
81
|
+
|
|
82
|
+
Toggles the use of [ANSI colors](https://en.wikipedia.org/wiki/ANSI_escape_code) on console output. Here are the defaults:
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
{
|
|
86
|
+
RED: {
|
|
87
|
+
code: '\x1b[91m',
|
|
88
|
+
},
|
|
89
|
+
GREEN: {
|
|
90
|
+
code: '\x1b[92m',
|
|
91
|
+
},
|
|
92
|
+
YELLOW: {
|
|
93
|
+
code: '\x1b[93m',
|
|
94
|
+
},
|
|
95
|
+
DEFAULT: {
|
|
96
|
+
code: '\x1b[94m',
|
|
97
|
+
},
|
|
98
|
+
RESET: {
|
|
99
|
+
code: '\x1b[0m',
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### _text_color_: `string`
|
|
105
|
+
|
|
106
|
+
Specify your own ANSI color code for console output text.
|
|
107
|
+
|
|
108
|
+
If [colors](#colors-boolean) is `false`, this option is ignored.
|
|
109
|
+
|
|
110
|
+
### _level_: `number`
|
|
111
|
+
|
|
112
|
+
One of:
|
|
113
|
+
|
|
114
|
+
- `0`: Allows [ `DEBUG`, `SUCCESS`, `WARNING`, `ERROR` ]
|
|
115
|
+
- `1`: Allows [ `WARNING`, `ERROR` ]
|
|
116
|
+
- `2`: Allows [ `ERROR` ]
|
|
117
|
+
|
|
118
|
+
## Types
|
|
119
|
+
|
|
120
|
+
The logger supports four types of output:
|
|
121
|
+
|
|
122
|
+
- **DEBUG**;
|
|
123
|
+
- **SUCCESS**;
|
|
124
|
+
- **WARNING**;
|
|
125
|
+
- **ERROR**.
|
|
126
|
+
|
|
127
|
+
Each level is aliased to support multiple ways of being emitted:
|
|
128
|
+
|
|
129
|
+
- **DEBUG**:
|
|
130
|
+
- `log`;
|
|
131
|
+
- `info`;
|
|
132
|
+
- `debug`;
|
|
133
|
+
- `l`;
|
|
134
|
+
- `i`;
|
|
135
|
+
- `d`.
|
|
136
|
+
- **SUCCESS**:
|
|
137
|
+
- `success`;
|
|
138
|
+
- `s`.
|
|
139
|
+
- **WARNING**:
|
|
140
|
+
- `warning`;
|
|
141
|
+
- `warn`;
|
|
142
|
+
- `w`.
|
|
143
|
+
- **ERROR**:
|
|
144
|
+
- `error`;
|
|
145
|
+
- `err`;
|
|
146
|
+
- `e`.
|
|
147
|
+
|
|
148
|
+
This means that all of this is game:
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
logger.log('"log" emits DEBUG')
|
|
152
|
+
logger.info('"info" emits DEBUG')
|
|
153
|
+
logger.debug('"debug" emits DEBUG')
|
|
154
|
+
logger.l('"l" emits DEBUG')
|
|
155
|
+
logger.i('"i" emits DEBUG')
|
|
156
|
+
logger.d('"d" emits DEBUG')
|
|
157
|
+
logger.success('"success" emits SUCESS')
|
|
158
|
+
logger.s('"s" emits SUCESS')
|
|
159
|
+
logger.warning('"warning" emits WARNING')
|
|
160
|
+
logger.warn('"warn" emits WARNING')
|
|
161
|
+
logger.w('"w" emits WARNING')
|
|
162
|
+
logger.error('"error" emits ERROR')
|
|
163
|
+
logger.err('"err" emits ERROR')
|
|
164
|
+
logger.e('"e" emits ERROR')
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Examples
|
|
168
|
+
|
|
169
|
+
### Basic
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
import Logger from '@leostacowski/pkgs/logger'
|
|
173
|
+
|
|
174
|
+
const logger = Logger()
|
|
175
|
+
|
|
176
|
+
logger.log('Hello World!')
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Outputs:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
> [2026-11-07T04:30:28.965Z] DEBUG:
|
|
183
|
+
Hello World!
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Prefix
|
|
187
|
+
|
|
188
|
+
```js
|
|
189
|
+
import Logger from '@leostacowski/pkgs/logger'
|
|
190
|
+
|
|
191
|
+
const logger = Logger('Hello')
|
|
192
|
+
|
|
193
|
+
logger.warn('World!')
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Outputs:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
> [2026-11-07T05:23:15.708Z] WARNING Hello:
|
|
200
|
+
World!
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Same Line
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
import Logger from '@leostacowski/pkgs/logger'
|
|
207
|
+
|
|
208
|
+
const logger = Logger({
|
|
209
|
+
group: false,
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
logger.info('Hello World!')
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Outputs:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
> [2026-11-07T05:25:23.193Z] DEBUG: Hello World!
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Level Filtering
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
import Logger from '@leostacowski/pkgs/logger'
|
|
225
|
+
|
|
226
|
+
const logger = Logger({
|
|
227
|
+
level: 2,
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
logger.log('0')
|
|
231
|
+
logger.warn('1')
|
|
232
|
+
logger.error('2')
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Outputs:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
> [2026-11-07T05:30:44.055Z] ERROR:
|
|
239
|
+
2
|
|
240
|
+
```
|
package/modules/logger/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leostacowski/pkgs",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Centralized package of reusable
|
|
5
|
-
"homepage": "https://
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Centralized package of reusable JavaScript tools.",
|
|
5
|
+
"homepage": "https://www.npmjs.com/package/@leostacowski/pkgs",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"nodejs",
|
|
8
|
+
"javascript",
|
|
9
|
+
"npm"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=22.12.0"
|
|
13
|
+
},
|
|
6
14
|
"bugs": {
|
|
7
15
|
"url": "https://github.com/leostacowski/pkgs/issues"
|
|
8
16
|
},
|