@reliverse/relinka 1.1.4 → 1.1.6

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 (118) hide show
  1. package/dist-npm/components/anykey/index.js +77 -57
  2. package/dist-npm/components/block/block.js +61 -48
  3. package/dist-npm/components/checkbox/index.js +211 -178
  4. package/dist-npm/components/confirm/confirm-main.js +122 -86
  5. package/dist-npm/components/confirm/confirm-three.js +27 -24
  6. package/dist-npm/components/confirm/index.js +45 -36
  7. package/dist-npm/components/core/Separator.js +17 -15
  8. package/dist-npm/components/core/create-prompt.js +124 -101
  9. package/dist-npm/components/core/errors.js +15 -19
  10. package/dist-npm/components/core/hook-engine.js +120 -91
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +6 -16
  13. package/dist-npm/components/core/lines.js +54 -45
  14. package/dist-npm/components/core/make-theme.js +30 -21
  15. package/dist-npm/components/core/position.js +23 -27
  16. package/dist-npm/components/core/promise-polyfill.js +14 -11
  17. package/dist-npm/components/core/screen-manager.js +74 -59
  18. package/dist-npm/components/core/theme.js +32 -22
  19. package/dist-npm/components/core/use-effect.js +15 -9
  20. package/dist-npm/components/core/use-keypress.js +23 -19
  21. package/dist-npm/components/core/use-memo.js +16 -10
  22. package/dist-npm/components/core/use-pagination.js +32 -33
  23. package/dist-npm/components/core/use-prefix.js +38 -40
  24. package/dist-npm/components/core/use-ref.js +5 -2
  25. package/dist-npm/components/core/use-state.js +23 -15
  26. package/dist-npm/components/core/useKeyPress.js +17 -14
  27. package/dist-npm/components/core/usePromptState.js +14 -8
  28. package/dist-npm/components/core/utils.js +16 -7
  29. package/dist-npm/components/date/date.js +204 -168
  30. package/dist-npm/components/editor/index.js +92 -71
  31. package/dist-npm/components/expand/index.js +124 -96
  32. package/dist-npm/components/figures/index.js +294 -283
  33. package/dist-npm/components/input/index.js +87 -61
  34. package/dist-npm/components/input/text-main.js +124 -86
  35. package/dist-npm/components/input/text.js +28 -24
  36. package/dist-npm/components/instance/basic.js +25 -17
  37. package/dist-npm/components/instance/browser.js +18 -14
  38. package/dist-npm/components/instance/reporter/basic.js +65 -46
  39. package/dist-npm/components/instance/reporter/browser.js +47 -44
  40. package/dist-npm/components/instance/reporter/fancy.js +96 -83
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +62 -52
  43. package/dist-npm/components/mono/monoTwo.js +49 -35
  44. package/dist-npm/components/multiselect/group-multiselect.js +71 -55
  45. package/dist-npm/components/multiselect/multi-select-two.js +130 -98
  46. package/dist-npm/components/multiselect/multi-select.js +49 -43
  47. package/dist-npm/components/multiselect/multiselect-main.js +146 -120
  48. package/dist-npm/components/multiselect/num-multi-select.js +130 -98
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -24
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -96
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -120
  55. package/dist-npm/components/password/password-three.js +30 -26
  56. package/dist-npm/components/progressbar/ProgressBar.js +64 -45
  57. package/dist-npm/components/progressbar/helper.js +40 -33
  58. package/dist-npm/components/progressbar/index.js +1 -1
  59. package/dist-npm/components/prompts/create.js +44 -29
  60. package/dist-npm/components/prompts/index.js +45 -45
  61. package/dist-npm/components/prompts/prompt.js +260 -211
  62. package/dist-npm/components/prompts/promptTwo.js +605 -561
  63. package/dist-npm/components/prompts/relinka.js +295 -237
  64. package/dist-npm/components/range/range.js +294 -247
  65. package/dist-npm/components/rawlist/index.js +107 -87
  66. package/dist-npm/components/results/results.js +37 -31
  67. package/dist-npm/components/search/index.js +193 -148
  68. package/dist-npm/components/select/index.js +186 -148
  69. package/dist-npm/components/select/num-select-main.js +27 -27
  70. package/dist-npm/components/select/num-select.js +5 -125
  71. package/dist-npm/components/select/select-key.js +25 -24
  72. package/dist-npm/components/select/select-main.js +133 -109
  73. package/dist-npm/components/select/select-three.js +36 -32
  74. package/dist-npm/components/select/select-two.js +87 -95
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.d.ts +1 -1
  77. package/dist-npm/components/st-end/end.js +26 -35
  78. package/dist-npm/components/st-end/start.d.ts +1 -1
  79. package/dist-npm/components/st-end/start.js +15 -30
  80. package/dist-npm/components/toggle/index.js +137 -113
  81. package/dist-npm/components/visual/animate/animate.js +10 -53
  82. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  83. package/dist-npm/mod.js +2 -1
  84. package/dist-npm/testing/index.js +83 -58
  85. package/dist-npm/types/general.d.ts +2 -1
  86. package/dist-npm/types/general.js +1 -0
  87. package/dist-npm/types/index.js +3 -2
  88. package/dist-npm/types/keypress.js +36 -35
  89. package/dist-npm/types/readline.js +1 -0
  90. package/dist-npm/types/relinka.js +1 -0
  91. package/dist-npm/types/utils.js +1 -0
  92. package/dist-npm/utils/box.js +137 -135
  93. package/dist-npm/utils/color.js +74 -65
  94. package/dist-npm/utils/colorize.js +156 -124
  95. package/dist-npm/utils/component.js +657 -532
  96. package/dist-npm/utils/constants.js +63 -64
  97. package/dist-npm/utils/core.js +3 -2
  98. package/dist-npm/utils/decoder.js +223 -244
  99. package/dist-npm/utils/error.js +9 -4
  100. package/dist-npm/utils/errors.js +4 -14
  101. package/dist-npm/utils/format.js +24 -19
  102. package/dist-npm/utils/keypress.js +414 -316
  103. package/dist-npm/utils/log.js +15 -11
  104. package/dist-npm/utils/mapping.js +52 -45
  105. package/dist-npm/utils/messages.js +183 -183
  106. package/dist-npm/utils/platforms.js +20 -16
  107. package/dist-npm/utils/prompt-tmp.js +286 -235
  108. package/dist-npm/utils/prompt-two.js +286 -235
  109. package/dist-npm/utils/readline.js +7 -5
  110. package/dist-npm/utils/skeleton.js +170 -130
  111. package/dist-npm/utils/stream.js +2 -2
  112. package/dist-npm/utils/string.js +58 -44
  113. package/dist-npm/utils/terminal.js +34 -23
  114. package/dist-npm/utils/tree.js +41 -30
  115. package/dist-npm/utils/types.js +1 -0
  116. package/dist-npm/utils/utils.js +8 -8
  117. package/dist-npm/utils/variants.js +44 -36
  118. package/package.json +20 -28
