@reliverse/relinka 1.1.5 → 1.1.7

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 (115) 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 -85
  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 -167
  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 -97
  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 -97
  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 -97
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -23
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -95
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -119
  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 -124
  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 -94
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.js +26 -34
  77. package/dist-npm/components/st-end/start.js +15 -29
  78. package/dist-npm/components/toggle/index.js +137 -113
  79. package/dist-npm/components/visual/animate/animate.js +10 -53
  80. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  81. package/dist-npm/mod.js +2 -1
  82. package/dist-npm/testing/index.js +83 -58
  83. package/dist-npm/types/general.js +1 -0
  84. package/dist-npm/types/index.js +3 -2
  85. package/dist-npm/types/keypress.js +36 -35
  86. package/dist-npm/types/readline.js +1 -0
  87. package/dist-npm/types/relinka.js +1 -0
  88. package/dist-npm/types/utils.js +1 -0
  89. package/dist-npm/utils/box.js +137 -135
  90. package/dist-npm/utils/color.js +74 -65
  91. package/dist-npm/utils/colorize.js +156 -124
  92. package/dist-npm/utils/component.js +657 -532
  93. package/dist-npm/utils/constants.js +63 -64
  94. package/dist-npm/utils/core.js +3 -2
  95. package/dist-npm/utils/decoder.js +223 -244
  96. package/dist-npm/utils/error.js +9 -4
  97. package/dist-npm/utils/errors.js +4 -14
  98. package/dist-npm/utils/format.js +24 -19
  99. package/dist-npm/utils/keypress.js +414 -316
  100. package/dist-npm/utils/log.js +15 -11
  101. package/dist-npm/utils/mapping.js +52 -45
  102. package/dist-npm/utils/messages.js +183 -183
  103. package/dist-npm/utils/platforms.js +20 -16
  104. package/dist-npm/utils/prompt-tmp.js +286 -235
  105. package/dist-npm/utils/prompt-two.js +286 -235
  106. package/dist-npm/utils/readline.js +7 -5
  107. package/dist-npm/utils/skeleton.js +170 -130
  108. package/dist-npm/utils/stream.js +2 -2
  109. package/dist-npm/utils/string.js +58 -44
  110. package/dist-npm/utils/terminal.js +34 -23
  111. package/dist-npm/utils/tree.js +41 -30
  112. package/dist-npm/utils/types.js +1 -0
  113. package/dist-npm/utils/utils.js +8 -8
  114. package/dist-npm/utils/variants.js +44 -36
  115. package/package.json +20 -28
@@ -1,68 +1,67 @@
1
1
  export const LogLevels = {
2
- silent: Number.NEGATIVE_INFINITY,
3
- fatal: 0,
4
- error: 0,
5
- warn: 1,
6
- log: 2,
7
- info: 3,
8
- success: 3,
9
- fail: 3,
10
- ready: 3,
11
- start: 3,
12
- box: 3,
13
- debug: 4,
14
- trace: 5,
15
- verbose: Number.POSITIVE_INFINITY
2
+ silent: Number.NEGATIVE_INFINITY,
3
+ fatal: 0,
4
+ error: 0,
5
+ warn: 1,
6
+ log: 2,
7
+ info: 3,
8
+ success: 3,
9
+ fail: 3,
10
+ ready: 3,
11
+ start: 3,
12
+ box: 3,
13
+ debug: 4,
14
+ trace: 5,
15
+ verbose: Number.POSITIVE_INFINITY,
16
16
  };
