yves 1.0.99 → 1.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/LICENSE +1 -1
- package/README.md +142 -48
- package/dist/yves.js +2722 -14483
- package/lib/yves.mjs +385 -905
- package/package.json +14 -17
- package/.eslintignore +0 -3
- package/.eslintrc.cjs +0 -48
- package/.tm_properties +0 -2
- package/Makefile +0 -4
- package/test/yves-test.js +0 -217
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,69 +1,163 @@
|
|
|
1
|
-
yves
|
|
2
|
-
====
|
|
1
|
+
# yves
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
A customizable value inspector for Node.js, inspired by [eyes](https://github.com/cloudhead/eyes.js/).
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
--------
|
|
5
|
+
Handles circular objects, pretty-prints object literals, and supports ANSI color output, HTML output, and [debug](https://github.com/visionmedia/debug) integration.
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
`sys.inspect()` didn't display regexps correctly, and was too verbose, and I had an hour or two to spare.
|
|
11
|
-
So I decided to have some fun. _yves_ were born.
|
|
7
|
+
## Install
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
```
|
|
10
|
+
npm install yves
|
|
11
|
+
```
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
-----
|
|
13
|
+
Requires Node.js >= 18.
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
## Usage
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
```js
|
|
18
|
+
import yves from 'yves'
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
yves.inspect(something)
|
|
21
|
+
```
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
With a label:
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
```js
|
|
26
|
+
yves.inspect(something, 'my value')
|
|
27
|
+
```
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
With a custom inspector:
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
```js
|
|
32
|
+
const inspect = yves.inspector({ styles: { all: 'magenta' } })
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
inspect(something)
|
|
35
|
+
```
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
To return the string instead of printing to stdout:
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
```js
|
|
40
|
+
const inspect = yves.inspector({ stream: null })
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
console.log(inspect({ something: 42 }))
|
|
43
|
+
```
|
|
40
44
|
|
|
41
|
-
|
|
45
|
+
## Options
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
all: 'cyan', // Overall style applied to everything
|
|
45
|
-
label: 'underline', // Inspection labels, like 'array' in `array: [1, 2, 3]`
|
|
46
|
-
other: 'inverted', // Objects which don't have a literal representation, such as functions
|
|
47
|
-
key: 'bold', // The keys in object literals, like 'a' in `{a: 1}`
|
|
48
|
-
special: 'grey', // null, undefined...
|
|
49
|
-
string: 'green',
|
|
50
|
-
number: 'magenta',
|
|
51
|
-
bool: 'blue', // true false
|
|
52
|
-
regexp: 'green', // /\d+/
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
pretty: true, // Indent object literals
|
|
56
|
-
hideFunctions: false, // Don't output functions at all
|
|
57
|
-
stream: process.stdout, // Stream to write to, or null
|
|
58
|
-
maxLength: 2048 // Truncate output if longer
|
|
47
|
+
Pass options to `inspector()` or as the third argument to `inspect()`.
|
|
59
48
|
|
|
60
|
-
|
|
49
|
+
### Styles
|
|
61
50
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
```js
|
|
52
|
+
styles: {
|
|
53
|
+
all: 'cyan', // Overall style applied to everything
|
|
54
|
+
label: 'underline', // Inspection labels, like 'array' in `array: [1, 2, 3]`
|
|
55
|
+
other: 'inverted', // Objects without a literal representation (functions)
|
|
56
|
+
key: 'bold', // Object keys, like 'a' in `{a: 1}`
|
|
57
|
+
special: 'grey', // null, undefined
|
|
58
|
+
string: 'green',
|
|
59
|
+
number: 'magenta',
|
|
60
|
+
bool: 'blue',
|
|
61
|
+
regexp: 'green',
|
|
62
|
+
}
|
|
63
|
+
```
|
|
69
64
|
|
|
65
|
+
Available styles: `bold`, `underline`, `inverse`, `cyan`, `magenta`, `blue`, `yellow`, `green`, `red`, `grey`.
|
|
66
|
+
|
|
67
|
+
Set `styles: false` to disable all styling. Set `colors: false` to disable ANSI codes.
|
|
68
|
+
|
|
69
|
+
### Formatting
|
|
70
|
+
|
|
71
|
+
| Option | Default | Description |
|
|
72
|
+
|--------|---------|-------------|
|
|
73
|
+
| `pretty` | `true` | Indent object literals and arrays |
|
|
74
|
+
| `indent` | `4` | Spaces per indentation level |
|
|
75
|
+
| `singleLineMax` | `2` | Max keys before an object is printed multiline |
|
|
76
|
+
| `trailingComma` | `true` | Add trailing commas in multiline output |
|
|
77
|
+
| `templateStrings` | `true` | Use backtick syntax for strings containing newlines/tabs |
|
|
78
|
+
| `escape` | `true` | Escape invisible characters in strings |
|
|
79
|
+
| `json` | `false` | Use JSON-style output (double-quoted keys and strings) |
|
|
80
|
+
| `sortKeys` | `false` | Sort object keys alphabetically |
|
|
81
|
+
| `sorted` | `false` | Deep-sort the input object before inspecting |
|
|
82
|
+
|
|
83
|
+
### Truncation
|
|
84
|
+
|
|
85
|
+
| Option | Default | Description |
|
|
86
|
+
|--------|---------|-------------|
|
|
87
|
+
| `maxLength` | `-1` | Max output length in characters (`-1` for unlimited) |
|
|
88
|
+
| `maxStringLength` | - | Truncate strings beyond this length |
|
|
89
|
+
| `maxArrayLength` | - | Show at most N array elements |
|
|
90
|
+
| `maxObjectKeys` | - | Show at most N object keys |
|
|
91
|
+
|
|
92
|
+
### Filtering
|
|
93
|
+
|
|
94
|
+
| Option | Default | Description |
|
|
95
|
+
|--------|---------|-------------|
|
|
96
|
+
| `includes` | `null` | Only show keys matching these strings/regexps |
|
|
97
|
+
| `excludes` | `null` | Hide keys matching these strings/regexps |
|
|
98
|
+
| `obfuscates` | `null` | Replace values of matching keys with `<<obfuscated>>` |
|
|
99
|
+
| `hideFunctions` | `false` | Omit function-valued properties |
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
yves.inspect(obj, 'filtered', {
|
|
103
|
+
includes: ['name', /^user/],
|
|
104
|
+
obfuscates: ['password', /secret/],
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Output
|
|
109
|
+
|
|
110
|
+
| Option | Default | Description |
|
|
111
|
+
|--------|---------|-------------|
|
|
112
|
+
| `stream` | `process.stdout` | Writable stream, or `null` to return the string |
|
|
113
|
+
| `colors` | auto-detected | Enable ANSI color codes |
|
|
114
|
+
| `html` | `false` | Output HTML `<span>` tags instead of ANSI codes |
|
|
115
|
+
| `decycle` | `true` | Safely handle circular references |
|
|
116
|
+
|
|
117
|
+
## HTML output
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
const inspect = yves.inspector({ stream: null, html: true, colors: true })
|
|
121
|
+
|
|
122
|
+
const html = inspect({ hello: 'world' })
|
|
123
|
+
// Returns a <pre> block with <span> color styling
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Debug integration
|
|
127
|
+
|
|
128
|
+
yves integrates with the [debug](https://github.com/visionmedia/debug) module. Use the `%y` formatter for compact output or `%Y` for sorted, function-free output:
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
import debug from 'debug'
|
|
132
|
+
const log = debug('app')
|
|
133
|
+
|
|
134
|
+
log('user data: %y', userData)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Console hijacking
|
|
138
|
+
|
|
139
|
+
Replace `console.log` / `console.dir` etc. with yves-powered output routed through `debug`:
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
yves.console('myapp')
|
|
143
|
+
|
|
144
|
+
console.log('hello') // now outputs via debug('myapp:console:log')
|
|
145
|
+
console.dir({ a: 1 }) // pretty-printed via yves
|
|
146
|
+
|
|
147
|
+
yves.console_unset() // restore original console
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## API
|
|
151
|
+
|
|
152
|
+
- **`yves.inspect(obj, label?, options?)`** -- inspect and print to stream
|
|
153
|
+
- **`yves.inspector(options?)`** -- returns a reusable inspect function
|
|
154
|
+
- **`yves.options(opts)`** -- update global defaults
|
|
155
|
+
- **`yves.stylize(str, style, options)`** -- apply a single ANSI/HTML style
|
|
156
|
+
- **`yves.typeOf(value)`** -- enhanced `typeof` (distinguishes array, regexp, date, buffer, null, bigint)
|
|
157
|
+
- **`yves.debugger(namespace)`** -- create a [debug](https://github.com/visionmedia/debug) logger
|
|
158
|
+
- **`yves.console(namespace?)`** -- hijack console with debug-powered output
|
|
159
|
+
- **`yves.console_unset()`** -- restore original console methods
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
MIT
|