@reliverse/relinka 1.1.6 → 1.1.8

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 (121) hide show
  1. package/dist-npm/components/anykey/index.js +57 -77
  2. package/dist-npm/components/block/block.js +48 -61
  3. package/dist-npm/components/checkbox/index.js +178 -211
  4. package/dist-npm/components/confirm/confirm-main.js +85 -122
  5. package/dist-npm/components/confirm/confirm-three.js +24 -27
  6. package/dist-npm/components/confirm/index.js +36 -45
  7. package/dist-npm/components/core/Separator.js +15 -17
  8. package/dist-npm/components/core/create-prompt.js +101 -124
  9. package/dist-npm/components/core/errors.js +19 -15
  10. package/dist-npm/components/core/hook-engine.js +91 -120
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +16 -6
  13. package/dist-npm/components/core/lines.js +45 -54
  14. package/dist-npm/components/core/make-theme.js +21 -30
  15. package/dist-npm/components/core/position.js +27 -23
  16. package/dist-npm/components/core/promise-polyfill.js +11 -14
  17. package/dist-npm/components/core/screen-manager.js +59 -74
  18. package/dist-npm/components/core/theme.js +22 -32
  19. package/dist-npm/components/core/use-effect.js +9 -15
  20. package/dist-npm/components/core/use-keypress.js +19 -23
  21. package/dist-npm/components/core/use-memo.js +10 -16
  22. package/dist-npm/components/core/use-pagination.js +33 -32
  23. package/dist-npm/components/core/use-prefix.js +40 -38
  24. package/dist-npm/components/core/use-ref.js +2 -5
  25. package/dist-npm/components/core/use-state.js +15 -23
  26. package/dist-npm/components/core/useKeyPress.js +14 -17
  27. package/dist-npm/components/core/usePromptState.js +8 -14
  28. package/dist-npm/components/core/utils.js +7 -16
  29. package/dist-npm/components/date/date.js +173 -204
  30. package/dist-npm/components/editor/index.js +71 -92
  31. package/dist-npm/components/expand/index.js +96 -124
  32. package/dist-npm/components/figures/index.js +283 -294
  33. package/dist-npm/components/input/index.js +61 -87
  34. package/dist-npm/components/input/text-main.js +97 -124
  35. package/dist-npm/components/input/text.js +24 -28
  36. package/dist-npm/components/instance/basic.js +17 -25
  37. package/dist-npm/components/instance/browser.js +14 -18
  38. package/dist-npm/components/instance/reporter/basic.js +46 -65
  39. package/dist-npm/components/instance/reporter/browser.js +44 -47
  40. package/dist-npm/components/instance/reporter/fancy.js +83 -96
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +52 -62
  43. package/dist-npm/components/mono/monoTwo.js +35 -49
  44. package/dist-npm/components/multiselect/group-multiselect.js +55 -71
  45. package/dist-npm/components/multiselect/multi-select-two.js +97 -130
  46. package/dist-npm/components/multiselect/multi-select.js +43 -49
  47. package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
  48. package/dist-npm/components/multiselect/multiselect-main.js +158 -145
  49. package/dist-npm/components/multiselect/num-multi-select.js +97 -130
  50. package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
  51. package/dist-npm/components/next-steps/next-steps.js +23 -25
  52. package/dist-npm/components/number/index.js +78 -112
  53. package/dist-npm/components/number/number-main.js +95 -2
  54. package/dist-npm/components/password/index.js +54 -73
  55. package/dist-npm/components/password/password-main.js +119 -2
  56. package/dist-npm/components/password/password-three.js +26 -30
  57. package/dist-npm/components/progressbar/ProgressBar.js +45 -64
  58. package/dist-npm/components/progressbar/helper.js +33 -40
  59. package/dist-npm/components/progressbar/index.js +1 -1
  60. package/dist-npm/components/prompts/create.js +29 -44
  61. package/dist-npm/components/prompts/index.d.ts +1 -0
  62. package/dist-npm/components/prompts/index.js +46 -45
  63. package/dist-npm/components/prompts/prompt.js +211 -260
  64. package/dist-npm/components/prompts/promptTwo.js +561 -605
  65. package/dist-npm/components/prompts/relinka.js +237 -295
  66. package/dist-npm/components/range/range.js +247 -294
  67. package/dist-npm/components/rawlist/index.js +87 -107
  68. package/dist-npm/components/results/results.js +31 -37
  69. package/dist-npm/components/search/index.js +148 -193
  70. package/dist-npm/components/select/index.js +148 -186
  71. package/dist-npm/components/select/num-select-main.js +27 -27
  72. package/dist-npm/components/select/num-select.js +124 -5
  73. package/dist-npm/components/select/select-key.js +24 -25
  74. package/dist-npm/components/select/select-main.d.ts +1 -0
  75. package/dist-npm/components/select/select-main.js +143 -133
  76. package/dist-npm/components/select/select-three.js +32 -36
  77. package/dist-npm/components/select/select-two.js +94 -87
  78. package/dist-npm/components/spinner/index.js +107 -136
  79. package/dist-npm/components/st-end/end.js +34 -26
  80. package/dist-npm/components/st-end/start.js +29 -15
  81. package/dist-npm/components/toggle/index.js +113 -137
  82. package/dist-npm/components/visual/animate/animate.js +53 -10
  83. package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
  84. package/dist-npm/main.js +1 -0
  85. package/dist-npm/testing/index.js +58 -83
  86. package/dist-npm/types/general.d.ts +1 -1
  87. package/dist-npm/types/general.js +0 -1
  88. package/dist-npm/types/index.js +2 -3
  89. package/dist-npm/types/keypress.js +35 -36
  90. package/dist-npm/types/readline.js +0 -1
  91. package/dist-npm/types/relinka.js +0 -1
  92. package/dist-npm/types/utils.js +0 -1
  93. package/dist-npm/utils/box.js +135 -137
  94. package/dist-npm/utils/color.js +65 -74
  95. package/dist-npm/utils/colorize.js +124 -156
  96. package/dist-npm/utils/component.js +532 -657
  97. package/dist-npm/utils/constants.js +64 -63
  98. package/dist-npm/utils/core.js +2 -3
  99. package/dist-npm/utils/decoder.js +244 -223
  100. package/dist-npm/utils/error.js +4 -9
  101. package/dist-npm/utils/errors.js +14 -4
  102. package/dist-npm/utils/format.js +19 -24
  103. package/dist-npm/utils/keypress.js +316 -414
  104. package/dist-npm/utils/log.js +11 -15
  105. package/dist-npm/utils/mapping.js +45 -52
  106. package/dist-npm/utils/messages.js +196 -183
  107. package/dist-npm/utils/platforms.js +16 -20
  108. package/dist-npm/utils/prompt-tmp.js +235 -286
  109. package/dist-npm/utils/prompt-two.js +235 -286
  110. package/dist-npm/utils/readline.js +5 -7
  111. package/dist-npm/utils/skeleton.js +130 -170
  112. package/dist-npm/utils/stream.js +2 -2
  113. package/dist-npm/utils/string.js +44 -58
  114. package/dist-npm/utils/terminal.js +23 -34
  115. package/dist-npm/utils/tree.js +30 -41
  116. package/dist-npm/utils/types.js +0 -1
  117. package/dist-npm/utils/utils.js +8 -8
  118. package/dist-npm/utils/variants.js +36 -44
  119. package/package.json +14 -14
  120. package/dist-npm/mod.js +0 -2
  121. /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
