@chainlink/external-adapter-framework 2.12.0 → 2.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/config/index.d.ts +9 -0
- package/config/index.js +12 -1
- package/config/index.js.map +1 -1
- package/generator-adapter/generators/app/templates/src/config/index.ts.ejs +3 -0
- package/generator-adapter/node_modules/.yarn-integrity +31 -35
- package/generator-adapter/node_modules/@inquirer/ansi/package.json +28 -26
- package/generator-adapter/node_modules/@inquirer/checkbox/dist/index.d.ts +6 -1
- package/generator-adapter/node_modules/@inquirer/checkbox/dist/index.js +30 -10
- package/generator-adapter/node_modules/@inquirer/checkbox/package.json +23 -21
- package/generator-adapter/node_modules/@inquirer/confirm/package.json +21 -19
- package/generator-adapter/node_modules/@inquirer/core/dist/index.d.ts +1 -1
- package/generator-adapter/node_modules/@inquirer/core/dist/index.js +1 -1
- package/generator-adapter/node_modules/@inquirer/core/dist/lib/create-prompt.js +51 -25
- package/generator-adapter/node_modules/@inquirer/core/dist/lib/key.d.ts +2 -0
- package/generator-adapter/node_modules/@inquirer/core/dist/lib/key.js +1 -0
- package/generator-adapter/node_modules/@inquirer/core/dist/lib/utils.js +1 -1
- package/generator-adapter/node_modules/@inquirer/core/package.json +22 -20
- package/generator-adapter/node_modules/@inquirer/editor/dist/index.d.ts +3 -0
- package/generator-adapter/node_modules/@inquirer/editor/dist/index.js +5 -5
- package/generator-adapter/node_modules/@inquirer/editor/package.json +22 -20
- package/generator-adapter/node_modules/@inquirer/expand/package.json +21 -19
- package/generator-adapter/node_modules/@inquirer/external-editor/package.json +33 -31
- package/generator-adapter/node_modules/@inquirer/figures/package.json +18 -16
- package/generator-adapter/node_modules/@inquirer/input/dist/index.js +5 -3
- package/generator-adapter/node_modules/@inquirer/input/package.json +21 -19
- package/generator-adapter/node_modules/@inquirer/number/package.json +21 -19
- package/generator-adapter/node_modules/@inquirer/password/dist/index.d.ts +6 -1
- package/generator-adapter/node_modules/@inquirer/password/dist/index.js +7 -2
- package/generator-adapter/node_modules/@inquirer/password/package.json +22 -20
- package/generator-adapter/node_modules/@inquirer/prompts/README.md +15 -0
- package/generator-adapter/node_modules/@inquirer/prompts/package.json +31 -29
- package/generator-adapter/node_modules/@inquirer/rawlist/README.md +4 -0
- package/generator-adapter/node_modules/@inquirer/rawlist/dist/index.d.ts +9 -2
- package/generator-adapter/node_modules/@inquirer/rawlist/dist/index.js +24 -7
- package/generator-adapter/node_modules/@inquirer/rawlist/package.json +21 -19
- package/generator-adapter/node_modules/@inquirer/search/README.md +2 -1
- package/generator-adapter/node_modules/@inquirer/search/dist/index.d.ts +1 -0
- package/generator-adapter/node_modules/@inquirer/search/dist/index.js +11 -4
- package/generator-adapter/node_modules/@inquirer/search/package.json +22 -20
- package/generator-adapter/node_modules/@inquirer/select/dist/index.d.ts +5 -2
- package/generator-adapter/node_modules/@inquirer/select/dist/index.js +28 -11
- package/generator-adapter/node_modules/@inquirer/select/package.json +23 -21
- package/generator-adapter/node_modules/@inquirer/type/package.json +18 -16
- package/generator-adapter/node_modules/@types/node/README.md +1 -1
- package/generator-adapter/node_modules/@types/node/http.d.ts +1 -1
- package/generator-adapter/node_modules/@types/node/package.json +2 -2
- package/generator-adapter/node_modules/@types/node/stream/web.d.ts +1 -1
- package/generator-adapter/node_modules/@types/node/test.d.ts +2 -1
- package/generator-adapter/node_modules/@types/node/web-globals/fetch.d.ts +12 -0
- package/generator-adapter/node_modules/@yeoman/adapter/dist/adapter.d.ts +0 -3
- package/generator-adapter/node_modules/@yeoman/adapter/dist/adapter.js +1 -0
- package/generator-adapter/node_modules/@yeoman/adapter/dist/adapter.js.map +1 -1
- package/generator-adapter/node_modules/@yeoman/adapter/dist/log.d.ts +0 -2
- package/generator-adapter/node_modules/@yeoman/adapter/dist/log.js.map +1 -1
- package/generator-adapter/node_modules/@yeoman/adapter/dist/queued-adapter.d.ts +0 -1
- package/generator-adapter/node_modules/@yeoman/adapter/dist/queued-adapter.js.map +1 -1
- package/generator-adapter/node_modules/@yeoman/adapter/dist/testing/test-adapter.d.ts +0 -1
- package/generator-adapter/node_modules/@yeoman/adapter/dist/testing/test-adapter.js.map +1 -1
- package/generator-adapter/node_modules/@yeoman/adapter/package.json +11 -11
- package/generator-adapter/node_modules/ansi-styles/index.d.ts +341 -232
- package/generator-adapter/node_modules/ansi-styles/index.js +130 -190
- package/generator-adapter/node_modules/ansi-styles/license +1 -1
- package/generator-adapter/node_modules/ansi-styles/package.json +10 -8
- package/generator-adapter/node_modules/ansi-styles/readme.md +32 -53
- package/generator-adapter/node_modules/chalk/package.json +3 -3
- package/generator-adapter/node_modules/chalk/readme.md +25 -53
- package/generator-adapter/node_modules/chalk/source/index.d.ts +6 -1
- package/generator-adapter/node_modules/chalk/source/vendor/supports-color/browser.js +6 -2
- package/generator-adapter/node_modules/chalk/source/vendor/supports-color/index.js +10 -2
- package/generator-adapter/node_modules/fast-string-truncated-width/dist/index.d.ts +4 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/dist/index.js +111 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/dist/types.d.ts +19 -0
- package/generator-adapter/node_modules/{p-queue/dist/options copy.js → fast-string-truncated-width/dist/types.js} +1 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/dist/utils.d.ts +4 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/license +21 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/package.json +35 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/readme.md +59 -0
- package/generator-adapter/node_modules/fast-string-width/dist/index.d.ts +4 -0
- package/generator-adapter/node_modules/fast-string-width/dist/index.js +14 -0
- package/generator-adapter/node_modules/fast-string-width/license +21 -0
- package/generator-adapter/node_modules/fast-string-width/package.json +34 -0
- package/generator-adapter/node_modules/fast-string-width/readme.md +42 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/LICENSE +23 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/README.md +26 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/lib/main.d.ts +6 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/lib/main.js +219 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/lib/main.js.map +1 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/package.json +51 -0
- package/generator-adapter/node_modules/iconv-lite/lib/index.d.ts +114 -26
- package/generator-adapter/node_modules/iconv-lite/lib/index.js +39 -40
- package/generator-adapter/node_modules/iconv-lite/package.json +13 -2
- package/generator-adapter/node_modules/iconv-lite/types/encodings.d.ts +423 -0
- package/generator-adapter/node_modules/inquirer/dist/types.d.ts +12 -11
- package/generator-adapter/node_modules/inquirer/dist/ui/prompt.js +9 -1
- package/generator-adapter/node_modules/inquirer/dist/ui/skipped-renderer.d.ts +13 -0
- package/generator-adapter/node_modules/inquirer/dist/ui/skipped-renderer.js +57 -0
- package/generator-adapter/node_modules/inquirer/package.json +21 -19
- package/generator-adapter/node_modules/log-symbols/package.json +1 -1
- package/generator-adapter/node_modules/log-symbols/symbols.js +1 -1
- package/generator-adapter/node_modules/mem-fs/dist/index.d.ts +0 -2
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/LICENSE +21 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/README.md +447 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/index.js +346 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/lib/inspect-stream.js +13 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/lib/is-stream.js +15 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/lib/normalize.js +9 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/package.json +59 -0
- package/generator-adapter/node_modules/mem-fs/package.json +9 -9
- package/generator-adapter/node_modules/ora/index.d.ts +3 -1
- package/generator-adapter/node_modules/ora/index.js +299 -109
- package/generator-adapter/node_modules/ora/package.json +3 -4
- package/generator-adapter/node_modules/ora/readme.md +24 -0
- package/generator-adapter/node_modules/p-queue/dist/index.js +145 -22
- package/generator-adapter/node_modules/p-queue/dist/options.d.ts +17 -1
- package/generator-adapter/node_modules/p-queue/package.json +1 -1
- package/generator-adapter/node_modules/p-queue/readme.md +32 -1
- package/generator-adapter/node_modules/stdin-discarder/index.js +50 -22
- package/generator-adapter/node_modules/stdin-discarder/package.json +1 -1
- package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/package.json +3 -3
- package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/readme.md +53 -25
- package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/source/index.d.ts +1 -6
- package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/source/vendor/supports-color/browser.js +2 -6
- package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/source/vendor/supports-color/index.js +2 -10
- package/generator-adapter/package.json +3 -3
- package/package.json +12 -12
- package/transports/websocket.d.ts +5 -0
- package/transports/websocket.js +25 -13
- package/transports/websocket.js.map +1 -1
- package/generator-adapter/node_modules/emoji-regex/LICENSE-MIT.txt +0 -20
- package/generator-adapter/node_modules/emoji-regex/README.md +0 -107
- package/generator-adapter/node_modules/emoji-regex/index.d.ts +0 -3
- package/generator-adapter/node_modules/emoji-regex/index.js +0 -4
- package/generator-adapter/node_modules/emoji-regex/index.mjs +0 -4
- package/generator-adapter/node_modules/emoji-regex/package.json +0 -45
- package/generator-adapter/node_modules/iconv-lite/Changelog.md +0 -236
- package/generator-adapter/node_modules/jake/node_modules/ansi-styles/index.d.ts +0 -345
- package/generator-adapter/node_modules/jake/node_modules/ansi-styles/index.js +0 -163
- package/generator-adapter/node_modules/jake/node_modules/ansi-styles/license +0 -9
- package/generator-adapter/node_modules/jake/node_modules/ansi-styles/package.json +0 -56
- package/generator-adapter/node_modules/jake/node_modules/ansi-styles/readme.md +0 -152
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/browser-symbols.js +0 -4
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/browser.js +0 -1
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/index.d.ts +0 -22
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/index.js +0 -1
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/license +0 -9
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/package.json +0 -60
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/readme.md +0 -39
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/symbols.js +0 -14
- package/generator-adapter/node_modules/ora/node_modules/strip-ansi/index.d.ts +0 -15
- package/generator-adapter/node_modules/ora/node_modules/strip-ansi/index.js +0 -14
- package/generator-adapter/node_modules/ora/node_modules/strip-ansi/license +0 -9
- package/generator-adapter/node_modules/ora/node_modules/strip-ansi/package.json +0 -59
- package/generator-adapter/node_modules/ora/node_modules/strip-ansi/readme.md +0 -37
- package/generator-adapter/node_modules/p-queue/dist/options copy.d.ts +0 -121
- package/generator-adapter/node_modules/wrap-ansi/index.d.ts +0 -41
- package/generator-adapter/node_modules/wrap-ansi/index.js +0 -222
- package/generator-adapter/node_modules/wrap-ansi/license +0 -9
- package/generator-adapter/node_modules/wrap-ansi/node_modules/string-width/index.d.ts +0 -39
- package/generator-adapter/node_modules/wrap-ansi/node_modules/string-width/index.js +0 -82
- package/generator-adapter/node_modules/wrap-ansi/node_modules/string-width/license +0 -9
- package/generator-adapter/node_modules/wrap-ansi/node_modules/string-width/package.json +0 -64
- package/generator-adapter/node_modules/wrap-ansi/node_modules/string-width/readme.md +0 -66
- package/generator-adapter/node_modules/wrap-ansi/package.json +0 -69
- package/generator-adapter/node_modules/wrap-ansi/readme.md +0 -75
- /package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/license +0 -0
- /package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/source/index.js +0 -0
- /package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/source/utilities.js +0 -0
- /package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +0 -0
- /package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/source/vendor/ansi-styles/index.js +0 -0
- /package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/source/vendor/supports-color/browser.d.ts +0 -0
- /package/generator-adapter/node_modules/{ora → yeoman-generator}/node_modules/chalk/source/vendor/supports-color/index.d.ts +0 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import stringWidth from 'fast-string-width';
|
|
2
|
+
const ESC = '\x1B';
|
|
3
|
+
const CSI = '\x9B';
|
|
4
|
+
const END_CODE = 39;
|
|
5
|
+
const ANSI_ESCAPE_BELL = '\u0007';
|
|
6
|
+
const ANSI_CSI = '[';
|
|
7
|
+
const ANSI_OSC = ']';
|
|
8
|
+
const ANSI_SGR_TERMINATOR = 'm';
|
|
9
|
+
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
10
|
+
const GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, 'y');
|
|
11
|
+
const getClosingCode = (openingCode) => {
|
|
12
|
+
if (openingCode >= 30 && openingCode <= 37)
|
|
13
|
+
return 39;
|
|
14
|
+
if (openingCode >= 90 && openingCode <= 97)
|
|
15
|
+
return 39;
|
|
16
|
+
if (openingCode >= 40 && openingCode <= 47)
|
|
17
|
+
return 49;
|
|
18
|
+
if (openingCode >= 100 && openingCode <= 107)
|
|
19
|
+
return 49;
|
|
20
|
+
if (openingCode === 1 || openingCode === 2)
|
|
21
|
+
return 22;
|
|
22
|
+
if (openingCode === 3)
|
|
23
|
+
return 23;
|
|
24
|
+
if (openingCode === 4)
|
|
25
|
+
return 24;
|
|
26
|
+
if (openingCode === 7)
|
|
27
|
+
return 27;
|
|
28
|
+
if (openingCode === 8)
|
|
29
|
+
return 28;
|
|
30
|
+
if (openingCode === 9)
|
|
31
|
+
return 29;
|
|
32
|
+
if (openingCode === 0)
|
|
33
|
+
return 0;
|
|
34
|
+
return undefined;
|
|
35
|
+
};
|
|
36
|
+
const wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
37
|
+
const wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
38
|
+
const wrapWord = (rows, word, columns) => {
|
|
39
|
+
const characters = word[Symbol.iterator]();
|
|
40
|
+
let isInsideEscape = false;
|
|
41
|
+
let isInsideLinkEscape = false;
|
|
42
|
+
let lastRow = rows.at(-1);
|
|
43
|
+
let visible = lastRow === undefined ? 0 : stringWidth(lastRow);
|
|
44
|
+
let currentCharacter = characters.next();
|
|
45
|
+
let nextCharacter = characters.next();
|
|
46
|
+
let rawCharacterIndex = 0;
|
|
47
|
+
while (!currentCharacter.done) {
|
|
48
|
+
const character = currentCharacter.value;
|
|
49
|
+
const characterLength = stringWidth(character);
|
|
50
|
+
if (visible + characterLength <= columns) {
|
|
51
|
+
rows[rows.length - 1] += character;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
rows.push(character);
|
|
55
|
+
visible = 0;
|
|
56
|
+
}
|
|
57
|
+
if (character === ESC || character === CSI) {
|
|
58
|
+
isInsideEscape = true;
|
|
59
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
60
|
+
}
|
|
61
|
+
if (isInsideEscape) {
|
|
62
|
+
if (isInsideLinkEscape) {
|
|
63
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
64
|
+
isInsideEscape = false;
|
|
65
|
+
isInsideLinkEscape = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (character === ANSI_SGR_TERMINATOR) {
|
|
69
|
+
isInsideEscape = false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
visible += characterLength;
|
|
74
|
+
if (visible === columns && !nextCharacter.done) {
|
|
75
|
+
rows.push('');
|
|
76
|
+
visible = 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
currentCharacter = nextCharacter;
|
|
80
|
+
nextCharacter = characters.next();
|
|
81
|
+
rawCharacterIndex += character.length;
|
|
82
|
+
}
|
|
83
|
+
lastRow = rows.at(-1);
|
|
84
|
+
if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
85
|
+
rows[rows.length - 2] += rows.pop();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const stringVisibleTrimSpacesRight = (string) => {
|
|
89
|
+
const words = string.split(' ');
|
|
90
|
+
let last = words.length;
|
|
91
|
+
while (last) {
|
|
92
|
+
if (stringWidth(words[last - 1])) {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
last--;
|
|
96
|
+
}
|
|
97
|
+
if (last === words.length) {
|
|
98
|
+
return string;
|
|
99
|
+
}
|
|
100
|
+
return words.slice(0, last).join(' ') + words.slice(last).join('');
|
|
101
|
+
};
|
|
102
|
+
const exec = (string, columns, options = {}) => {
|
|
103
|
+
if (options.trim !== false && string.trim() === '') {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
let returnValue = '';
|
|
107
|
+
let escapeCode;
|
|
108
|
+
let escapeUrl;
|
|
109
|
+
const words = string.split(' ');
|
|
110
|
+
let rows = [''];
|
|
111
|
+
let rowLength = 0;
|
|
112
|
+
for (let index = 0; index < words.length; index++) {
|
|
113
|
+
const word = words[index];
|
|
114
|
+
if (options.trim !== false) {
|
|
115
|
+
const row = rows.at(-1) ?? '';
|
|
116
|
+
const trimmed = row.trimStart();
|
|
117
|
+
if (row.length !== trimmed.length) {
|
|
118
|
+
rows[rows.length - 1] = trimmed;
|
|
119
|
+
rowLength = stringWidth(trimmed);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (index !== 0) {
|
|
123
|
+
if (rowLength >= columns &&
|
|
124
|
+
(options.wordWrap === false || options.trim === false)) {
|
|
125
|
+
rows.push('');
|
|
126
|
+
rowLength = 0;
|
|
127
|
+
}
|
|
128
|
+
if (rowLength || options.trim === false) {
|
|
129
|
+
rows[rows.length - 1] += ' ';
|
|
130
|
+
rowLength++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const wordLength = stringWidth(word);
|
|
134
|
+
if (options.hard && wordLength > columns) {
|
|
135
|
+
const remainingColumns = columns - rowLength;
|
|
136
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
137
|
+
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
138
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
139
|
+
rows.push('');
|
|
140
|
+
}
|
|
141
|
+
wrapWord(rows, word, columns);
|
|
142
|
+
rowLength = stringWidth(rows.at(-1) ?? '');
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
146
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
147
|
+
wrapWord(rows, word, columns);
|
|
148
|
+
rowLength = stringWidth(rows.at(-1) ?? '');
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
rows.push('');
|
|
152
|
+
rowLength = 0;
|
|
153
|
+
}
|
|
154
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
155
|
+
wrapWord(rows, word, columns);
|
|
156
|
+
rowLength = stringWidth(rows.at(-1) ?? '');
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
rows[rows.length - 1] += word;
|
|
160
|
+
rowLength += wordLength;
|
|
161
|
+
}
|
|
162
|
+
if (options.trim !== false) {
|
|
163
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
164
|
+
}
|
|
165
|
+
const preString = rows.join('\n');
|
|
166
|
+
let inSurrogate = false;
|
|
167
|
+
for (let i = 0; i < preString.length; i++) {
|
|
168
|
+
const character = preString[i];
|
|
169
|
+
returnValue += character;
|
|
170
|
+
if (!inSurrogate) {
|
|
171
|
+
inSurrogate = character >= '\ud800' && character <= '\udbff';
|
|
172
|
+
if (inSurrogate) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
inSurrogate = false;
|
|
178
|
+
}
|
|
179
|
+
if (character === ESC || character === CSI) {
|
|
180
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
181
|
+
const groupsResult = GROUP_REGEX.exec(preString);
|
|
182
|
+
const groups = groupsResult?.groups;
|
|
183
|
+
if (groups?.code !== undefined) {
|
|
184
|
+
const code = Number.parseFloat(groups.code);
|
|
185
|
+
escapeCode = code === END_CODE ? undefined : code;
|
|
186
|
+
}
|
|
187
|
+
else if (groups?.uri !== undefined) {
|
|
188
|
+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (preString[i + 1] === '\n') {
|
|
192
|
+
if (escapeUrl) {
|
|
193
|
+
returnValue += wrapAnsiHyperlink('');
|
|
194
|
+
}
|
|
195
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
|
|
196
|
+
if (escapeCode && closingCode) {
|
|
197
|
+
returnValue += wrapAnsiCode(closingCode);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (character === '\n') {
|
|
201
|
+
if (escapeCode && getClosingCode(escapeCode)) {
|
|
202
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
203
|
+
}
|
|
204
|
+
if (escapeUrl) {
|
|
205
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return returnValue;
|
|
210
|
+
};
|
|
211
|
+
const CRLF_OR_LF = /\r?\n/;
|
|
212
|
+
export function wrapAnsi(string, columns, options) {
|
|
213
|
+
return String(string)
|
|
214
|
+
.normalize()
|
|
215
|
+
.split(CRLF_OR_LF)
|
|
216
|
+
.map((line) => exec(line, columns, options))
|
|
217
|
+
.join('\n');
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAE5C,MAAM,GAAG,GAAG,MAAM,CAAC;AACnB,MAAM,GAAG,GAAG,MAAM,CAAC;AAEnB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAClC,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,gBAAgB,GAAG,GAAG,QAAQ,KAAK,CAAC;AAC1C,MAAM,WAAW,GAAG,IAAI,MAAM,CAC5B,QAAQ,QAAQ,oBAAoB,gBAAgB,aAAa,gBAAgB,GAAG,EACpF,GAAG,CACJ,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,WAAmB,EAAsB,EAAE;IACjE,IAAI,WAAW,IAAI,EAAE,IAAI,WAAW,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IACtD,IAAI,WAAW,IAAI,EAAE,IAAI,WAAW,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IACtD,IAAI,WAAW,IAAI,EAAE,IAAI,WAAW,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IACtD,IAAI,WAAW,IAAI,GAAG,IAAI,WAAW,IAAI,GAAG;QAAE,OAAO,EAAE,CAAC;IACxD,IAAI,WAAW,KAAK,CAAC,IAAI,WAAW,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACtD,IAAI,WAAW,KAAK,CAAC;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CAAC,CAAC;SAC3C,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fast-wrap-ansi",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"files": [
|
|
5
|
+
"lib"
|
|
6
|
+
],
|
|
7
|
+
"description": "A tiny and fast text wrap library which takes ANSI escapes into account.",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"wrap",
|
|
10
|
+
"ansi",
|
|
11
|
+
"term",
|
|
12
|
+
"colors"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/43081j/fast-wrap-ansi#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/43081j/fast-wrap-ansi/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/43081j/fast-wrap-ansi.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "James Garbutt (https://github.com/43081j)",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "lib/main.js",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"format": "prettier --write src test",
|
|
28
|
+
"lint": "npm run lint:js && npm run lint:format && npm run lint:types",
|
|
29
|
+
"lint:js": "eslint src test",
|
|
30
|
+
"lint:format": "prettier --check src test",
|
|
31
|
+
"lint:types": "npx tsc --noEmit -p tsconfig.test.json",
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"test": "vitest run"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@eslint/js": "^9.32.0",
|
|
37
|
+
"@types/node": "^24.2.0",
|
|
38
|
+
"eslint": "^9.32.0",
|
|
39
|
+
"fast-wrap-ansi-prod": "npm:fast-wrap-ansi@*",
|
|
40
|
+
"picocolors": "^1.1.1",
|
|
41
|
+
"prettier": "^3.6.2",
|
|
42
|
+
"tinybench": "^5.0.1",
|
|
43
|
+
"typescript": "^5.8.3",
|
|
44
|
+
"typescript-eslint": "^8.38.0",
|
|
45
|
+
"vitest": "^3.2.4",
|
|
46
|
+
"wrap-ansi": "^9.0.2"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"fast-string-width": "^3.0.2"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,41 +1,129 @@
|
|
|
1
|
-
|
|
1
|
+
/* ---------------------------------------------------------------------------------------------
|
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
* REQUIREMENT: This definition is dependent on the @types/node definition.
|
|
5
5
|
* Install with `npm install @types/node --save-dev`
|
|
6
|
-
|
|
6
|
+
*-------------------------------------------------------------------------------------------- */
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/* ---------------------------------------------------------------------------------------------
|
|
9
|
+
* This file provides detailed typings for the public API of iconv-lite
|
|
10
|
+
*-------------------------------------------------------------------------------------------- */
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
import type Stream = require("stream")
|
|
13
|
+
import type { Encoding } from "../types/encodings"
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
declare namespace iconv {
|
|
16
|
+
export interface DecodeOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Strip the Byte Order Mark (BOM) from the input,
|
|
19
|
+
* when decoding, if the codec is BOM-aware. @default true
|
|
20
|
+
*/
|
|
21
|
+
stripBOM?: boolean;
|
|
22
|
+
/** Override the default endianness for `UTF-16` and `UTF-32` decodings. */
|
|
23
|
+
defaultEncoding?: "utf16be" | "utf32be";
|
|
24
|
+
}
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
export interface EncodeOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Add a Byte Order Mark (BOM) to the output, when encoding,
|
|
29
|
+
* if the codec is BOM-aware. @default false
|
|
30
|
+
*/
|
|
31
|
+
addBOM?: boolean;
|
|
32
|
+
/** Override the default endianness for `UTF-32` encoding. */
|
|
33
|
+
defaultEncoding?: "utf32be";
|
|
34
|
+
}
|
|
18
35
|
|
|
19
|
-
|
|
36
|
+
export interface EncoderStream {
|
|
37
|
+
write(str: string): Buffer;
|
|
38
|
+
end(): Buffer | undefined;
|
|
39
|
+
}
|
|
20
40
|
|
|
21
|
-
|
|
22
|
-
|
|
41
|
+
export interface DecoderStream {
|
|
42
|
+
write(buf: Buffer): string;
|
|
43
|
+
end(): string | undefined;
|
|
44
|
+
}
|
|
23
45
|
|
|
24
|
-
|
|
25
|
-
|
|
46
|
+
export interface Codec {
|
|
47
|
+
encoder: new (options?: EncodeOptions, codec?: Codec) => EncoderStream;
|
|
48
|
+
decoder: new (options?: DecodeOptions, codec?: Codec) => DecoderStream;
|
|
49
|
+
bomAware?: boolean;
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
}
|
|
26
52
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
addBOM?: boolean;
|
|
30
|
-
defaultEncoding?: string;
|
|
31
|
-
}
|
|
53
|
+
/** Encodes a `string` into a `Buffer`, using the provided `encoding`. */
|
|
54
|
+
export function encode (content: string, encoding: Encoding, options?: EncodeOptions): Buffer
|
|
32
55
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
56
|
+
/** Decodes a `Buffer` into a `string`, using the provided `encoding`. */
|
|
57
|
+
export function decode (buffer: Buffer | Uint8Array, encoding: Encoding, options?: DecodeOptions): string
|
|
58
|
+
|
|
59
|
+
/** Checks if a given encoding is supported by `iconv-lite`. */
|
|
60
|
+
export function encodingExists (encoding: string): encoding is Encoding
|
|
61
|
+
|
|
62
|
+
/** Legacy alias for {@link iconv.encode}. */
|
|
63
|
+
export const toEncoding: typeof iconv.encode
|
|
64
|
+
|
|
65
|
+
/** Legacy alias for {@link iconv.decode}. */
|
|
66
|
+
export const fromEncoding: typeof iconv.decode
|
|
67
|
+
|
|
68
|
+
/** Creates a stream that decodes binary data from a given `encoding` into strings. */
|
|
69
|
+
export function decodeStream (encoding: Encoding, options?: DecodeOptions): NodeJS.ReadWriteStream
|
|
70
|
+
|
|
71
|
+
/** Creates a stream that encodes strings into binary data in a given `encoding`. */
|
|
72
|
+
export function encodeStream (encoding: Encoding, options?: EncodeOptions): NodeJS.ReadWriteStream
|
|
37
73
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Explicitly enable Streaming API in browser environments by passing in:
|
|
76
|
+
* ```js
|
|
77
|
+
* require('stream')
|
|
78
|
+
* ```
|
|
79
|
+
* @example iconv.enableStreamingAPI(require('stream'));
|
|
80
|
+
*/
|
|
81
|
+
export function enableStreamingAPI (stream_module: { Transform: typeof Stream.Transform }): void
|
|
82
|
+
|
|
83
|
+
/** Creates and returns a low-level encoder stream. */
|
|
84
|
+
export function getEncoder (encoding: Encoding, options?: EncodeOptions): EncoderStream
|
|
85
|
+
|
|
86
|
+
/** Creates and returns a low-level decoder stream. */
|
|
87
|
+
export function getDecoder (encoding: Encoding, options?: DecodeOptions): DecoderStream
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Returns a codec object for the given `encoding`.
|
|
91
|
+
* @throws If the `encoding` is not recognized.
|
|
92
|
+
*/
|
|
93
|
+
export function getCodec (encoding: Encoding): Codec
|
|
94
|
+
|
|
95
|
+
/** Strips all non-alphanumeric characters and appended year from `encoding`. */
|
|
96
|
+
export function _canonicalizeEncoding (encoding: Encoding): string
|
|
97
|
+
|
|
98
|
+
/** A cache of all loaded encoding definitions. */
|
|
99
|
+
export let encodings: Record<
|
|
100
|
+
Encoding,
|
|
101
|
+
| string
|
|
102
|
+
| {
|
|
103
|
+
type: string;
|
|
104
|
+
[key: string]: any;
|
|
105
|
+
}
|
|
106
|
+
> | null
|
|
107
|
+
|
|
108
|
+
/** A cache of initialized codec objects. */
|
|
109
|
+
export let _codecDataCache: Record<string, Codec>
|
|
110
|
+
|
|
111
|
+
/** The character used for untranslatable `Unicode` characters. @default "�" */
|
|
112
|
+
export let defaultCharUnicode: string
|
|
113
|
+
|
|
114
|
+
/** The character used for untranslatable `single-byte` characters. @default "?" */
|
|
115
|
+
export let defaultCharSingleByte: string
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Skip deprecation warning when strings are used instead of Buffers during decoding.
|
|
119
|
+
* Note: {@link iconv.decode} converts the string to Buffer regardless.
|
|
120
|
+
*/
|
|
121
|
+
export let skipDecodeWarning: boolean
|
|
122
|
+
|
|
123
|
+
/** @readonly Whether or not, Streaming API is enabled. */
|
|
124
|
+
export const supportsStreams: boolean
|
|
125
|
+
|
|
126
|
+
export type { iconv as Iconv, Encoding }
|
|
41
127
|
}
|
|
128
|
+
|
|
129
|
+
export = iconv
|
|
@@ -4,22 +4,21 @@ var Buffer = require("safer-buffer").Buffer
|
|
|
4
4
|
|
|
5
5
|
var bomHandling = require("./bom-handling")
|
|
6
6
|
var mergeModules = require("./helpers/merge-exports")
|
|
7
|
-
var iconv = module.exports
|
|
8
7
|
|
|
9
8
|
// All codecs and aliases are kept here, keyed by encoding name/alias.
|
|
10
9
|
// They are lazy loaded in `iconv.getCodec` from `encodings/index.js`.
|
|
11
10
|
// Cannot initialize with { __proto__: null } because Boolean({ __proto__: null }) === true
|
|
12
|
-
|
|
11
|
+
module.exports.encodings = null
|
|
13
12
|
|
|
14
13
|
// Characters emitted in case of error.
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
module.exports.defaultCharUnicode = "�"
|
|
15
|
+
module.exports.defaultCharSingleByte = "?"
|
|
17
16
|
|
|
18
17
|
// Public API.
|
|
19
|
-
|
|
18
|
+
module.exports.encode = function encode (str, encoding, options) {
|
|
20
19
|
str = "" + (str || "") // Ensure string.
|
|
21
20
|
|
|
22
|
-
var encoder =
|
|
21
|
+
var encoder = module.exports.getEncoder(encoding, options)
|
|
23
22
|
|
|
24
23
|
var res = encoder.write(str)
|
|
25
24
|
var trail = encoder.end()
|
|
@@ -27,17 +26,17 @@ iconv.encode = function encode (str, encoding, options) {
|
|
|
27
26
|
return (trail && trail.length > 0) ? Buffer.concat([res, trail]) : res
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
module.exports.decode = function decode (buf, encoding, options) {
|
|
31
30
|
if (typeof buf === "string") {
|
|
32
|
-
if (!
|
|
31
|
+
if (!module.exports.skipDecodeWarning) {
|
|
33
32
|
console.error("Iconv-lite warning: decode()-ing strings is deprecated. Refer to https://github.com/ashtuchkin/iconv-lite/wiki/Use-Buffers-when-decoding")
|
|
34
|
-
|
|
33
|
+
module.exports.skipDecodeWarning = true
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
buf = Buffer.from("" + (buf || ""), "binary") // Ensure buffer.
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
var decoder =
|
|
39
|
+
var decoder = module.exports.getDecoder(encoding, options)
|
|
41
40
|
|
|
42
41
|
var res = decoder.write(buf)
|
|
43
42
|
var trail = decoder.end()
|
|
@@ -45,9 +44,9 @@ iconv.decode = function decode (buf, encoding, options) {
|
|
|
45
44
|
return trail ? (res + trail) : res
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
|
|
47
|
+
module.exports.encodingExists = function encodingExists (enc) {
|
|
49
48
|
try {
|
|
50
|
-
|
|
49
|
+
module.exports.getCodec(enc)
|
|
51
50
|
return true
|
|
52
51
|
} catch (e) {
|
|
53
52
|
return false
|
|
@@ -55,31 +54,31 @@ iconv.encodingExists = function encodingExists (enc) {
|
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
// Legacy aliases to convert functions
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
module.exports.toEncoding = module.exports.encode
|
|
58
|
+
module.exports.fromEncoding = module.exports.decode
|
|
60
59
|
|
|
61
60
|
// Search for a codec in iconv.encodings. Cache codec data in iconv._codecDataCache.
|
|
62
|
-
|
|
61
|
+
module.exports._codecDataCache = { __proto__: null }
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
if (!
|
|
63
|
+
module.exports.getCodec = function getCodec (encoding) {
|
|
64
|
+
if (!module.exports.encodings) {
|
|
66
65
|
var raw = require("../encodings")
|
|
67
66
|
// TODO: In future versions when old nodejs support is removed can use object.assign
|
|
68
|
-
|
|
69
|
-
mergeModules(
|
|
67
|
+
module.exports.encodings = { __proto__: null } // Initialize as empty object.
|
|
68
|
+
mergeModules(module.exports.encodings, raw)
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
// Canonicalize encoding name: strip all non-alphanumeric chars and appended year.
|
|
73
|
-
var enc =
|
|
72
|
+
var enc = module.exports._canonicalizeEncoding(encoding)
|
|
74
73
|
|
|
75
74
|
// Traverse iconv.encodings to find actual codec.
|
|
76
75
|
var codecOptions = {}
|
|
77
76
|
while (true) {
|
|
78
|
-
var codec =
|
|
77
|
+
var codec = module.exports._codecDataCache[enc]
|
|
79
78
|
|
|
80
79
|
if (codec) { return codec }
|
|
81
80
|
|
|
82
|
-
var codecDef =
|
|
81
|
+
var codecDef = module.exports.encodings[enc]
|
|
83
82
|
|
|
84
83
|
switch (typeof codecDef) {
|
|
85
84
|
case "string": // Direct alias to other encoding.
|
|
@@ -100,9 +99,9 @@ iconv.getCodec = function getCodec (encoding) {
|
|
|
100
99
|
// The codec function must load all tables and return object with .encoder and .decoder methods.
|
|
101
100
|
// It'll be called only once (for each different options object).
|
|
102
101
|
//
|
|
103
|
-
codec = new codecDef(codecOptions,
|
|
102
|
+
codec = new codecDef(codecOptions, module.exports)
|
|
104
103
|
|
|
105
|
-
|
|
104
|
+
module.exports._codecDataCache[codecOptions.encodingName] = codec // Save it to be reused later.
|
|
106
105
|
return codec
|
|
107
106
|
|
|
108
107
|
default:
|
|
@@ -111,13 +110,13 @@ iconv.getCodec = function getCodec (encoding) {
|
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
|
|
113
|
+
module.exports._canonicalizeEncoding = function (encoding) {
|
|
115
114
|
// Canonicalize encoding name: strip all non-alphanumeric chars and appended year.
|
|
116
115
|
return ("" + encoding).toLowerCase().replace(/:\d{4}$|[^0-9a-z]/g, "")
|
|
117
116
|
}
|
|
118
117
|
|
|
119
|
-
|
|
120
|
-
var codec =
|
|
118
|
+
module.exports.getEncoder = function getEncoder (encoding, options) {
|
|
119
|
+
var codec = module.exports.getCodec(encoding)
|
|
121
120
|
var encoder = new codec.encoder(options, codec)
|
|
122
121
|
|
|
123
122
|
if (codec.bomAware && options && options.addBOM) { encoder = new bomHandling.PrependBOM(encoder, options) }
|
|
@@ -125,8 +124,8 @@ iconv.getEncoder = function getEncoder (encoding, options) {
|
|
|
125
124
|
return encoder
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
|
|
129
|
-
var codec =
|
|
127
|
+
module.exports.getDecoder = function getDecoder (encoding, options) {
|
|
128
|
+
var codec = module.exports.getCodec(encoding)
|
|
130
129
|
var decoder = new codec.decoder(options, codec)
|
|
131
130
|
|
|
132
131
|
if (codec.bomAware && !(options && options.stripBOM === false)) { decoder = new bomHandling.StripBOM(decoder, options) }
|
|
@@ -139,26 +138,26 @@ iconv.getDecoder = function getDecoder (encoding, options) {
|
|
|
139
138
|
// up to 100Kb to the output bundle. To avoid unnecessary code bloat, we don't enable Streaming API in browser by default.
|
|
140
139
|
// If you would like to enable it explicitly, please add the following code to your app:
|
|
141
140
|
// > iconv.enableStreamingAPI(require('stream'));
|
|
142
|
-
|
|
143
|
-
if (
|
|
141
|
+
module.exports.enableStreamingAPI = function enableStreamingAPI (streamModule) {
|
|
142
|
+
if (module.exports.supportsStreams) { return }
|
|
144
143
|
|
|
145
144
|
// Dependency-inject stream module to create IconvLite stream classes.
|
|
146
145
|
var streams = require("./streams")(streamModule)
|
|
147
146
|
|
|
148
147
|
// Not public API yet, but expose the stream classes.
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
module.exports.IconvLiteEncoderStream = streams.IconvLiteEncoderStream
|
|
149
|
+
module.exports.IconvLiteDecoderStream = streams.IconvLiteDecoderStream
|
|
151
150
|
|
|
152
151
|
// Streaming API.
|
|
153
|
-
|
|
154
|
-
return new
|
|
152
|
+
module.exports.encodeStream = function encodeStream (encoding, options) {
|
|
153
|
+
return new module.exports.IconvLiteEncoderStream(module.exports.getEncoder(encoding, options), options)
|
|
155
154
|
}
|
|
156
155
|
|
|
157
|
-
|
|
158
|
-
return new
|
|
156
|
+
module.exports.decodeStream = function decodeStream (encoding, options) {
|
|
157
|
+
return new module.exports.IconvLiteDecoderStream(module.exports.getDecoder(encoding, options), options)
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
|
|
160
|
+
module.exports.supportsStreams = true
|
|
162
161
|
}
|
|
163
162
|
|
|
164
163
|
// Enable Streaming API automatically if 'stream' module is available and non-empty (the majority of environments).
|
|
@@ -168,10 +167,10 @@ try {
|
|
|
168
167
|
} catch (e) {}
|
|
169
168
|
|
|
170
169
|
if (streamModule && streamModule.Transform) {
|
|
171
|
-
|
|
170
|
+
module.exports.enableStreamingAPI(streamModule)
|
|
172
171
|
} else {
|
|
173
172
|
// In rare cases where 'stream' module is not available by default, throw a helpful exception.
|
|
174
|
-
|
|
173
|
+
module.exports.encodeStream = module.exports.decodeStream = function () {
|
|
175
174
|
throw new Error("iconv-lite Streaming API is not enabled. Use iconv.enableStreamingAPI(require('stream')); to enable it.")
|
|
176
175
|
}
|
|
177
176
|
}
|