17
17
  export const LogTypes = {
18
-
19
- silent: {
20
- level: -1
21
- },
22
-
23
- fatal: {
24
- level: LogLevels.fatal
25
- },
26
- error: {
27
- level: LogLevels.error
28
- },
29
-
30
- warn: {
31
- level: LogLevels.warn
32
- },
33
-
34
- log: {
35
- level: LogLevels.log
36
- },
37
-
38
- info: {
39
- level: LogLevels.info
40
- },
41
- success: {
42
- level: LogLevels.success
43
- },
44
- fail: {
45
- level: LogLevels.fail
46
- },
47
- ready: {
48
- level: LogLevels.info
49
- },
50
- start: {
51
- level: LogLevels.info
52
- },
53
- box: {
54
- level: LogLevels.info
55
- },
56
-
57
- debug: {
58
- level: LogLevels.debug
59
- },
60
-
61
- trace: {
62
- level: LogLevels.trace
63
- },
64
-
65
- verbose: {
66
- level: LogLevels.verbose
67
- }
18
+ silent: {
19
+ level: -1,
20
+ },
21
+
22
+ fatal: {
23
+ level: LogLevels.fatal,
24
+ },
25
+ error: {
26
+ level: LogLevels.error,
27
+ },
28
+
29
+ warn: {
30
+ level: LogLevels.warn,
31
+ },
32
+
33
+ log: {
34
+ level: LogLevels.log,
35
+ },
36
+
37
+ info: {
38
+ level: LogLevels.info,
39
+ },
40
+ success: {
41
+ level: LogLevels.success,
42
+ },
43
+ fail: {
44
+ level: LogLevels.fail,
45
+ },
46
+ ready: {
47
+ level: LogLevels.info,
48
+ },
49
+ start: {
50
+ level: LogLevels.info,
51
+ },
52
+ box: {
53
+ level: LogLevels.info,
54
+ },
55
+
56
+ debug: {
57
+ level: LogLevels.debug,
58
+ },
59
+
60
+ trace: {
61
+ level: LogLevels.trace,
62
+ },
63
+
64
+ verbose: {
65
+ level: LogLevels.verbose,
66
+ },
68
67
  };
@@ -1,2 +1,3 @@
1
- export { createRelinka } from "../components/prompts/relinka.js";
2
- export * from "../components/instance/shared.js";
1
+ export {createRelinka} from '../components/prompts/relinka.js';
2
+ export * from '../components/instance/shared.js';
3
+
@@ -1,281 +1,260 @@
1
- import { Buffer } from "safe-buffer";
1
+ import {Buffer} from 'safe-buffer';
2
+
3
+ const isString = (a) => typeof a === 'string';
2
4
  const isEncoding = Buffer.isEncoding || function(encoding) {
3
- const enc = String(encoding).toLowerCase();
4
- switch (enc) {
5
- case "hex":
6
- case "utf8":
7
- case "utf-8":
8
- case "ascii":
9
- case "binary":
10
- case "base64":
11
- case "ucs2":
12
- case "ucs-2":
13
- case "utf16le":
14
- case "utf-16le":
15
- case "raw":
16
- return true;
5
+ const enc = String(encoding).toLowerCase();
6
+
7
+ switch(enc) {
8
+ case 'hex':
9
+ case 'utf8':
10
+ case 'utf-8':
11
+ case 'ascii':
12
+ case 'binary':
13
+ case 'base64':
14
+ case 'ucs2':
15
+ case 'ucs-2':
16
+ case 'utf16le':
17
+ case 'utf-16le':
18
+ case 'raw':
19
+ return true;
20
+
17
21
  default:
18
- return false;
19
- }
22
+ return false;
23
+ }
20
24
  };
