@vidavidorra/bunyan-pretty-stream 3.0.17 → 4.0.0-beta.2

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.
Files changed (51) hide show
  1. package/LICENSE.md +70 -70
  2. package/dist/bunyan/core-fields.d.ts +6 -0
  3. package/dist/bunyan/core-fields.js +16 -0
  4. package/dist/bunyan/from-json-string.d.ts +3 -0
  5. package/dist/bunyan/from-json-string.js +17 -0
  6. package/dist/bunyan/index.d.ts +4 -0
  7. package/dist/bunyan/index.js +4 -0
  8. package/dist/bunyan/is-record.d.ts +3 -0
  9. package/dist/bunyan/is-record.js +17 -0
  10. package/dist/bunyan/record.d.ts +16 -0
  11. package/dist/bunyan/record.js +2 -0
  12. package/dist/bunyan-pretty-stream.d.ts +11 -0
  13. package/dist/bunyan-pretty-stream.js +25 -0
  14. package/dist/formatter/extra.d.ts +11 -0
  15. package/dist/formatter/extra.js +33 -0
  16. package/dist/formatter/extras.d.ts +7 -0
  17. package/dist/formatter/extras.js +18 -0
  18. package/dist/formatter/formatter.d.ts +25 -0
  19. package/dist/formatter/formatter.js +116 -0
  20. package/dist/formatter/index.d.ts +1 -0
  21. package/dist/formatter/index.js +2 -0
  22. package/dist/formatter/time.d.ts +11 -0
  23. package/dist/formatter/time.js +68 -0
  24. package/dist/helpers/normalise-path.d.ts +2 -0
  25. package/dist/helpers/normalise-path.js +9 -0
  26. package/dist/index.d.ts +3 -0
  27. package/dist/index.js +2 -0
  28. package/dist/{src/logger.d.ts → logger.d.ts} +2 -2
  29. package/dist/logger.js +2 -0
  30. package/dist/options.d.ts +332 -0
  31. package/dist/options.js +109 -0
  32. package/dist/parser/extras.d.ts +13 -0
  33. package/dist/parser/extras.js +47 -0
  34. package/dist/parser/parser.d.ts +22 -0
  35. package/dist/parser/parser.js +53 -0
  36. package/package.json +192 -45
  37. package/dist/src/bunyan-pretty-stream.d.ts +0 -10
  38. package/dist/src/bunyan-pretty-stream.js +0 -32
  39. package/dist/src/bunyan-record.d.ts +0 -19
  40. package/dist/src/bunyan-record.js +0 -55
  41. package/dist/src/formatter/extras.d.ts +0 -34
  42. package/dist/src/formatter/extras.js +0 -94
  43. package/dist/src/formatter/formatter.d.ts +0 -34
  44. package/dist/src/formatter/formatter.js +0 -200
  45. package/dist/src/formatter/index.d.ts +0 -2
  46. package/dist/src/formatter/index.js +0 -5
  47. package/dist/src/index.d.ts +0 -3
  48. package/dist/src/index.js +0 -5
  49. package/dist/src/logger.js +0 -2
  50. package/dist/src/options.d.ts +0 -151
  51. package/dist/src/options.js +0 -68
package/LICENSE.md CHANGED
@@ -217,23 +217,23 @@ produce it from the Program, in the form of source code under the
217
217
  terms of section 4, provided that you also meet all of these
218
218
  conditions:
219
219
 
220
- - a) The work must carry prominent notices stating that you modified
221
- it, and giving a relevant date.
222
- - b) The work must carry prominent notices stating that it is
223
- released under this License and any conditions added under
224
- section 7. This requirement modifies the requirement in section 4
225
- to "keep intact all notices".
226
- - c) You must license the entire work, as a whole, under this
227
- License to anyone who comes into possession of a copy. This
228
- License will therefore apply, along with any applicable section 7
229
- additional terms, to the whole of the work, and all its parts,
230
- regardless of how they are packaged. This License gives no
231
- permission to license the work in any other way, but it does not
232
- invalidate such permission if you have separately received it.
233
- - d) If the work has interactive user interfaces, each must display
234
- Appropriate Legal Notices; however, if the Program has interactive
235
- interfaces that do not display Appropriate Legal Notices, your
236
- work need not make them do so.
220
+ - a) The work must carry prominent notices stating that you modified
221
+ it, and giving a relevant date.
222
+ - b) The work must carry prominent notices stating that it is
223
+ released under this License and any conditions added under
224
+ section 7. This requirement modifies the requirement in section 4
225
+ to "keep intact all notices".
226
+ - c) You must license the entire work, as a whole, under this
227
+ License to anyone who comes into possession of a copy. This
228
+ License will therefore apply, along with any applicable section 7
229
+ additional terms, to the whole of the work, and all its parts,
230
+ regardless of how they are packaged. This License gives no
231
+ permission to license the work in any other way, but it does not
232
+ invalidate such permission if you have separately received it.
233
+ - d) If the work has interactive user interfaces, each must display
234
+ Appropriate Legal Notices; however, if the Program has interactive
235
+ interfaces that do not display Appropriate Legal Notices, your
236
+ work need not make them do so.
237
237
 