@@ -1,92 +1,66 @@
1
1
  import {
2
- createPrompt,
3
- useState,
4
- useKeypress,
5
- usePrefix,
6
- isEnterKey,
7
- isBackspaceKey,
8
- makeTheme,
9
- } from '../../components/core/index.js';
10
-
11
- const isFn = (a) => typeof a === 'function';
12
-
2
+ createPrompt,
3
+ useState,
4
+ useKeypress,
5
+ usePrefix,
6
+ isEnterKey,
7
+ isBackspaceKey,
8
+ makeTheme
9
+ } from "../../components/core/index.js";
13
10
  export default createPrompt((config, done) => {
14
- const {required, validate = () => true} = config;
15
- const theme = makeTheme(config.theme);
16
- const [status, setStatus] = useState('idle');
17
- const [defaultValue = '', setDefaultValue] = useState(config.default);
18
- const [errorMsg, setError] = useState();
19
- const [value, setValue] = useState('');
20
- const prefix = usePrefix({
21
- status,
22
- theme,
23
- });
24
-
25
- useKeypress(async (key, rl) => {
26
- if (status !== 'idle') {
27
- return;
28
- }
29
-
30
- if (isEnterKey(key)) {
31
- const answer = value || defaultValue;
32
- setStatus('loading');
33
- const isValid = required && !answer ? 'You must provide a value' : await validate(answer);
34
-
35
- if (isValid) {
36
- setValue(answer);
37
- setStatus('done');
38
- done(answer);
39
- } else {
40
- rl.write(value);
41
- setError(isValid || 'You must provide a valid value');
42
- setStatus('idle');
43
- }
44
- } else if (isBackspaceKey(key) && !value) {
45
- setDefaultValue(void 0);
46
- } else if (key.name === 'tab' && !value) {
47
- setDefaultValue(void 0);
48
- rl.clearLine(0);
49
- rl.write(defaultValue);
50
- setValue(defaultValue);
51
- } else {
52
- setValue(rl.line);
53
- setError(void 0);
54
- }
55
-
56
- });
57
- const message = theme.style.message(config.message, status);
58
- let formattedValue = value;
59
-
60
- if (isFn(config.transformer)) {
61
- formattedValue = config.transformer(value, {
62
- isFinal: status === 'done',
63
- });
64
- } else if (status === 'done') {
65
- formattedValue = theme.style.answer(value);
11
+ const { required, validate = () => true } = config;
12
+ const theme = makeTheme(config.theme);
13
+ const [status, setStatus] = useState("idle");
14
+ const [defaultValue = "", setDefaultValue] = useState(config.default);
15
+ const [errorMsg, setError] = useState();
16
+ const [value, setValue] = useState("");
17
+ const prefix = usePrefix({ status, theme });
18
+ useKeypress(async (key, rl) => {
19
+ if (status !== "idle") {
20
+ return;
66
21
  }
67
-
68
-
69
- let defaultStr;
70
-
71
- if (defaultValue && status !== 'done' && !value) {
72
- defaultStr = theme.style.defaultAnswer(defaultValue);
22
+ if (isEnterKey(key)) {
23
+ const answer = value || defaultValue;
24
+ setStatus("loading");
25
+ const isValid = required && !answer ? "You must provide a value" : await validate(answer);
26
+ if (isValid === true) {
27
+ setValue(answer);
28
+ setStatus("done");
29
+ done(answer);
30
+ } else {
31
+ rl.write(value);
32
+ setError(isValid || "You must provide a valid value");
33
+ setStatus("idle");
34
+ }
35
+ } else if (isBackspaceKey(key) && !value) {
36
+ setDefaultValue(void 0);
37
+ } else if (key.name === "tab" && !value) {
38
+ setDefaultValue(void 0);
39
+ rl.clearLine(0);
40
+ rl.write(defaultValue);
41
+ setValue(defaultValue);
42
+ } else {
43
+ setValue(rl.line);
44
+ setError(void 0);
73
45
  }
74
-
75
- let error = '';
76
-
77
- if (errorMsg) {
78
- error = theme.style.error(errorMsg);
79
- }
80
-
81
- return [
82
- [
83
- prefix,
84
- message,
85
- defaultStr,
86
- formattedValue,
87
- ]
88
- .filter((v) => v !== void 0)
89
- .join(' '),
90
- error,
91
- ];
46
+ });
47
+ const message = theme.style.message(config.message, status);
48
+ let formattedValue = value;
49
+ if (typeof config.transformer === "function") {
50
+ formattedValue = config.transformer(value, { isFinal: status === "done" });
51
+ } else if (status === "done") {
52
+ formattedValue = theme.style.answer(value);
53
+ }
54
+ let defaultStr;
55
+ if (defaultValue && status !== "done" && !value) {
56
+ defaultStr = theme.style.defaultAnswer(defaultValue);
57
+ }
58
+ let error = "";
59
+ if (errorMsg) {
60
+ error = theme.style.error(errorMsg);
61
+ }
62
+ return [
63
+ [prefix, message, defaultStr, formattedValue].filter((v) => v !== void 0).join(" "),
64
+ error
65
+ ];
92
66
  });
@@ -1,130 +1,103 @@
1
- import {Value} from '@sinclair/typebox/value';
1
+ import { Value } from "@sinclair/typebox/value";
2
+ import { stdin as input, stdout as output } from "node:process";
3
+ import readline from "node:readline/promises";
4
+ import { fmt, msg } from "../../utils/messages.js";
2
5
  import {
3
- stdin as input,
4
- stdout as output,
5
- } from 'node:process';
6
- import readline from 'node:readline/promises';
7
- import {fmt, msg} from '../../utils/messages.js';
8
- import {
9
- countLines,
10
- deleteLastLine,
11
- deleteLastLines,
12
- } from '../../utils/terminal.js';
13
-
14
- const isString = (a) => typeof a === 'string';
15
-
6
+ countLines,
7
+ deleteLastLine,
8
+ deleteLastLines
9
+ } from "../../utils/terminal.js";
16
10
  export async function textPrompt(options) {
17
- const {
18
- title,
19
- hint,
20
- validate,
21
- defaultValue = '',
22
- schema,
23
- titleColor = 'cyanBright',
24
- titleTypography = 'bold',
25
- titleVariant,
26
- content,
27
- contentColor,
28
- contentTypography,
29
- contentVariant,
30
- borderColor = 'viceGradient',
31
- variantOptions,
32
- placeholder,
33
- } = options;
34
-
35
- const rl = readline.createInterface({
36
- input,
37
- output,
11
+ const {
12
+ title,
13
+ hint,
14
+ validate,
15
+ defaultValue = "",
16
+ schema,
17
+ titleColor = "cyanBright",
18
+ titleTypography = "bold",
19
+ titleVariant,
20
+ content,
21
+ contentColor,
22
+ contentTypography,
23
+ contentVariant,
24
+ borderColor = "viceGradient",
25
+ variantOptions,
26
+ placeholder
27
+ } = options;
28
+ const rl = readline.createInterface({ input, output });
29
+ let linesToDelete = 0;
30
+ let errorMessage = "";
31
+ let currentInput = "";
32
+ let showPlaceholder = true;
33
+ while (true) {
34
+ if (linesToDelete > 0) {
35
+ deleteLastLines(linesToDelete);
36
+ }
37
+ const question = fmt({
38
+ type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
39
+ title,
40
+ titleColor,
41
+ titleTypography,
42
+ titleVariant,
43
+ content,
44
+ contentColor,
45
+ contentTypography,
46
+ contentVariant,
47
+ borderColor,
48
+ hint,
49
+ placeholder: showPlaceholder ? placeholder : void 0,
50
+ variantOptions,
51
+ errorMessage
38
52
  });
39
- let linesToDelete = 0;
40
- let errorMessage = '';
41
- let currentInput = '';
42
- let showPlaceholder = true;
43
-
44
- while (true) {
45
- if (linesToDelete > 0) {
46
- deleteLastLines(linesToDelete);
47
- }
48
-
49
- const question = fmt({
50
- type: errorMessage !== '' ? 'M_ERROR' : 'M_GENERAL',
51
- title,
52
- titleColor,
53
- titleTypography,
54
- titleVariant,
55
- content,
56
- contentColor,
57
- contentTypography,
58
- contentVariant,
59
- borderColor,
60
- hint,
61
- placeholder: showPlaceholder ? placeholder : void 0,
62
- variantOptions,
63
- errorMessage,
64
- });
65
-
66
- const questionLines = countLines(question);
67
- const prompt = await rl.question(question);
68
-
69
- currentInput = prompt.trim();
70
- if (showPlaceholder && currentInput !== '') {
71
- showPlaceholder = false;
72
- deleteLastLine();
73
- deleteLastLine();
74
- msg({
75
- type: 'M_MIDDLE',
76
- title: ` ${currentInput}`,
77
- });
78
- }
79
-
80
- linesToDelete = questionLines + 1;
81
- const answer = currentInput || defaultValue;
82
-
83
- if (currentInput === '' && defaultValue !== '') {
84
- deleteLastLine();
85
- deleteLastLine();
86
- const defaultMsg = fmt({
87
- type: 'M_MIDDLE',
88
- title: ` ${defaultValue}`,
89
- borderColor,
90
- });
91
-
92
- linesToDelete += countLines(defaultMsg);
93
- }
94
-
95
- let isValid = true;
96
-
97
- errorMessage = '';
98
- if (schema) {
99
- isValid = Value.Check(schema, answer);
100
- if (!isValid) {
101
- const errors = Value.Errors(schema, answer);
102
-
103
- if (errors.length > 0) {
104
- errorMessage = errors[0]?.message ?? 'Invalid input.';
105
- } else {
106
- errorMessage = 'Invalid input.';
107
- }
108
- }
109
- }
110
-
111
- if (validate && isValid) {
112
- const validation = await validate(answer);
113
-
114
- if (!validation) {
115
- isValid = false;
116
- errorMessage = isString(validation) ? validation : 'Invalid input.';
117
- }
118
- }
119
-
120
- if (isValid) {
121
- msg({
122
- type: 'M_NEWLINE',
123
- });
124
- rl.close();
125
- return answer;
53
+ const questionLines = countLines(question);
54
+ const prompt = await rl.question(question);
55
+ currentInput = prompt.trim();
56
+ if (showPlaceholder && currentInput !== "") {
57
+ showPlaceholder = false;
58
+ deleteLastLine();
59
+ deleteLastLine();
60
+ msg({ type: "M_MIDDLE", title: ` ${currentInput}` });
61
+ }
62
+ linesToDelete = questionLines + 1;
63
+ const answer = currentInput || defaultValue;
64
+ if (currentInput === "" && defaultValue !== "") {
65
+ deleteLastLine();
66
+ deleteLastLine();
67
+ const defaultMsg = fmt({
68
+ type: "M_MIDDLE",
69
+ title: ` ${defaultValue}`,
70
+ borderColor
71
+ });
72
+ console.log(defaultMsg);
73
+ linesToDelete += countLines(defaultMsg);
74
+ }
75
+ let isValid = true;
76
+ errorMessage = "";
77
+ if (schema) {
78
+ isValid = Value.Check(schema, answer);
79
+ if (!isValid) {
80
+ const errors = [...Value.Errors(schema, answer)];
81
+ if (errors.length > 0) {
82
+ errorMessage = errors[0]?.message ?? "Invalid input.";
83
+ } else {
84
+ errorMessage = "Invalid input.";
126
85
  }
127
-
128
- linesToDelete += 0;
86
+ }
87
+ }
88
+ if (validate && isValid) {
89
+ const validation = await validate(answer);
90
+ if (validation !== true) {
91
+ isValid = false;
92
+ errorMessage = typeof validation === "string" ? validation : "Invalid input.";
93
+ }
94
+ }
95
+ if (isValid) {
96
+ msg({ type: "M_NEWLINE" });
97
+ rl.close();
98
+ return answer;
99
+ } else {
100
+ linesToDelete += 0;
129
101
  }
102
+ }
130
103
  }
@@ -1,30 +1,26 @@
1
- import color from 'picocolors';
2
- import Prompt from '../prompts/prompt.js';
3
-
1
+ import color from "picocolors";
2
+ import Prompt from "../prompts/prompt.js";
4
3
  export default class TextPrompt extends Prompt {
5
- valueWithCursor = '';
6
- get cursor() {
7
- return this._cursor;
8
- }
9
-
10
- constructor(opts) {
11
- super(opts);
12
- this.on('finalize', () => {
13
- if (!this.value) {
14
- this.value = opts.defaultValue;
15
- }
16
-
17
- this.valueWithCursor = this.value;
18
- });
19
- this.on('value', () => {
20
- if (this.cursor >= this.value.length) {
21
- this.valueWithCursor = `${this.value}${color.inverse(color.hidden('_'))}`;
22
- } else {
23
- const s1 = this.value.slice(0, this.cursor);
24
- const s2 = this.value.slice(this.cursor);
25
-
26
- this.valueWithCursor = `${s1}${color.inverse(s2[0])}${s2.slice(1)}`;
27
- }
28
- });
29
- }
4
+ valueWithCursor = "";
5
+ get cursor() {
6
+ return this._cursor;
7
+ }
8
+ constructor(opts) {
9
+ super(opts);
10
+ this.on("finalize", () => {
11
+ if (!this.value) {
12
+ this.value = opts.defaultValue;
13
+ }
14
+ this.valueWithCursor = this.value;
15
+ });
16
+ this.on("value", () => {
17
+ if (this.cursor >= this.value.length) {
18
+ this.valueWithCursor = `${this.value}${color.inverse(color.hidden("_"))}`;
19
+ } else {
20
+ const s1 = this.value.slice(0, this.cursor);
21
+ const s2 = this.value.slice(this.cursor);
22
+ this.valueWithCursor = `${s1}${color.inverse(s2[0])}${s2.slice(1)}`;
23
+ }
24
+ });
25
+ }
30
26
  }
@@ -1,29 +1,21 @@
1
- import {BasicReporter} from '../../components/instance/reporter/basic.js';
2
- import {createRelinka as _createRelinka} from '../../components/prompts/relinka.js';
3
- import process from 'node:process';
4
- import {LogLevels} from '../../utils/constants.js';
5
-
6
- export * from '../../components/instance/shared.js';
1
+ import { BasicReporter } from "../../components/instance/reporter/basic.js";
2
+ import { createRelinka as _createRelinka } from "../../components/prompts/relinka.js";
3
+ import { LogLevels } from "../../utils/constants.js";
4
+ export * from "../../components/instance/shared.js";
7
5
  export function createRelinka(options = {}) {
8
- let level = LogLevels.info;
9
-
10
- if (process.env.RELINKA_LEVEL) {
11
- level = Number.parseInt(process.env.RELINKA_LEVEL) ?? level;
12
- }
13
-
14
- const relinka2 = _createRelinka({
15
- level,
16
- defaults: {
17
- level,
18
- },
19
- stdout: process.stdout,
20
- stderr: process.stderr,
21
- reporters: options.reporters || [new BasicReporter()],
22
- ...options,
23
- });
24
-
25
- return relinka2;
6
+ let level = LogLevels.info;
7
+ if (process.env.RELINKA_LEVEL) {
8
+ level = Number.parseInt(process.env.RELINKA_LEVEL) ?? level;
9
+ }
10
+ const relinka2 = _createRelinka({
11
+ level,
12
+ defaults: { level },
13
+ stdout: process.stdout,
14
+ stderr: process.stderr,
15
+ reporters: options.reporters || [new BasicReporter()],
16
+ ...options
17
+ });
18
+ return relinka2;
26
19
  }
27
-
28
20
  export const relinka = createRelinka();
29
21
  export default relinka;
@@ -1,22 +1,18 @@
1
- import {BrowserReporter} from '../../components/instance/reporter/browser.js';
2
- import {createRelinka as _createRelinka} from '../../components/prompts/relinka.js';
3
-
4
- export * from '../../components/instance/shared.js';
1
+ import { BrowserReporter } from "../../components/instance/reporter/browser.js";
2
+ import { createRelinka as _createRelinka } from "../../components/prompts/relinka.js";
3
+ export * from "../../components/instance/shared.js";
5
4
  export function createRelinka(options = {}) {
6
- const relinka2 = _createRelinka({
7
- reporters: options.reporters || [new BrowserReporter({})],
8
- prompt(message, options2 = {}) {
9
- if (options2.type === 'confirm') {
10
- return Promise.resolve(confirm(message));
11
- }
12
-
13
- return Promise.resolve(prompt(message));
14
- },
15
- ...options,
16
- });
17
-
18
- return relinka2;
5
+ const relinka2 = _createRelinka({
6
+ reporters: options.reporters || [new BrowserReporter({})],
7
+ prompt(message, options2 = {}) {
8
+ if (options2.type === "confirm") {
9
+ return Promise.resolve(confirm(message));
10
+ }
11
+ return Promise.resolve(prompt(message));
12
+ },
13
+ ...options
14
+ });
15
+ return relinka2;
19
16
  }
20
-
21
17
  export const relinka = createRelinka();
22
18
  export default relinka;
@@ -1,68 +1,49 @@
1
- import {formatWithOptions} from 'node:util';
2
- import process from 'node:process';
3
- import {parseStack} from '../../../utils/error.js';
4
- import {writeStream} from '../../../utils/stream.js';
5
-
6
- const isString = (a) => typeof a === 'string';
7
- const bracket = (x) => x ? `[${x}]` : '';
8
-
1
+ import { formatWithOptions } from "node:util";
2
+ import { parseStack } from "../../../utils/error.js";
3
+ import { writeStream } from "../../../utils/stream.js";
4
+ const bracket = (x) => x ? `[${x}]` : "";
9
5
  export class BasicReporter {
10
- formatStack(stack) {
11
- return ' ' + parseStack(stack).join('\n ');
12
- }
13
-
14
- formatArgs(args, opts) {
15
- const _args = args.map((arg) => {
16
- if (arg && isString(arg.stack)) {
17
- return arg.message + '\n' + this.formatStack(arg.stack, opts);
18
- }
19
-
20
- return arg;
21
- });
22
-
23
- return formatWithOptions(opts, ..._args);
24
- }
25
-
26
- formatDate(date, opts) {
27
- return opts.date ? date.toLocaleTimeString() : '';
28
- }
29
-
30
- filterAndJoin(arr) {
31
- return arr
32
- .filter(Boolean)
33
- .join(' ');
34
- }
35
-
36
- formatLogObj(logObj, opts) {
37
- const message = this.formatArgs(logObj.args, opts);
38
-
39
- if (logObj.type === 'box') {
40
- return `
41
- ${[
42
- bracket(logObj.tag),
43
- logObj.title,
44
- ...message.split('\n'),
45
- ]
46
- .filter(Boolean)
47
- .map((l) => ` > ${l}`)
48
- .join('\n')}
49
- `;
50
- }
51
-
52
- return this.filterAndJoin([
53
- bracket(logObj.type),
54
- bracket(logObj.tag),
55
- message,
56
- ]);
57
- }
58
-
59
- log(logObj, ctx) {
60
- const line = this.formatLogObj(logObj, {
61
- columns: ctx.options.stdout.columns || 0,
62
- ...ctx.options.formatOptions,
63
- });
64
-
65
- return writeStream(`${line}
66
- `, logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout);
6
+ formatStack(stack, opts) {
7
+ return " " + parseStack(stack).join("\n ");
8
+ }
9
+ formatArgs(args, opts) {
10
+ const _args = args.map((arg) => {
11
+ if (arg && typeof arg.stack === "string") {
12
+ return arg.message + "\n" + this.formatStack(arg.stack, opts);
13
+ }
14
+ return arg;
15
+ });
16
+ return formatWithOptions(opts, ..._args);
17
+ }
18
+ formatDate(date, opts) {
19
+ return opts.date ? date.toLocaleTimeString() : "";
20
+ }
21
+ filterAndJoin(arr) {
22
+ return arr.filter(Boolean).join(" ");
23
+ }
24
+ formatLogObj(logObj, opts) {
25
+ const message = this.formatArgs(logObj.args, opts);
26
+ if (logObj.type === "box") {
27
+ return "\n" + [
28
+ bracket(logObj.tag),
29
+ logObj.title && logObj.title,
30
+ ...message.split("\n")
31
+ ].filter(Boolean).map((l) => " > " + l).join("\n") + "\n";
67
32
  }
33
+ return this.filterAndJoin([
34
+ bracket(logObj.type),
35
+ bracket(logObj.tag),
36
+ message
37
+ ]);
38
+ }
39
+ log(logObj, ctx) {
40
+ const line = this.formatLogObj(logObj, {
41
+ columns: ctx.options.stdout.columns || 0,
42
+ ...ctx.options.formatOptions
43
+ });
44
+ return writeStream(
45
+ line + "\n",
46
+ logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout
47
+ );
48
+ }
68
49
  }