Skip to content

Commit fafca8a

Browse files
authored
Merge pull request #103 from Jaaneek/fix/102
fix: allow specifying encoding when reading as Text
2 parents ff8bc98 + 33a32aa commit fafca8a

5 files changed

Lines changed: 352 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ const Imperative = () => {
352352
| readFilesContent | Ignores files content and omits reading process if set to false | true | true, false |
353353
| validators | Add validation logic. You can use some of the [built-in validators](#built-in-validators) like FileAmountLimitValidator or create your own [custom validation](#custom-validation) logic | [] | [MyValidator, MySecondValidator] |
354354
| initializeWithCustomParameters | allows for customization of the input element that is created by the file picker. It accepts a function that takes in the input element as a parameter and can be used to set any desired attributes or styles on the element. | n/a | (input) => input.setAttribute("disabled", "") |
355+
| encoding | Specifies the encoding to use when reading text files. Only applicable when readAs is set to "Text". Available options include all standard encodings. | "utf-8" | "latin1", "utf-8", "windows-1252" |
355356
| onFilesSelected | A callback function that is called when files are successfully selected. The function is passed an array of objects with information about each successfully selected file | n/a | (data) => console.log(data) |
356357
| onFilesSuccessfullySelected | A callback function that is called when files are successfully selected. The function is passed an array of objects with information about each successfully selected file | n/a | (data) => console.log(data) |
357358
| onFilesRejected | A callback function that is called when files are rejected due to validation errors or other issues. The function is passed an array of objects with information about each rejected file | n/a | (data) => console.log(data) |
@@ -462,12 +463,6 @@ class CustomValidator extends Validator {
462463
- Github: [@MrKampla](https://github.com/MrKampla)
463464
- LinkedIn: [@https://www.linkedin.com/in/kamil-planer/](https://www.linkedin.com/in/kamil-planer/)
464465

465-
👤 **Adam Dobrzeniewski**
466-
467-
- Twitter: [@twitter.com/xForsect](https://twitter.com/xForsect)
468-
- Github: [@Forsect](https://github.com/Forsect)
469-
- LinkedIn: [@https://www.linkedin.com/in/adam-dobrzeniewski](https://www.linkedin.com/in/adam-dobrzeniewski)
470-
471466
## [](https://github.com/Jaaneek/useFilePicker#-contributing)🤝 Contributing
472467

473468
Contributions, issues and feature requests are welcome!

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "use-file-picker",
33
"description": "Simple react hook to open browser file selector.",
4-
"version": "2.1.3-canary.0",
4+
"version": "2.1.3",
55
"license": "MIT",
66
"author": "Milosz Jankiewicz",
77
"homepage": "https://github.com/Jaaneek/useFilePicker",

src/helpers/encodings.ts

Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
export const ENCODINGS = [
2+
{
3+
encodings: [
4+
{
5+
labels: ['unicode-1-1-utf-8', 'unicode11utf8', 'unicode20utf8', 'utf-8', 'utf8', 'x-unicode20utf8'],
6+
name: 'UTF-8',
7+
},
8+
],
9+
heading: 'The Default Encoding',
10+
},
11+
{
12+
encodings: [
13+
{
14+
labels: ['866', 'cp866', 'csibm866', 'ibm866'],
15+
name: 'IBM866',
16+
},
17+
{
18+
labels: [
19+
'csisolatin2',
20+
'iso-8859-2',
21+
'iso-ir-101',
22+
'iso8859-2',
23+
'iso88592',
24+
'iso_8859-2',
25+
'iso_8859-2:1987',
26+
'l2',
27+
'latin2',
28+
],
29+
name: 'ISO-8859-2',
30+
},
31+
{
32+
labels: [
33+
'csisolatin3',
34+
'iso-8859-3',
35+
'iso-ir-109',
36+
'iso8859-3',
37+
'iso88593',
38+
'iso_8859-3',
39+
'iso_8859-3:1988',
40+
'l3',
41+
'latin3',
42+
],
43+
name: 'ISO-8859-3',
44+
},
45+
{
46+
labels: [
47+
'csisolatin4',
48+
'iso-8859-4',
49+
'iso-ir-110',
50+
'iso8859-4',
51+
'iso88594',
52+
'iso_8859-4',
53+
'iso_8859-4:1988',
54+
'l4',
55+
'latin4',
56+
],
57+
name: 'ISO-8859-4',
58+
},
59+
{
60+
labels: [
61+
'csisolatincyrillic',
62+
'cyrillic',
63+
'iso-8859-5',
64+
'iso-ir-144',
65+
'iso8859-5',
66+
'iso88595',
67+
'iso_8859-5',
68+
'iso_8859-5:1988',
69+
],
70+
name: 'ISO-8859-5',
71+
},
72+
{
73+
labels: [
74+
'arabic',
75+
'asmo-708',
76+
'csiso88596e',
77+
'csiso88596i',
78+
'csisolatinarabic',
79+
'ecma-114',
80+
'iso-8859-6',
81+
'iso-8859-6-e',
82+
'iso-8859-6-i',
83+
'iso-ir-127',
84+
'iso8859-6',
85+
'iso88596',
86+
'iso_8859-6',
87+
'iso_8859-6:1987',
88+
],
89+
name: 'ISO-8859-6',
90+
},
91+
{
92+
labels: [
93+
'csisolatingreek',
94+
'ecma-118',
95+
'elot_928',
96+
'greek',
97+
'greek8',
98+
'iso-8859-7',
99+
'iso-ir-126',
100+
'iso8859-7',
101+
'iso88597',
102+
'iso_8859-7',
103+
'iso_8859-7:1987',
104+
'sun_eu_greek',
105+
],
106+
name: 'ISO-8859-7',
107+
},
108+
{
109+
labels: [
110+
'csiso88598e',
111+
'csisolatinhebrew',
112+
'hebrew',
113+
'iso-8859-8',
114+
'iso-8859-8-e',
115+
'iso-ir-138',
116+
'iso8859-8',
117+
'iso88598',
118+
'iso_8859-8',
119+
'iso_8859-8:1988',
120+
'visual',
121+
],
122+
name: 'ISO-8859-8',
123+
},
124+
{
125+
labels: ['csiso88598i', 'iso-8859-8-i', 'logical'],
126+
name: 'ISO-8859-8-I',
127+
},
128+
{
129+
labels: ['csisolatin6', 'iso-8859-10', 'iso-ir-157', 'iso8859-10', 'iso885910', 'l6', 'latin6'],
130+
name: 'ISO-8859-10',
131+
},
132+
{
133+
labels: ['iso-8859-13', 'iso8859-13', 'iso885913'],
134+
name: 'ISO-8859-13',
135+
},
136+
{
137+
labels: ['iso-8859-14', 'iso8859-14', 'iso885914'],
138+
name: 'ISO-8859-14',
139+
},
140+
{
141+
labels: ['csisolatin9', 'iso-8859-15', 'iso8859-15', 'iso885915', 'iso_8859-15', 'l9'],
142+
name: 'ISO-8859-15',
143+
},
144+
{
145+
labels: ['iso-8859-16'],
146+
name: 'ISO-8859-16',
147+
},
148+
{
149+
labels: ['cskoi8r', 'koi', 'koi8', 'koi8-r', 'koi8_r'],
150+
name: 'KOI8-R',
151+
},
152+
{
153+
labels: ['koi8-ru', 'koi8-u'],
154+
name: 'KOI8-U',
155+
},
156+
{
157+
labels: ['csmacintosh', 'mac', 'macintosh', 'x-mac-roman'],
158+
name: 'macintosh',
159+
},
160+
{
161+
labels: ['dos-874', 'iso-8859-11', 'iso8859-11', 'iso885911', 'tis-620', 'windows-874'],
162+
name: 'windows-874',
163+
},
164+
{
165+
labels: ['cp1250', 'windows-1250', 'x-cp1250'],
166+
name: 'windows-1250',
167+
},
168+
{
169+
labels: ['cp1251', 'windows-1251', 'x-cp1251'],
170+
name: 'windows-1251',
171+
},
172+
{
173+
labels: [
174+
'ansi_x3.4-1968',
175+
'ascii',
176+
'cp1252',
177+
'cp819',
178+
'csisolatin1',
179+
'ibm819',
180+
'iso-8859-1',
181+
'iso-ir-100',
182+
'iso8859-1',
183+
'iso88591',
184+
'iso_8859-1',
185+
'iso_8859-1:1987',
186+
'l1',
187+
'latin1',
188+
'us-ascii',
189+
'windows-1252',
190+
'x-cp1252',
191+
],
192+
name: 'windows-1252',
193+
},
194+
{
195+
labels: ['cp1253', 'windows-1253', 'x-cp1253'],
196+
name: 'windows-1253',
197+
},
198+
{
199+
labels: [
200+
'cp1254',
201+
'csisolatin5',
202+
'iso-8859-9',
203+
'iso-ir-148',
204+
'iso8859-9',
205+
'iso88599',
206+
'iso_8859-9',
207+
'iso_8859-9:1989',
208+
'l5',
209+
'latin5',
210+
'windows-1254',
211+
'x-cp1254',
212+
],
213+
name: 'windows-1254',
214+
},
215+
{
216+
labels: ['cp1255', 'windows-1255', 'x-cp1255'],
217+
name: 'windows-1255',
218+
},
219+
{
220+
labels: ['cp1256', 'windows-1256', 'x-cp1256'],
221+
name: 'windows-1256',
222+
},
223+
{
224+
labels: ['cp1257', 'windows-1257', 'x-cp1257'],
225+
name: 'windows-1257',
226+
},
227+
{
228+
labels: ['cp1258', 'windows-1258', 'x-cp1258'],
229+
name: 'windows-1258',
230+
},
231+
{
232+
labels: ['x-mac-cyrillic', 'x-mac-ukrainian'],
233+
name: 'x-mac-cyrillic',
234+
},
235+
],
236+
heading: 'Legacy single-byte encodings',
237+
},
238+
{
239+
encodings: [
240+
{
241+
labels: [
242+
'chinese',
243+
'csgb2312',
244+
'csiso58gb231280',
245+
'gb2312',
246+
'gb_2312',
247+
'gb_2312-80',
248+
'gbk',
249+
'iso-ir-58',
250+
'x-gbk',
251+
],
252+
name: 'GBK',
253+
},
254+
{
255+
labels: ['gb18030'],
256+
name: 'gb18030',
257+
},
258+
],
259+
heading: 'Legacy multi-byte Chinese (simplified) encodings',
260+
},
261+
{
262+
encodings: [
263+
{
264+
labels: ['big5', 'big5-hkscs', 'cn-big5', 'csbig5', 'x-x-big5'],
265+
name: 'Big5',
266+
},
267+
],
268+
heading: 'Legacy multi-byte Chinese (traditional) encodings',
269+
},
270+
{
271+
encodings: [
272+
{
273+
labels: ['cseucpkdfmtjapanese', 'euc-jp', 'x-euc-jp'],
274+
name: 'EUC-JP',
275+
},
276+
{
277+
labels: ['csiso2022jp', 'iso-2022-jp'],
278+
name: 'ISO-2022-JP',
279+
},
280+
{
281+
labels: ['csshiftjis', 'ms932', 'ms_kanji', 'shift-jis', 'shift_jis', 'sjis', 'windows-31j', 'x-sjis'],
282+
name: 'Shift_JIS',
283+
},
284+
],
285+
heading: 'Legacy multi-byte Japanese encodings',
286+
},
287+
{
288+
encodings: [
289+
{
290+
labels: [
291+
'cseuckr',
292+
'csksc56011987',
293+
'euc-kr',
294+
'iso-ir-149',
295+
'korean',
296+
'ks_c_5601-1987',
297+
'ks_c_5601-1989',
298+
'ksc5601',
299+
'ksc_5601',
300+
'windows-949',
301+
],
302+
name: 'EUC-KR',
303+
},
304+
],
305+
heading: 'Legacy multi-byte Korean encodings',
306+
},
307+
{
308+
encodings: [
309+
{
310+
labels: ['csiso2022kr', 'hz-gb-2312', 'iso-2022-cn', 'iso-2022-cn-ext', 'iso-2022-kr', 'replacement'],
311+
name: 'replacement',
312+
},
313+
{
314+
labels: ['unicodefffe', 'utf-16be'],
315+
name: 'UTF-16BE',
316+
},
317+
{
318+
labels: ['csunicode', 'iso-10646-ucs-2', 'ucs-2', 'unicode', 'unicodefeff', 'utf-16', 'utf-16le'],
319+
name: 'UTF-16LE',
320+
},
321+
],
322+
heading: 'Legacy miscellaneous encodings',
323+
},
324+
] as const;

0 commit comments

Comments
 (0)