238
238
  A compilation of a covered work with other separate and independent
239
239
  works, which are not by their nature extensions of the covered work,
@@ -252,42 +252,42 @@ sections 4 and 5, provided that you also convey the machine-readable
252
252
  Corresponding Source under the terms of this License, in one of these
253
253
  ways:
254
254
 
255
- - a) Convey the object code in, or embodied in, a physical product
256
- (including a physical distribution medium), accompanied by the
257
- Corresponding Source fixed on a durable physical medium
258
- customarily used for software interchange.
259
- - b) Convey the object code in, or embodied in, a physical product
260
- (including a physical distribution medium), accompanied by a
261
- written offer, valid for at least three years and valid for as
262
- long as you offer spare parts or customer support for that product
263
- model, to give anyone who possesses the object code either (1) a
264
- copy of the Corresponding Source for all the software in the
265
- product that is covered by this License, on a durable physical
266
- medium customarily used for software interchange, for a price no
267
- more than your reasonable cost of physically performing this
268
- conveying of source, or (2) access to copy the Corresponding
269
- Source from a network server at no charge.
270
- - c) Convey individual copies of the object code with a copy of the
271
- written offer to provide the Corresponding Source. This
272
- alternative is allowed only occasionally and noncommercially, and
273
- only if you received the object code with such an offer, in accord
274
- with subsection 6b.
275
- - d) Convey the object code by offering access from a designated
276
- place (gratis or for a charge), and offer equivalent access to the
277
- Corresponding Source in the same way through the same place at no
278
- further charge. You need not require recipients to copy the
279
- Corresponding Source along with the object code. If the place to
280
- copy the object code is a network server, the Corresponding Source
281
- may be on a different server (operated by you or a third party)
282
- that supports equivalent copying facilities, provided you maintain
283
- clear directions next to the object code saying where to find the
284
- Corresponding Source. Regardless of what server hosts the
285
- Corresponding Source, you remain obligated to ensure that it is
286
- available for as long as needed to satisfy these requirements.
287
- - e) Convey the object code using peer-to-peer transmission,
288
- provided you inform other peers where the object code and
289
- Corresponding Source of the work are being offered to the general
290
- public at no charge under subsection 6d.
255
+ - a) Convey the object code in, or embodied in, a physical product
256
+ (including a physical distribution medium), accompanied by the
257
+ Corresponding Source fixed on a durable physical medium
258
+ customarily used for software interchange.
259
+ - b) Convey the object code in, or embodied in, a physical product
260
+ (including a physical distribution medium), accompanied by a
261
+ written offer, valid for at least three years and valid for as
262
+ long as you offer spare parts or customer support for that product
263
+ model, to give anyone who possesses the object code either (1) a
264
+ copy of the Corresponding Source for all the software in the
265
+ product that is covered by this License, on a durable physical
266
+ medium customarily used for software interchange, for a price no
267
+ more than your reasonable cost of physically performing this
268
+ conveying of source, or (2) access to copy the Corresponding
269
+ Source from a network server at no charge.
270
+ - c) Convey individual copies of the object code with a copy of the
271
+ written offer to provide the Corresponding Source. This
272
+ alternative is allowed only occasionally and noncommercially, and
273
+ only if you received the object code with such an offer, in accord
274
+ with subsection 6b.
275
+ - d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+ - e) Convey the object code using peer-to-peer transmission,
288
+ provided you inform other peers where the object code and
289
+ Corresponding Source of the work are being offered to the general
290
+ public at no charge under subsection 6d.
291
291
 
292
292
  A separable portion of the object code, whose source code is excluded