25
+
21
26
  function _normalizeEncoding(enc) {
22
- if (!enc) {
23
- return "utf8";
24
- }
25
- let retried = false;
26
- let encoding = String(enc);
27
- while (true) {
28
- switch (encoding) {
29
- case "utf8":
30
- case "utf-8":
31
- return "utf8";
32
- case "ucs2":
33
- case "ucs-2":
34
- case "utf16le":
35
- case "utf-16le":
36
- return "utf16le";
37
- case "latin1":
38
- case "binary":
39
- return "latin1";
40
- case "base64":
41
- case "ascii":
42
- case "hex":
43
- return encoding;
44
- default:
45
- if (retried) {
46
- return void 0;
27
+ if (!enc) {
28
+ return 'utf8';
29
+ }
30
+
31
+ let retried = false;
32
+ let encoding = String(enc);
33
+
34
+ while (true) {
35
+ switch(encoding) {
36
+ case 'utf8':
37
+ case 'utf-8':
38
+ return 'utf8';
39
+
40
+ case 'ucs2':
41
+ case 'ucs-2':
42
+ case 'utf16le':
43
+ case 'utf-16le':
44
+ return 'utf16le';
45
+
46
+ case 'latin1':
47
+ case 'binary':
48
+ return 'latin1';
49
+
50
+ case 'base64':
51
+ case 'ascii':
52
+ case 'hex':
53
+ return encoding;
54
+
55
+ default:
56
+ if (retried) {
57
+ return void 0;
58
+ }
59
+
60
+ encoding = encoding.toLowerCase();
61
+ retried = true;
47
62
  }
48
- encoding = encoding.toLowerCase();
49
- retried = true;
50
63
  }
51
- }
52
64
  }
65
+
53
66
  function normalizeEncoding(enc) {
54
- const nenc = _normalizeEncoding(enc);
55
- if (typeof nenc !== "string" && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) {
56
- throw new Error("Unknown encoding: " + enc);
57
- }
58
- return nenc || enc;
67
+ const nenc = _normalizeEncoding(enc);
68
+
69
+ if (!isString(nenc) && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) {
70
+ throw Error(`Unknown encoding: ${enc}`);
71
+ }
72
+
73
+ return nenc || enc;
59
74
  }
75
+
60
76
  export class StringDecoder {
61
- encoding;
62
- lastNeed;
63
- lastTotal;
64
- lastChar;
65
- fillLast;
66
- text;
67
- endFn;
68
- writeFn;
69
- constructor(encoding) {
70
- this.encoding = normalizeEncoding(encoding);
71
- let nb;
72
- switch (this.encoding) {
73
- case "utf16le":
74
- this.text = utf16Text;
75
- this.endFn = utf16End;
76
- nb = 4;
77
- break;
78
- case "utf8":
79
- this.fillLast = utf8FillLast;
80
- nb = 4;
81
- break;
82
- case "base64":
83
- this.text = base64Text;
84
- this.endFn = base64End;
85
- nb = 3;
86
- break;
87
- default:
88
- this.writeFn = simpleWrite;
89
- this.endFn = simpleEnd;
90
- return;
77
+ encoding;
78
+ lastNeed;
79
+ lastTotal;
80
+ lastChar;
81
+ fillLast;
82
+ text;
83
+ endFn;
84
+ writeFn;
85
+ constructor(encoding) {
86
+ this.encoding = normalizeEncoding(encoding);
87
+ let nb;
88
+
89
+ switch(this.encoding) {
90
+ case 'utf16le':
91
+ this.text = utf16Text;
92
+ this.endFn = utf16End;
93
+ nb = 4;
94
+ break;
95
+
96
+ case 'utf8':
97
+ this.fillLast = utf8FillLast;
98
+ nb = 4;
99
+ break;
100
+
101
+ case 'base64':
102
+ this.text = base64Text;
103
+ this.endFn = base64End;
104
+ nb = 3;
105
+ break;
106
+
107
+ default:
108
+ this.writeFn = simpleWrite;
109
+ this.endFn = simpleEnd;
110
+ return;
111
+ }
112
+
113
+ this.lastNeed = 0;
114
+ this.lastTotal = 0;
115
+ this.lastChar = Buffer.allocUnsafe(nb);
116
+ this.writeFn = this.write.bind(this);
91
117
  }
92
- this.lastNeed = 0;
93
- this.lastTotal = 0;
94
- this.lastChar = Buffer.allocUnsafe(nb);
95
- this.writeFn = this.write.bind(this);
96
- }
118
+
97
119
  write(buf) {
98
- if (buf.length === 0) {
99
- return "";
100
- }
101
- let r;
102
- let i;
103
- if (this.lastNeed) {
104
- r = this.fillLast(buf);
105
- if (r === void 0) {
106
- return "";
107
- }
108
- i = this.lastNeed;
109
- this.lastNeed = 0;
110
- } else {
111
- i = 0;
112
- }
113
- if (i < buf.length) {
114
- return r ? r + (this.text ? this.text(buf, i) : "") : this.text ? this.text(buf, i) : "";
120
+ if (!buf.length) {
121
+ return '';
122
+ }
123
+
124
+ let r;
125
+ let i;
126
+
127
+ if (this.lastNeed) {
128
+ r = this.fillLast(buf);
129
+ if (r === void 0) {
130
+ return '';
131
+ }
132
+
133
+ i = this.lastNeed;
134
+ this.lastNeed = 0;
135
+ } else {
136
+ i = 0;
137
+ }
138
+
139
+ if (i < buf.length) {
140
+ return r ? r + (this.text ? this.text(buf, i) : '') : this.text ? this.text(buf, i) : '';
141
+ }
142
+
143
+ return r || '';
115
144
  }
116
- return r || "";
117
- }
118
- /**
145
+ /**
119
146
  * Ends the decoding and returns any remaining characters.
120
147
  * @param buf - Optional buffer to write before ending.
121
148
  * @returns The final decoded string.
122
149
  */
123
- end(buf) {
124
- const result = this.endFn?.(buf) ?? "";
125
- return result;
126
- }
127
- }
128
- function utf8FillLast(buf) {
129
- const p = this.lastTotal - this.lastNeed;
130
- const r = utf8CheckExtraBytes(this, buf, p);
131
- if (r !== void 0) {
132
- return r;
133
- }
134
- if (this.lastNeed <= buf.length) {
135
- buf.copy(this.lastChar, p, 0, this.lastNeed);
136
- return this.lastChar.toString(this.encoding, 0, this.lastTotal);
137
- }
138
- buf.copy(this.lastChar, p, 0, buf.length);
139
- this.lastNeed -= buf.length;
140
- }
141
- function utf8Text(buf, i) {
142
- const total = utf8CheckIncomplete(this, buf, i);
143
- if (!this.lastNeed) {
144
- return buf.toString("utf8", i);
145
- }
146
- this.lastTotal = total;
147
- const end = buf.length - (total - this.lastNeed);
148
- buf.copy(this.lastChar, 0, end);
149
- return buf.toString("utf8", i, end);
150
- }
151
- function utf8End(buf) {
152
- const r = buf?.length ? this.write(buf) : "";
153
- if (this.lastNeed) {
154
- return r + "\uFFFD";
155
- }
156
- return r;
157
- }
158
- function utf8CheckByte(byte) {
159
- if (byte <= 127) {
160
- return 0;
161
- } else if (byte >> 5 === 6) {
162
- return 2;
163
- } else if (byte >> 4 === 14) {
164
- return 3;
165
- } else if (byte >> 3 === 30) {
166
- return 4;
167
- }
168
- return byte >> 6 === 2 ? -1 : -2;
169
- }
170
- function utf8CheckIncomplete(self, buf, i) {
171
- let j = buf.length - 1;
172
- if (j < i) {
173
- return 0;
174
- }
175
- let nb = utf8CheckByte(buf[j]);
176
- if (nb >= 0) {
177
- if (nb > 0) {
178
- self.lastNeed = nb - 1;
150
+ end(buf) {
151
+ return this.endFn?.(buf) ?? '';
179
152
  }
180
- return nb;
181
- }
182
- if (--j < i || nb === -2) {
183
- return 0;
184
- }
185
- nb = utf8CheckByte(buf[j]);
186
- if (nb >= 0) {
187
- if (nb > 0) {
188
- self.lastNeed = nb - 2;
153
+ }function utf8FillLast(buf) {
154
+ const p = this.lastTotal - this.lastNeed;
155
+ const r = utf8CheckExtraBytes(this, buf);
156
+
157
+ if (r !== void 0) {
158
+ return r;
189
159
  }
190
- return nb;
191
- }
192
- if (--j < i || nb === -2) {
193
- return 0;
194
- }
195
- nb = utf8CheckByte(buf[j]);
196
- if (nb >= 0) {
197
- if (nb > 0) {
198
- if (nb === 2) {
199
- nb = 0;
200
- } else {
201
- self.lastNeed = nb - 3;
202
- }
160
+
161
+ if (this.lastNeed <= buf.length) {
162
+ buf.copy(this.lastChar, p, 0, this.lastNeed);
163
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
203
164
  }
204
- return nb;
205
- }
206
- return 0;
165
+
166
+ buf.copy(this.lastChar, p, 0, buf.length);
167
+ this.lastNeed -= buf.length;
207
168
  }
208
- function utf8CheckExtraBytes(self, buf, p) {
209
- if ((buf[0] & 192) !== 128) {
210
- self.lastNeed = 0;
211
- return "\uFFFD";
212
- }
213
- if (self.lastNeed > 1 && buf.length > 1) {
214
- if ((buf[1] & 192) !== 128) {
215
- self.lastNeed = 1;
216
- return "\uFFFD";
169
+
170
+ function utf8CheckExtraBytes(self, buf) {
171
+ if ((buf[0] & 192) !== 128) {
172
+ self.lastNeed = 0;
173
+ return '\uFFFD';
217
174
  }
218
- if (self.lastNeed > 2 && buf.length > 2) {
219
- if ((buf[2] & 192) !== 128) {
220
- self.lastNeed = 2;
221
- return "\uFFFD";
222
- }
175
+
176
+ if (self.lastNeed > 1 && buf.length > 1) {
177
+ if ((buf[1] & 192) !== 128) {
178
+ self.lastNeed = 1;
179
+ return '\uFFFD';
180
+ }
181
+
182
+ if (self.lastNeed > 2 && buf.length > 2 && (buf[2] & 192) !== 128) {
183
+ self.lastNeed = 2;
184
+ return '\uFFFD';
185
+ }
223
186
  }
224
- }
225
187
  }
188
+
226
189
  function utf16Text(buf, i) {
227
- if ((buf.length - i) % 2 === 0) {
228
- const r = buf.toString("utf16le", i);
229
- if (r) {
230
- const c = r.charCodeAt(r.length - 1);
231
- if (c >= 55296 && c <= 56319) {
232
- this.lastNeed = 2;
233
- this.lastTotal = 4;
234
- this.lastChar[0] = buf[buf.length - 2];
235
- this.lastChar[1] = buf[buf.length - 1];
236
- return r.slice(0, -1);
237
- }
190
+ if (!((buf.length - i) % 2)) {
191
+ const r = buf.toString('utf16le', i);
192
+
193
+ if (r) {
194
+ const c = r.charCodeAt(r.length - 1);
195
+
196
+ if (c >= 55_296 && c <= 56_319) {
197
+ this.lastNeed = 2;
198
+ this.lastTotal = 4;
199
+ this.lastChar[0] = buf[buf.length - 2];
200
+ this.lastChar[1] = buf[buf.length - 1];
201
+ return r.slice(0, -1);
202
+ }
203
+ }
204
+
205
+ return r;
238
206
  }
239
- return r;
240
- }
241
- this.lastNeed = 1;
242
- this.lastTotal = 2;
243
- this.lastChar[0] = buf[buf.length - 1];
244
- return buf.toString("utf16le", i, buf.length - 1);
207
+
208
+ this.lastNeed = 1;
209
+ this.lastTotal = 2;
210
+ this.lastChar[0] = buf[buf.length - 1];
211
+ return buf.toString('utf16le', i, buf.length - 1);
245
212
  }
213
+
246
214
  function utf16End(buf) {
247
- const r = buf?.length ? this.write(buf) : "";
248
- if (this.lastNeed) {
249
- const end = this.lastTotal - this.lastNeed;
250
- return r + this.lastChar.toString("utf16le", 0, end);
251
- }
252
- return r;
215
+ const r = buf?.length ? this.write(buf) : '';
216
+
217
+ if (this.lastNeed) {
218
+ const end = this.lastTotal - this.lastNeed;
219
+ return r + this.lastChar.toString('utf16le', 0, end);
220
+ }
221
+
222
+ return r;
253
223
  }
224
+
254
225
  function base64Text(buf, i) {
255
- const n = (buf.length - i) % 3;
256
- if (n === 0) {
257
- return buf.toString("base64", i);
258
- }
259
- this.lastNeed = 3 - n;
260
- this.lastTotal = 3;
261
- if (n === 1) {
262
- this.lastChar[0] = buf[buf.length - 1];
263
- } else {
264
- this.lastChar[0] = buf[buf.length - 2];
265
- this.lastChar[1] = buf[buf.length - 1];
266
- }
267
- return buf.toString("base64", i, buf.length - n);
226
+ const n = (buf.length - i) % 3;
227
+
228
+ if (!n) {
229
+ return buf.toString('base64', i);
230
+ }
231
+
232
+ this.lastNeed = 3 - n;
233
+ this.lastTotal = 3;
234
+ if (n === 1) {
235
+ this.lastChar[0] = buf[buf.length - 1];
236
+ } else {
237
+ this.lastChar[0] = buf[buf.length - 2];
238
+ this.lastChar[1] = buf[buf.length - 1];
239
+ }
240
+
241
+ return buf.toString('base64', i, buf.length - n);
268
242
  }
243
+
269
244
  function base64End(buf) {
270
- const r = buf?.length ? this.write(buf) : "";
271
- if (this.lastNeed) {
272
- return r + this.lastChar.toString("base64", 0, 3 - this.lastNeed);
273
- }
274
- return r;
245
+ const r = buf?.length ? this.write(buf) : '';
246
+
247
+ if (this.lastNeed) {
248
+ return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
249
+ }
250
+
251
+ return r;
275
252
  }
253
+
276
254
  function simpleWrite(buf) {
277
- return buf.toString(this.encoding);
255
+ return buf.toString(this.encoding);
278
256
  }
257
+
279
258
  function simpleEnd(buf) {
280
- return buf?.length ? this.write(buf) : "";
259
+ return buf?.length ? this.write(buf) : '';
281
260
  }
@@ -1,6 +1,11 @@
1
- import { sep } from "node:path";
1
+ import {sep} from 'node:path';
2
+ import process from 'node:process';
3
+
2
4
  export function parseStack(stack) {
3
- const cwd = process.cwd() + sep;
4
- const lines = stack.split("\n").splice(1).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
5
- return lines;
5
+ const cwd = process.cwd() + sep;
6
+
7
+ return stack
8
+ .split('\n')
9
+ .splice(1)
10
+ .map((l) => l.trim().replace('file://', '').replace(cwd, ''));
6
11
  }