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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017 Joris Röling
3
+ Copyright (c) 2017-2026 Joris Röling
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,69 +1,163 @@
1
- yves
2
- ====
1
+ # yves
3
2
 
4
- a customizable value inspector for Node.js inspired by [eyes](https://github.com/cloudhead/eyes.js/)
3
+ A customizable value inspector for Node.js, inspired by [eyes](https://github.com/cloudhead/eyes.js/).
5
4
 
6
- synopsis
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
- I was tired of looking at cluttered output in the console -- something needed to be done,
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
- *yves* also deals with circular objects in an intelligent way, and can pretty-print object literals.
9
+ ```
10
+ npm install yves
11
+ ```
14
12
 
15
- usage
16
- -----
13
+ Requires Node.js >= 18.
17
14
 
18
- var inspect = require('yves').inspector({styles: {all: 'magenta'}});
15
+ ## Usage
19
16
 
20
- inspect(something); // inspect with the settings passed to `inspector`
17
+ ```js
18
+ import yves from 'yves'
21
19
 
22
- or
20
+ yves.inspect(something)
21
+ ```
23
22
 
24
- var yves = require('yves');
23
+ With a label:
25
24
 
26
- yves.inspect(something); // inspect with the default settings
25
+ ```js
26
+ yves.inspect(something, 'my value')
27
+ ```
27
28
 
28
- you can pass a _label_ to `inspect()`, to keep track of your inspections:
29
+ With a custom inspector:
29
30
 
30
- yves.inspect(something, "a random value");
31
+ ```js
32
+ const inspect = yves.inspector({ styles: { all: 'magenta' } })
31
33
 
32
- If you want to return the output of yves without printing it, you can set it up this way:
34
+ inspect(something)
35
+ ```
33
36
 
34
- var inspect = require('yves').inspector({ stream: null });
37
+ To return the string instead of printing to stdout:
35
38
 
36
- sys.puts(inspect({ something: 42 }));
39
+ ```js
40
+ const inspect = yves.inspector({ stream: null })
37
41
 
38
- customization
39
- -------------
42
+ console.log(inspect({ something: 42 }))
43
+ ```
40
44
 
41
- These are the default styles and settings used by _yves_.
45
+ ## Options
42
46
 
43
- styles: { // Styles applied to stdout
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
- You can overwrite them with your own, by passing a similar object to `inspector()` or `inspect()`.
49
+ ### Styles
61
50
 
62
- var inspect = require('yves').inspector({
63
- styles: {
64
- all: 'magenta',
65
- special: 'bold'
66
- },
67
- maxLength: 512
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