forked from processing/p5.js-web-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileUtils.js
75 lines (69 loc) · 1.69 KB
/
fileUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
export const fileExtensionsArray = [
'gif',
'jpg',
'jpeg',
'png',
'bmp',
'wav',
'flac',
'ogg',
'oga',
'mp4',
'm4p',
'mp3',
'm4a',
'aiff',
'aif',
'm4v',
'aac',
'webm',
'mpg',
'mp2',
'mpeg',
'mpe',
'mpv',
'js',
'jsx',
'html',
'htm',
'css',
'json',
'csv',
'tsv',
'obj',
'svg',
'otf',
'ttf',
'txt',
'mov',
'vert',
'frag',
'bin',
'xml',
'stl'
];
export const mimeTypes = `image/*,audio/*,text/javascript,text/html,text/css,
application/json,application/x-font-ttf,application/x-font-truetype,text/plain,
text/csv,.obj,video/webm,video/ogg,video/quicktime,video/mp4,application/xml,.stl`;
export const fileExtensions = fileExtensionsArray
.map((ext) => `.${ext}`)
.join(',');
export const fileExtensionsAndMimeTypes = `${fileExtensions},${mimeTypes}`;
export const MEDIA_FILE_REGEX = new RegExp(
`^(?!(http:\\/\\/|https:\\/\\/)).*\\.(${fileExtensionsArray.join('|')})$`,
'i'
);
export const MEDIA_FILE_QUOTED_REGEX = new RegExp(
`^('|")(?!(http:\\/\\/|https:\\/\\/)).*\\.(${fileExtensionsArray.join(
'|'
)})('|")$`,
'i'
);
export const STRING_REGEX = /(['"])((\\\1|.)*?)\1/gm;
// these are files that have to be linked to with a blob url
export const PLAINTEXT_FILE_REGEX = /.+\.(json|txt|csv|vert|frag|tsv|xml|stl)$/i;
// these are files that users would want to edit as text (maybe svg should be here?)
export const TEXT_FILE_REGEX = /.+\.(json|txt|csv|tsv|vert|frag|js|css|html|htm|jsx|xml|stl)$/i;
export const NOT_EXTERNAL_LINK_REGEX = /^(?!(http:\/\/|https:\/\/))/;
export const EXTERNAL_LINK_REGEX = /^(http:\/\/|https:\/\/)/;
export const CREATE_FILE_REGEX = /.+\.(json|txt|csv|tsv|js|css|frag|vert|xml|html|htm|stl)$/i;