293
293
  from the Corresponding Source as a System Library, need not be
@@ -363,23 +363,23 @@ Notwithstanding any other provision of this License, for material you
363
363
  add to a covered work, you may (if authorized by the copyright holders
364
364
  of that material) supplement the terms of this License with terms:
365
365
 
366
- - a) Disclaiming warranty or limiting liability differently from the
367
- terms of sections 15 and 16 of this License; or
368
- - b) Requiring preservation of specified reasonable legal notices or
369
- author attributions in that material or in the Appropriate Legal
370
- Notices displayed by works containing it; or
371
- - c) Prohibiting misrepresentation of the origin of that material,
372
- or requiring that modified versions of such material be marked in
373
- reasonable ways as different from the original version; or
374
- - d) Limiting the use for publicity purposes of names of licensors
375
- or authors of the material; or
376
- - e) Declining to grant rights under trademark law for use of some
377
- trade names, trademarks, or service marks; or
378
- - f) Requiring indemnification of licensors and authors of that
379
- material by anyone who conveys the material (or modified versions
380
- of it) with contractual assumptions of liability to the recipient,
381
- for any liability that these contractual assumptions directly
382
- impose on those licensors and authors.
366
+ - a) Disclaiming warranty or limiting liability differently from the
367
+ terms of sections 15 and 16 of this License; or
368
+ - b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+ - c) Prohibiting misrepresentation of the origin of that material,
372
+ or requiring that modified versions of such material be marked in
373
+ reasonable ways as different from the original version; or
374
+ - d) Limiting the use for publicity purposes of names of licensors
375
+ or authors of the material; or
376
+ - e) Declining to grant rights under trademark law for use of some
377
+ trade names, trademarks, or service marks; or
378
+ - f) Requiring indemnification of licensors and authors of that
379
+ material by anyone who conveys the material (or modified versions
380
+ of it) with contractual assumptions of liability to the recipient,
381
+ for any liability that these contractual assumptions directly
382
+ impose on those licensors and authors.
383
383
 
384
384
  All other non-permissive additional terms are considered "further