@@ -1,66 +1,92 @@
1
1
  import {
2
- createPrompt,
3
- useState,
4
- useKeypress,
5
- usePrefix,
6
- isEnterKey,
7
- isBackspaceKey,
8
- makeTheme
9
- } from "../../components/core/index.js";
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
+
10
13
  export default createPrompt((config, done) => {
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;
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);
21
66
  }
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);
67
+
68
+
69
+ let defaultStr;
70
+
71
+ if (defaultValue && status !== 'done' && !value) {
72
+ defaultStr = theme.style.defaultAnswer(defaultValue);
45
73
  }
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
- ];
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
+ ];
66
92
  });
@@ -1,92 +1,130 @@
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";
1
+ import {Value} from '@sinclair/typebox/value';
5
2
  import {
6
- countLines,
7
- deleteLastLine,
8
- deleteLastLines
9
- } from "../../utils/terminal.js";
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
+
10
16
  export async function textPrompt(options) {
11
- const {
12
- title,
13
- hint,
14
- validate,
15
- defaultValue = "",
16
- schema,
17
- titleColor = "cyanBright",
18
- answerColor = "none",
19
- titleTypography = "bold",
20
- titleVariant,
21
- content,
22
- contentColor,
23
- contentTypography,
24
- contentVariant,
25
- borderColor = "viceGradient",
26
- variantOptions
27
- } = options;
28
- const rl = readline.createInterface({ input, output });
29
- let linesToDelete = 0;
30
- let errorMessage = "";
31
- while (true) {
32
- if (linesToDelete > 0) {
33
- deleteLastLines(linesToDelete);
34
- }
35
- const question = fmt({
36
- type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
37
- title,
38
- titleColor,
39
- titleTypography,
40
- titleVariant,
41
- content,
42
- contentColor,
43
- contentTypography,
44
- contentVariant,
45
- borderColor,
46
- hint,
47
- variantOptions,
48
- errorMessage
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,
49
38
  });
50
- const questionLines = countLines(question);
51
- const prompt = await rl.question(question);
52
- linesToDelete = questionLines + 1;
53
- const answer = prompt.trim() || defaultValue;
54
- if (prompt.trim() === "" && defaultValue !== "") {
55
- deleteLastLine();
56
- const defaultMsg = fmt({
57
- type: "M_MIDDLE",
58
- title: ` ${defaultValue}`,
59
- borderColor
60
- });
61
- console.log(defaultMsg);
62
- linesToDelete += countLines(defaultMsg);
63
- }
64
- let isValid = true;
65
- errorMessage = "";
66
- if (schema) {
67
- isValid = Value.Check(schema, answer);
68
- if (!isValid) {
69
- const errors = [...Value.Errors(schema, answer)];
70
- if (errors.length > 0) {
71
- errorMessage = errors[0]?.message ?? "Invalid input.";
72
- } else {
73
- errorMessage = "Invalid input.";
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);
74
47
  }
75
- }
76
- }
77
- if (validate && isValid) {
78
- const validation = await validate(answer);
79
- if (validation !== true) {
80
- isValid = false;
81
- errorMessage = typeof validation === "string" ? validation : "Invalid input.";
82
- }
83
- }
84
- if (isValid) {
85
- msg({ type: "M_NEWLINE" });
86
- rl.close();
87
- return answer;
88
- } else {
89
- linesToDelete += 0;
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;
126
+ }
127
+
128
+ linesToDelete += 0;
90
129
  }
91
- }
92
130
  }
@@ -1,26 +1,30 @@
1
- import color from "picocolors";
2
- import Prompt from "../prompts/prompt.js";
1
+ import color from 'picocolors';
2
+ import Prompt from '../prompts/prompt.js';
3
+
3
4
  export default class TextPrompt extends Prompt {
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
- }
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
+ }
26
30
  }
@@ -1,21 +1,29 @@
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";
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';
5
7
  export function createRelinka(options = {}) {
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;
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;
19
26
  }
27
+
20
28
  export const relinka = createRelinka();
21
29
  export default relinka;
@@ -1,18 +1,22 @@
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";
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';
4
5
  export function createRelinka(options = {}) {
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;
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;
16
19
  }
20
+
17
21
  export const relinka = createRelinka();
18
22
  export default relinka;
@@ -1,49 +1,68 @@
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}]` : "";
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
+
5
9
  export class BasicReporter {
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";
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);
32
67
  }
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
- }
49
68
  }