385
385
  restrictions" within the meaning of section 10. If the Program as you
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Bunyan core fields as defined by the [Core fields](
3
+ * https://github.com/trentm/node-bunyan/tree/1.8.15#core-fields) documentation.
4
+ */
5
+ declare const coreFields: readonly string[];
6
+ export default coreFields;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Bunyan core fields as defined by the [Core fields](
3
+ * https://github.com/trentm/node-bunyan/tree/1.8.15#core-fields) documentation.
4
+ */
5
+ const coreFields = [
6
+ 'v',
7
+ 'level',
8
+ 'name',
9
+ 'hostname',
10
+ 'pid',
11
+ 'time',
12
+ 'msg',
13
+ 'src',
14
+ ];
15
+ export default coreFields;
16
+ //# sourceMappingURL=core-fields.js.map
@@ -0,0 +1,3 @@
1
+ import type BunyanRecord from './record.js';
2
+ declare function fromJsonString(json: string): BunyanRecord;
3
+ export default fromJsonString;
@@ -0,0 +1,17 @@
1
+ import isBunyanRecord from './is-record.js';
2
+ function fromJsonString(json) {
3
+ const record = JSON.parse(json, (key, value) => {
4
+ if (key === 'time' &&
5
+ typeof value === 'string' &&
6
+ /^((\+-)\d{2})?\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(value)) {
7
+ return new Date(value);
8
+ }
9
+ return value;
10
+ });
11
+ if (!isBunyanRecord(record)) {
12
+ throw new Error('string MUST be parsable to a valid Bunyan record');
13
+ }
14
+ return record;
15
+ }
16
+ export default fromJsonString;
17
+ //# sourceMappingURL=from-json-string.js.map
@@ -0,0 +1,4 @@
1
+ export { default as isBunyanRecord } from './is-record.js';
2
+ export { type default as BunyanRecord } from './record.js';
3
+ export { default as coreFields } from './core-fields.js';
4
+ export { default as fromJsonString } from './from-json-string.js';
@@ -0,0 +1,4 @@
1
+ export { default as isBunyanRecord } from './is-record.js';
2
+ export { default as coreFields } from './core-fields.js';
3
+ export { default as fromJsonString } from './from-json-string.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import type BunyanRecord from './record.js';
2
+ declare function isBunyanRecord(value: unknown): value is BunyanRecord;
3
+ export default isBunyanRecord;
@@ -0,0 +1,17 @@
1
+ import is from '@sindresorhus/is';
2
+ function isBunyanRecord(value) {
3
+ return (is.plainObject(value) &&
4
+ is.number(value.v) &&
5
+ is.number(value.level) &&
6
+ is.string(value.name) &&
7
+ is.string(value.hostname) &&
8
+ is.number(value.pid) &&
9
+ is.date(value.time) &&
10
+ is.string(value.msg) &&
11
+ (is.undefined(value.src) ||
12
+ (is.plainObject(value.src) &&
13
+ is.number(value.src.line) &&
14
+ (is.undefined(value.src.func) || is.string(value.src.func)))));
15
+ }
16
+ export default isBunyanRecord;
17
+ //# sourceMappingURL=is-record.js.map
@@ -0,0 +1,16 @@
1
+ type BunyanRecord = {
2
+ [key: string]: unknown;
3
+ v: number;
4
+ level: number;
5
+ name: string;
6
+ hostname: string;
7
+ pid: number;
8
+ time: Date;
9
+ msg: string;
10
+ src?: {
11
+ file: string;
12
+ line: number;
13
+ func?: string;
14
+ };
15
+ };
16
+ export default BunyanRecord;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=record.js.map
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ import type { TransformCallback } from 'node:stream';
4
+ import { Transform } from 'node:stream';
5
+ import type { PublicOptions as Options } from './options.js';
6
+ declare class PrettyStream extends Transform {
7
+ private readonly _formatter;
8
+ constructor(options?: Options);
9
+ _transform(chunk: any, _: BufferEncoding, done: TransformCallback): void;
10
+ }
11
+ export { PrettyStream };
@@ -0,0 +1,25 @@
1
+ import { Transform } from 'node:stream';
2
+ import { fromJsonString, isBunyanRecord } from './bunyan/index.js';
3
+ import { Formatter } from './formatter/index.js';
4
+ class PrettyStream extends Transform {
5
+ _formatter;
6
+ constructor(options = {}) {
7
+ super({ objectMode: true });
8
+ this._formatter = new Formatter(options);
9
+ }
10
+ _transform(chunk, _, done) {
11
+ if (typeof chunk === 'string') {
12
+ this.push(this._formatter.format(fromJsonString(chunk)));
13
+ done();
14
+ }
15
+ else if (isBunyanRecord(chunk)) {
16
+ this.push(this._formatter.format(chunk));
17
+ done();
18
+ }
19
+ else {
20
+ done(new Error('data MUST be a valid bunyan record'));
21
+ }
22
+ }
23
+ }
24
+ export { PrettyStream };
25
+ //# sourceMappingURL=bunyan-pretty-stream.js.map
@@ -0,0 +1,11 @@
1
+ declare class Extra {
2
+ private readonly _keyValueSeparator;
3
+ constructor(keyValueSeparator: string);
4
+ format(key: string, value: unknown): {
5
+ formatted: string;
6
+ key: string;
7
+ value: string;
8
+ } | null;
9
+ private stringify;
10
+ }
11
+ export default Extra;
@@ -0,0 +1,33 @@
1
+ class Extra {
2
+ _keyValueSeparator;
3
+ constructor(keyValueSeparator) {
4
+ this._keyValueSeparator = keyValueSeparator;
5
+ }
6
+ format(key, value) {
7
+ const stringifiedKey = this.stringify(key);
8
+ const stringifiedValue = this.stringify(value);
9
+ if (stringifiedKey === undefined || stringifiedValue === undefined) {
10
+ return null;
11
+ }
12
+ return {
13
+ formatted: [
14
+ stringifiedKey,
15
+ this._keyValueSeparator,
16
+ stringifiedValue,
17
+ ].join(''),
18
+ key: stringifiedKey,
19
+ value: stringifiedValue,
20
+ };
21
+ }
22
+ stringify(value) {
23
+ if (typeof value === 'string' &&
24
+ value.length > 0 &&
25
+ !/\s|"/.test(value) &&
26
+ !value.includes(this._keyValueSeparator)) {
27
+ return value;
28
+ }
29
+ return JSON.stringify(value);
30
+ }
31
+ }
32
+ export default Extra;
33
+ //# sourceMappingURL=extra.js.map
@@ -0,0 +1,7 @@
1
+ import type { Options } from '../options.js';
2
+ declare class Extras {
3
+ private readonly _formatCharacters;
4
+ constructor(formatCharacters: Options['extras']['formatCharacters']);
5
+ format(extras: string[]): string;
6
+ }
7
+ export default Extras;
@@ -0,0 +1,18 @@
1
+ class Extras {
2
+ _formatCharacters;
3
+ constructor(formatCharacters) {
4
+ this._formatCharacters = formatCharacters;
5
+ }
6
+ format(extras) {
7
+ if (extras.length === 0) {
8
+ return '';
9
+ }
10
+ return [
11
+ this._formatCharacters.start,
12
+ extras.join(this._formatCharacters.separator),
13
+ this._formatCharacters.end,
14
+ ].join('');
15
+ }
16
+ }
17
+ export default Extras;
18
+ //# sourceMappingURL=extras.js.map
@@ -0,0 +1,25 @@
1
+ import type { ChalkInstance as Chalk } from 'chalk';
2
+ import type BunyanRecord from '../bunyan/record.js';
3
+ import type { PublicOptions } from '../options.js';
4
+ import type { ParsedRecord } from '../parser/parser.js';
5
+ declare class Formatter {
6
+ private readonly _options;
7
+ private readonly _parser;
8
+ private readonly _extras;
9
+ private readonly _time;
10
+ private readonly _newLineRegex;
11
+ private readonly _levels;
12
+ constructor(options: PublicOptions);
13
+ format(record: BunyanRecord): string;
14
+ formatTime(time: ParsedRecord['time']): string;
15
+ formatLevel(level: ParsedRecord['level']): string;
16
+ formatName(name: ParsedRecord['name']): string;
17
+ formatPid(pid: ParsedRecord['pid']): string;
18
+ formatHostname(hostname: ParsedRecord['hostname']): string;
19
+ formatSource(source: ParsedRecord['source'], colour: Chalk): string;
20
+ formatMessage(message: ParsedRecord['message'], colour: Chalk): string;
21
+ formatExtras(extras: string[], colour: Chalk): string;
22
+ formatDetails(message: ParsedRecord['message'], details: ParsedRecord['details']): string;
23
+ private indent;
24
+ }
25
+ export { Formatter };
@@ -0,0 +1,116 @@
1
+ import { relative } from 'node:path';
2
+ import bunyan from 'bunyan';
3
+ import chalk from 'chalk';
4
+ import stringify from 'json-stringify-pretty-compact';
5
+ import { schema } from '../options.js';
6
+ import Parser from '../parser/parser.js';
7
+ import normalisePath from '../helpers/normalise-path.js';
8
+ import Extras from './extras.js';
9
+ import Time from './time.js';
10
+ class Formatter {
11
+ _options;
12
+ _parser;
13
+ _extras;
14
+ _time;
15
+ _newLineRegex;
16
+ _levels;
17
+ constructor(options) {
18
+ this._options = schema.parse(options);
19
+ this._parser = new Parser({
20
+ show: this._options.show.extras,
21
+ extras: this._options.extras,
22
+ });
23
+ this._extras = new Extras(this._options.extras.formatCharacters);
24
+ this._time = new Time(this._options.time);
25
+ this._newLineRegex = /\r\n|\r|\n/;
26
+ this._levels = {
27
+ [bunyan.levelFromName.trace]: chalk.gray('TRACE'),
28
+ [bunyan.levelFromName.debug]: chalk.blue('DEBUG'),
29
+ [bunyan.levelFromName.info]: chalk.green(' INFO'),
30
+ [bunyan.levelFromName.warn]: chalk.magenta(' WARN'),
31
+ [bunyan.levelFromName.error]: chalk.red('ERROR'),
32
+ [bunyan.levelFromName.fatal]: chalk.bgRed('FATAL'),
33
+ };
34
+ }
35
+ format(record) {
36
+ const parsedRecord = this._parser.parse(structuredClone(record));
37
+ return [
38
+ this.formatTime(parsedRecord.time),
39
+ this.formatLevel(parsedRecord.level),
40
+ ':',
41
+ this.formatName(parsedRecord.name),
42
+ this.formatPid(parsedRecord.pid),
43
+ this.formatHostname(parsedRecord.hostname),
44
+ this.formatSource(parsedRecord.source, chalk.green),
45
+ this.formatMessage(parsedRecord.message, chalk.blue),
46
+ this.formatExtras(parsedRecord.extras, chalk.red),
47
+ this._options.newLineCharacter,
48
+ this.formatDetails(parsedRecord.message, parsedRecord.details),
49
+ ].join('');
50
+ }
51
+ formatTime(time) {
52
+ return this._options.show.time ? `[${this._time.format(time)}]` : '';
53
+ }
54
+ formatLevel(level) {
55
+ const prefix = this._options.show.time ? ' ' : '';
56
+ return `${prefix}${this._levels[level]}`;
57
+ }
58
+ formatName(name) {
59
+ return this._options.show.name ? ` ${name}` : '';
60
+ }
61
+ formatPid(pid) {
62
+ return this._options.show.pid
63
+ ? `${this._options.show.name ? '/' : ' '}${pid}`
64
+ : '';
65
+ }
66
+ formatHostname(hostname) {
67
+ if (!this._options.show.hostname) {
68
+ return '';
69
+ }
70
+ return [
71
+ ' ',
72
+ this._options.show.name || this._options.show.pid ? 'on ' : '',
73
+ hostname,
74
+ ].join('');
75
+ }
76
+ formatSource(source, colour) {
77
+ if (!this._options.show.source || source === undefined) {
78
+ return '';
79
+ }
80
+ const file = relative(this._options.basePath, normalisePath(source.file));
81
+ const formattedSource = [
82
+ ` (${file}:${source.line}`,
83
+ source.func === undefined ? '' : ` in ${source.func}`,
84
+ ')',
85
+ ].join('');
86
+ return colour(formattedSource);
87
+ }
88
+ formatMessage(message, colour) {
89
+ return this._newLineRegex.test(message) ? '' : colour(` ${message}`);
90
+ }
91
+ formatExtras(extras, colour) {
92
+ const formattedExtras = this._extras.format(extras);
93
+ return formattedExtras.length === 0 ? '' : colour(` ${formattedExtras}`);
94
+ }
95
+ formatDetails(message, details) {
96
+ const formatted = [];
97
+ if (this._newLineRegex.test(message)) {
98
+ formatted.push(chalk.blue(this.indent(message)));
99
+ }
100
+ formatted.push(...Object.entries(details).map(([key, value]) => chalk.cyan(this.indent(`${key}: ${stringify(value, {
101
+ indent: this._options.indent.json,
102
+ maxLength: 80,
103
+ })}`))));
104
+ const suffix = formatted.length > 0 ? this._options.newLineCharacter : '';
105
+ return `${formatted.join(this._options.newLineCharacter)}${suffix}`;
106
+ }
107
+ indent(input) {
108
+ const indentation = ' '.repeat(this._options.indent.details);
109
+ const formatted = input
110
+ .split(this._newLineRegex)
111
+ .join(`${this._options.newLineCharacter}${indentation}`);
112
+ return `${indentation}${formatted}`;
113
+ }
114
+ }
115
+ export { Formatter };
116
+ //# sourceMappingURL=formatter.js.map
@@ -0,0 +1 @@
1
+ export { Formatter } from './formatter.js';
@@ -0,0 +1,2 @@
1
+ export { Formatter } from './formatter.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ import type { Options } from '../options.js';
2
+ declare class Formatter {
3
+ private readonly _options;
4
+ private readonly _iso8601Presets;
5
+ constructor(options: Options['time']);
6
+ format(date: Date): string;
7
+ private isIso8601;
8
+ private toIso8601;
9
+ private toLocaleString;
10
+ }
11
+ export default Formatter;
@@ -0,0 +1,68 @@
1
+ import { DateTime } from 'luxon';
2
+ class Formatter {
3
+ _options;
4
+ _iso8601Presets = [
5
+ 'TIME_ISO_8601',
6
+ 'TIME_ISO_8601_OFFSET',
7
+ 'DATETIME_ISO_8601_OFFSET',
8
+ 'DATETIME_ISO_8601',
9
+ ];
10
+ constructor(options) {
11
+ this._options = options;
12
+ }
13
+ format(date) {
14
+ const dateTime = this._options.utc
15
+ ? DateTime.fromJSDate(date).toUTC()
16
+ : DateTime.fromJSDate(date);
17
+ if (this._options.format !== undefined) {
18
+ return dateTime.toFormat(this._options.format);
19
+ }
20
+ if (this.isIso8601(this._options.preset)) {
21
+ return this.toIso8601(dateTime, this._options.preset);
22
+ }
23
+ return this.toLocaleString(dateTime);
24
+ }
25
+ isIso8601(preset) {
26
+ return this._iso8601Presets.includes(preset);
27
+ }
28
+ toIso8601(dateTime, preset) {
29
+ const includeOffset = preset === 'TIME_ISO_8601_OFFSET' ||
30
+ preset === 'DATETIME_ISO_8601_OFFSET';
31
+ if (preset === 'TIME_ISO_8601_OFFSET' || preset === 'TIME_ISO_8601') {
32
+ return dateTime.toISOTime({ includeOffset });
33
+ }
34
+ return dateTime.toISO({ includeOffset });
35
+ }
36
+ toLocaleString(dateTime) {
37
+ const presetToFormatOptions = new Map([
38
+ ['DATE_SHORT', DateTime.DATE_SHORT],
39
+ ['DATE_MED', DateTime.DATE_MED],
40
+ ['DATE_MED_WITH_WEEKDAY', DateTime.DATE_MED_WITH_WEEKDAY],
41
+ ['DATE_FULL', DateTime.DATE_FULL],
42
+ ['DATE_HUGE', DateTime.DATE_HUGE],
43
+ ['TIME_SIMPLE', DateTime.TIME_SIMPLE],
44
+ ['TIME_WITH_SECONDS', DateTime.TIME_WITH_SECONDS],
45
+ ['TIME_WITH_SHORT_OFFSET', DateTime.TIME_WITH_SHORT_OFFSET],
46
+ ['TIME_WITH_LONG_OFFSET', DateTime.TIME_WITH_LONG_OFFSET],
47
+ ['TIME_24_SIMPLE', DateTime.TIME_24_SIMPLE],
48
+ ['TIME_24_WITH_SECONDS', DateTime.TIME_24_WITH_SECONDS],
49
+ ['TIME_24_WITH_SHORT_OFFSET', DateTime.TIME_24_WITH_SHORT_OFFSET],
50
+ ['TIME_24_WITH_LONG_OFFSET', DateTime.TIME_24_WITH_LONG_OFFSET],
51
+ ['DATETIME_SHORT', DateTime.DATETIME_SHORT],
52
+ ['DATETIME_MED', DateTime.DATETIME_MED],
53
+ ['DATETIME_FULL', DateTime.DATETIME_FULL],
54
+ ['DATETIME_HUGE', DateTime.DATETIME_HUGE],
55
+ ['DATETIME_SHORT_WITH_SECONDS', DateTime.DATETIME_SHORT_WITH_SECONDS],
56
+ ['DATETIME_MED_WITH_SECONDS', DateTime.DATETIME_MED_WITH_SECONDS],
57
+ ['DATETIME_FULL_WITH_SECONDS', DateTime.DATETIME_FULL_WITH_SECONDS],
58
+ ['DATETIME_HUGE_WITH_SECONDS', DateTime.DATETIME_HUGE_WITH_SECONDS],
59
+ ]);
60
+ const formatOptions = presetToFormatOptions.get(this._options.preset);
61
+ if (formatOptions === undefined) {
62
+ throw new Error('unknown Luxon preset');
63
+ }
64
+ return dateTime.toLocaleString(formatOptions);
65
+ }
66
+ }
67
+ export default Formatter;
68
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1,2 @@
1
+ declare function normalisePath(pathOrFileUrl: string): string;
2
+ export default normalisePath;
@@ -0,0 +1,9 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { normalize } from 'node:path';
3
+ function normalisePath(pathOrFileUrl) {
4
+ return normalize(pathOrFileUrl.startsWith('file://')
5
+ ? fileURLToPath(pathOrFileUrl)
6
+ : pathOrFileUrl);
7
+ }
8
+ export default normalisePath;
9
+ //# sourceMappingURL=normalise-path.js.map
@@ -0,0 +1,3 @@
1
+ export { type Logger } from './logger.js';
2
+ export { PrettyStream } from './bunyan-pretty-stream.js';
3
+ export type { PublicOptions as Options } from './options.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { PrettyStream } from './bunyan-pretty-stream.js';
2
+ //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
- import bunyan from 'bunyan';
1
+ import type bunyan from 'bunyan';
2
2
  type Logger = Pick<ReturnType<typeof bunyan.createLogger>, 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'>;
3
- export { Logger };
3
+ export type { Logger };
package/dist/logger.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=logger.js.map