@alessiofrittoli/media-utils 0.1.0
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 +287 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/mime.d.mts +553 -0
- package/dist/mime.d.ts +553 -0
- package/dist/mime.js +1 -0
- package/dist/mime.mjs +1 -0
- package/license.md +21 -0
- package/package.json +110 -0
package/README.md
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# Media Utils 🎥
|
|
2
|
+
|
|
3
|
+
[![NPM Latest Version][version-badge]][npm-url] [![Coverage Status][coverage-badge]][coverage-url] [![Socket Status][socket-badge]][socket-url] [![NPM Monthly Downloads][downloads-badge]][npm-url] [![Dependencies][deps-badge]][deps-url]
|
|
4
|
+
|
|
5
|
+
[![GitHub Sponsor][sponsor-badge]][sponsor-url]
|
|
6
|
+
|
|
7
|
+
[version-badge]: https://img.shields.io/npm/v/%40alessiofrittoli%2Fmedia-utils
|
|
8
|
+
[npm-url]: https://npmjs.org/package/%40alessiofrittoli%2Fmedia-utils
|
|
9
|
+
[coverage-badge]: https://coveralls.io/repos/github/alessiofrittoli/media-utils/badge.svg
|
|
10
|
+
[coverage-url]: https://coveralls.io/github/alessiofrittoli/media-utils
|
|
11
|
+
[socket-badge]: https://socket.dev/api/badge/npm/package/@alessiofrittoli/media-utils
|
|
12
|
+
[socket-url]: https://socket.dev/npm/package/@alessiofrittoli/media-utils/overview
|
|
13
|
+
[downloads-badge]: https://img.shields.io/npm/dm/%40alessiofrittoli%2Fmedia-utils.svg
|
|
14
|
+
[deps-badge]: https://img.shields.io/librariesio/release/npm/%40alessiofrittoli%2Fmedia-utils
|
|
15
|
+
[deps-url]: https://libraries.io/npm/%40alessiofrittoli%2Fmedia-utils
|
|
16
|
+
[sponsor-badge]: https://img.shields.io/static/v1?label=Fund%20this%20package&message=%E2%9D%A4&logo=GitHub&color=%23DB61A2
|
|
17
|
+
[sponsor-url]: https://github.com/sponsors/alessiofrittoli
|
|
18
|
+
|
|
19
|
+
## TypeScript media utility library
|
|
20
|
+
|
|
21
|
+
### Table of Contents
|
|
22
|
+
|
|
23
|
+
- [Getting started](#getting-started)
|
|
24
|
+
- [API Reference](#api-reference)
|
|
25
|
+
- [MIME types](#mime-types)
|
|
26
|
+
- [Development](#development)
|
|
27
|
+
- [Install depenendencies](#install-depenendencies)
|
|
28
|
+
- [Build the source code](#build-the-source-code)
|
|
29
|
+
- [ESLint](#eslint)
|
|
30
|
+
- [Jest](#jest)
|
|
31
|
+
- [Contributing](#contributing)
|
|
32
|
+
- [Security](#security)
|
|
33
|
+
- [Credits](#made-with-)
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### Getting started
|
|
38
|
+
|
|
39
|
+
Run the following command to start using `media-utils` in your projects:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm i @alessiofrittoli/media-utils
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
or using `pnpm`
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pnpm i @alessiofrittoli/media-utils
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### API Reference
|
|
54
|
+
|
|
55
|
+
#### MIME types
|
|
56
|
+
|
|
57
|
+
##### `getMimeType`
|
|
58
|
+
|
|
59
|
+
Get the MIME type from the given `input` string.
|
|
60
|
+
|
|
61
|
+
<details>
|
|
62
|
+
|
|
63
|
+
<summary style="cursor:pointer">Parameters</summary>
|
|
64
|
+
|
|
65
|
+
| Parameter | Type | Description |
|
|
66
|
+
| --------- | ----------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
67
|
+
| `input` | `string` | The input string where MIME type is extracted from. |
|
|
68
|
+
| `type` | `MediaType` | (Optional) Accepted media type. This may be usefull when subtype matches other media types (eg. `audio/mp4` - `video/mp4`). |
|
|
69
|
+
|
|
70
|
+
</details>
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
<details>
|
|
75
|
+
|
|
76
|
+
<summary style="cursor:pointer">Returns</summary>
|
|
77
|
+
|
|
78
|
+
Type: `MIMEType`
|
|
79
|
+
|
|
80
|
+
- The MIME type if found.
|
|
81
|
+
- `undefined` otherwise.
|
|
82
|
+
|
|
83
|
+
</details>
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
<details>
|
|
88
|
+
|
|
89
|
+
<summary style="cursor:pointer">Examples</summary>
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { getMimeType } from "@alessiofrittoli/media-utils";
|
|
93
|
+
// or
|
|
94
|
+
import { getMimeType } from "@alessiofrittoli/media-utils/mime";
|
|
95
|
+
|
|
96
|
+
console.log(getMimeType("/path/to/video-file.mp4")); // Outputs: 'video/mp4'
|
|
97
|
+
console.log(getMimeType("/path/to/audio-file.mp4", "audio")); // Outputs: 'audio/mp4'
|
|
98
|
+
console.log(getMimeType("/path/to/audio-file.mp3")); // Outputs: 'audio/mpeg'
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
</details>
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
##### `getAllowedMimeTypes`
|
|
106
|
+
|
|
107
|
+
Get allowed MIME types.
|
|
108
|
+
|
|
109
|
+
<!-- /**
|
|
110
|
+
*
|
|
111
|
+
* @param accept (Optional) A string describing allowed MIME types.
|
|
112
|
+
* The format is the same accepted by {@link HTMLInputElement.accept} attribute.
|
|
113
|
+
*
|
|
114
|
+
* It could be one of the following examples:
|
|
115
|
+
* - `*`
|
|
116
|
+
* - `image` (type)
|
|
117
|
+
* - `image/*` ({type}/{subtype})
|
|
118
|
+
* - `image/png` ({type}/{subtype}) - specific
|
|
119
|
+
* - `.png` (extension)
|
|
120
|
+
* - `image,audio` (multiple types)
|
|
121
|
+
* - `image/*,audio/*` (multiple {type}/{subtype})
|
|
122
|
+
* - `.png, .mp3` (multiple extensions)
|
|
123
|
+
* - `.docx, audio, video/*, text/html` (mixed)
|
|
124
|
+
*
|
|
125
|
+
* @returns An array of MIME types based on the `accept` value. `[ '*' ]` if a wildcard or no `accept` is given.
|
|
126
|
+
*/
|
|
127
|
+
export const getAllowedMimeTypes = ( accept?: string ) => { -->
|
|
128
|
+
|
|
129
|
+
<details>
|
|
130
|
+
|
|
131
|
+
<summary style="cursor:pointer">Parameters</summary>
|
|
132
|
+
|
|
133
|
+
| Parameter | Type | Description |
|
|
134
|
+
| --------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
135
|
+
| `accept` | `string` | (Optioanl) A string describing allowed MIME types. |
|
|
136
|
+
| | | The format is the same accepted by [`HTMLInputElement.accept`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/accept) attribute. |
|
|
137
|
+
| | | It could be one of the following examples: |
|
|
138
|
+
| | | `*` |
|
|
139
|
+
| | | `image` (type) |
|
|
140
|
+
| | | `image/*` ({type}/{subtype}) |
|
|
141
|
+
| | | `image/png` ({type}/{subtype}) - specific |
|
|
142
|
+
| | | `.png` (extension) |
|
|
143
|
+
| | | `image,audio` (multiple types) |
|
|
144
|
+
| | | `image/*,audio/*` (multiple {type}/{subtype}) |
|
|
145
|
+
| | | `.png, .mp3` (multiple extensions) |
|
|
146
|
+
| | | `.docx, audio, video/*, text/html` (mixed) |
|
|
147
|
+
|
|
148
|
+
</details>
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
<details>
|
|
153
|
+
|
|
154
|
+
<summary style="cursor:pointer">Returns</summary>
|
|
155
|
+
|
|
156
|
+
Type: `(MIMEType | '*')[]`
|
|
157
|
+
|
|
158
|
+
An array of MIME types based on the `accept` value. `[ '*' ]` if a wildcard or no `accept` is given.
|
|
159
|
+
|
|
160
|
+
</details>
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
<details>
|
|
165
|
+
|
|
166
|
+
<summary style="cursor:pointer">Examples</summary>
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
import { getAllowedMimeTypes } from "@alessiofrittoli/media-utils";
|
|
170
|
+
// or
|
|
171
|
+
import { getAllowedMimeTypes } from "@alessiofrittoli/media-utils/mime";
|
|
172
|
+
|
|
173
|
+
console.log(getAllowedMimeTypes());
|
|
174
|
+
console.log(getAllowedMimeTypes("*"));
|
|
175
|
+
console.log(getAllowedMimeTypes("image"));
|
|
176
|
+
console.log(getAllowedMimeTypes("audio/*"));
|
|
177
|
+
console.log(getAllowedMimeTypes("image,video"));
|
|
178
|
+
console.log(getAllowedMimeTypes("image/*,video/*"));
|
|
179
|
+
console.log(getAllowedMimeTypes(".mp3,mp4"));
|
|
180
|
+
console.log(getAllowedMimeTypes(".jpg, .png"));
|
|
181
|
+
console.log(getAllowedMimeTypes("image/jpeg,.jpg"));
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
</details>
|
|
185
|
+
|
|
186
|
+
### Development
|
|
187
|
+
|
|
188
|
+
#### Install depenendencies
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
npm install
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
or using `pnpm`
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
pnpm i
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### Build the source code
|
|
201
|
+
|
|
202
|
+
Run the following command to test and build code for distribution.
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
pnpm build
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### [ESLint](https://www.npmjs.com/package/eslint)
|
|
209
|
+
|
|
210
|
+
warnings / errors check.
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
pnpm lint
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### [Jest](https://npmjs.com/package/jest)
|
|
217
|
+
|
|
218
|
+
Run all the defined test suites by running the following:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Run tests and watch file changes.
|
|
222
|
+
pnpm test:watch
|
|
223
|
+
|
|
224
|
+
# Run tests in a CI environment.
|
|
225
|
+
pnpm test:ci
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
- See [`package.json`](./package.json) file scripts for more info.
|
|
229
|
+
|
|
230
|
+
Run tests with coverage.
|
|
231
|
+
|
|
232
|
+
An HTTP server is then started to serve coverage files from `./coverage` folder.
|
|
233
|
+
|
|
234
|
+
⚠️ You may see a blank page the first time you run this command. Simply refresh the browser to see the updates.
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
test:coverage:serve
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
### Contributing
|
|
243
|
+
|
|
244
|
+
Contributions are truly welcome!
|
|
245
|
+
|
|
246
|
+
Please refer to the [Contributing Doc](./CONTRIBUTING.md) for more information on how to start contributing to this project.
|
|
247
|
+
|
|
248
|
+
Help keep this project up to date with [GitHub Sponsor][sponsor-url].
|
|
249
|
+
|
|
250
|
+
[![GitHub Sponsor][sponsor-badge]][sponsor-url]
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
### Security
|
|
255
|
+
|
|
256
|
+
If you believe you have found a security vulnerability, we encourage you to **_responsibly disclose this and NOT open a public issue_**. We will investigate all legitimate reports. Email `security@alessiofrittoli.it` to disclose any security vulnerabilities.
|
|
257
|
+
|
|
258
|
+
### Made with ☕
|
|
259
|
+
|
|
260
|
+
<table style='display:flex;gap:20px;'>
|
|
261
|
+
<tbody>
|
|
262
|
+
<tr>
|
|
263
|
+
<td>
|
|
264
|
+
<img alt="avatar" src='https://avatars.githubusercontent.com/u/35973186' style='width:60px;border-radius:50%;object-fit:contain;'>
|
|
265
|
+
</td>
|
|
266
|
+
<td>
|
|
267
|
+
<table style='display:flex;gap:2px;flex-direction:column;'>
|
|
268
|
+
<tbody>
|
|
269
|
+
<tr>
|
|
270
|
+
<td>
|
|
271
|
+
<a href='https://github.com/alessiofrittoli' target='_blank' rel='noopener'>Alessio Frittoli</a>
|
|
272
|
+
</td>
|
|
273
|
+
</tr>
|
|
274
|
+
<tr>
|
|
275
|
+
<td>
|
|
276
|
+
<small>
|
|
277
|
+
<a href='https://alessiofrittoli.it' target='_blank' rel='noopener'>https://alessiofrittoli.it</a> |
|
|
278
|
+
<a href='mailto:info@alessiofrittoli.it' target='_blank' rel='noopener'>info@alessiofrittoli.it</a>
|
|
279
|
+
</small>
|
|
280
|
+
</td>
|
|
281
|
+
</tr>
|
|
282
|
+
</tbody>
|
|
283
|
+
</table>
|
|
284
|
+
</td>
|
|
285
|
+
</tr>
|
|
286
|
+
</tbody>
|
|
287
|
+
</table>
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { APPLICATION_MIME_TYPES, AUDIO_MIME_TYPES, Extension, FONT_MIME_TYPES, IMAGE_MIME_TYPES, MIMEType, MIME_TYPES_MAP, MODEL_MIME_TYPES, MediaType, TEXT_MIME_TYPES, VIDEO_MIME_TYPES, getAllowedMimeTypes, getFileExtension, getMimeType } from './mime.mjs';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { APPLICATION_MIME_TYPES, AUDIO_MIME_TYPES, Extension, FONT_MIME_TYPES, IMAGE_MIME_TYPES, MIMEType, MIME_TYPES_MAP, MODEL_MIME_TYPES, MediaType, TEXT_MIME_TYPES, VIDEO_MIME_TYPES, getAllowedMimeTypes, getFileExtension, getMimeType } from './mime.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var webUtils=require('@alessiofrittoli/web-utils');var l={body:"text/html",css:"text/css",csv:"text/csv",etx:"text/x-setext",htc:"text/x-component",htm:"text/html",html:"text/html",ics:"text/calendar",jad:"text/vnd.sun.j2me.app-descriptor",java:"text/x-java-source",jsf:"text/plain",jspf:"text/plain",man:"text/troff",me:"text/troff",mjs:"text/javascript",roff:"text/troff",rtx:"text/richtext",t:"text/troff",tr:"text/troff",tsv:"text/tab-separated-values",txt:"text/plain",wml:"text/vnd.wap.wml",wmls:"text/vnd.wap.wmlsc",md:"text/markdown"},d={art:"image/x-jg",avif:"image/avif",bmp:"image/bmp",dib:"image/bmp",gif:"image/gif",ico:"image/vnd.microsoft.icon",ief:"image/ief",jpe:"image/jpeg",jpeg:"image/jpeg",jpg:"image/jpeg",mac:"image/x-macpaint",pbm:"image/x-portable-bitmap",pct:"image/pict",pgm:"image/x-portable-graymap",pic:"image/pict",pict:"image/pict",png:"image/png",apng:"image/apng",pnm:"image/x-portable-anymap",pnt:"image/x-macpaint",ppm:"image/x-portable-pixmap",psd:"image/vnd.adobe.photoshop",qti:"image/x-quicktime",qtif:"image/x-quicktime",ras:"image/x-cmu-raster",rgb:"image/x-rgb",svg:"image/svg+xml",svgz:"image/svg+xml",tif:"image/tiff",tiff:"image/tiff",xbm:"image/x-xbitmap",xpm:"image/x-xpixmap",xwd:"image/x-xwindowdump",webp:"image/webp",wbmp:"image/vnd.wap.wbmp"},x={aac:"audio/aac",abs:"audio/x-mpeg",aif:"audio/x-aiff",aifc:"audio/x-aiff",aiff:"audio/x-aiff",au:"audio/basic",kar:"audio/midi",m3u:"audio/x-mpegurl",mid:"audio/midi",midi:"audio/midi",m4a:"audio/x-m4a",mp1:"audio/mpeg",mp2:"audio/mpeg",mp3:"audio/mpeg",mpa:"audio/mpeg",mp4:"audio/mp4",mpega:"audio/x-mpeg",oga:"audio/ogg",ogg:"audio/ogg",opus:"audio/ogg",spx:"audio/ogg",flac:"audio/flac",axa:"audio/annodex",snd:"audio/basic",pls:"audio/x-scpls",ulw:"audio/basic",wav:"audio/wav",weba:"audio/webm",wma:"audio/x-ms-wma","3gp":"audio/3gpp","3g2":"audio/3gpp2"},f={asf:"video/x-ms-asf",asx:"video/x-ms-asf",avi:"video/x-msvideo",avx:"video/x-rad-screenplay",dv:"video/x-dv",mov:"video/quicktime",movie:"video/x-sgi-movie",mp4:"video/mp4",mpe:"video/mpeg",mpeg:"video/mpeg",mpg:"video/mpeg",mpv2:"video/mpeg2",ogv:"video/ogg",axv:"video/annodex",qt:"video/quicktime",ts:"video/mp2t",webm:"video/webm",wmv:"video/x-ms-wmv","3gp":"video/3gpp","3g2":"video/3gpp2"},r={ttf:"font/ttf",otf:"font/otf",woff:"font/woff",woff2:"font/woff2"},g={wrl:"model/vrml"},v={abw:"application/x-abiword",ai:"application/postscript",aim:"application/x-aim",arc:"application/x-freearc",azw:"application/vnd.amazon.ebook",bcpio:"application/x-bcpio",bin:"application/octet-stream",bz:"application/x-bzip",bz2:"application/x-bzip2",cda:"application/x-cdf",cdf:"application/x-cdf",cer:"application/pkix-cert",class:"application/java",cpio:"application/x-cpio",csh:"application/x-csh",dll:"application/x-msdownload",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",dtd:"application/xml-dtd",dvi:"application/x-dvi",eot:"application/vnd.ms-fontobject",eps:"application/postscript",epub:"application/epub+zip",exe:"application/octet-stream",gtar:"application/x-gtar",gz:"application/gzip",hdf:"application/x-hdf",hqx:"application/mac-binhex40",jar:"application/java-archive",jnlp:"application/x-java-jnlp-file",js:"application/javascript",json:"application/json",jsonld:"application/ld+json",jsx:"application/javascript",latex:"application/x-latex",mathml:"application/mathml+xml",mif:"application/x-mif",mpkg:"application/vnd.apple.installer+xml",ms:"application/x-wais-source",nc:"application/x-netcdf",oda:"application/oda",odb:"application/vnd.oasis.opendocument.database",odc:"application/vnd.oasis.opendocument.chart",odf:"application/vnd.oasis.opendocument.formula",odg:"application/vnd.oasis.opendocument.graphics",odi:"application/vnd.oasis.opendocument.image",odm:"application/vnd.oasis.opendocument.text-master",odp:"application/vnd.oasis.opendocument.presentation",ods:"application/vnd.oasis.opendocument.spreadsheet",odt:"application/vnd.oasis.opendocument.text",otg:"application/vnd.oasis.opendocument.graphics-template",oth:"application/vnd.oasis.opendocument.text-web",otp:"application/vnd.oasis.opendocument.presentation-template",ots:"application/vnd.oasis.opendocument.spreadsheet-template",ott:"application/vnd.oasis.opendocument.text-template",ogx:"application/ogg",otf:"application/x-font-opentype",anx:"application/annodex",xspf:"application/xspf+xml",pdf:"application/pdf",php:"application/x-httpd-php",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",pps:"application/vnd.ms-powerpoint",ps:"application/postscript",rar:"application/vnd.rar",rdf:"application/rdf+xml",rm:"application/vnd.rn-realmedia",rtf:"application/rtf",sfnt:"application/font-sfnt",sh:"application/x-sh",shar:"application/x-shar",sit:"application/x-stuffit",src:"application/x-wais-source",sv4cpio:"application/x-sv4cpio",sv4crc:"application/x-sv4crc",swf:"application/x-shockwave-flash",tar:"application/x-tar",tcl:"application/x-tcl",tex:"application/x-tex",texi:"application/x-texinfo",texinfo:"application/x-texinfo",ustar:"application/x-ustar",vxml:"application/voicexml+xml",xht:"application/xhtml+xml",xhtml:"application/xhtml+xml",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xml:"application/xml",xsl:"application/xml",xslt:"application/xslt+xml",xul:"application/vnd.mozilla.xul+xml",vsd:"application/vnd.visio",wmlc:"application/vnd.wap.wmlc",wmlscriptc:"application/vnd.wap.wmlscriptc",wspolicy:"application/wspolicy+xml",z:"application/x-compress",zip:"application/zip",manifest:"application/manifest+json","7z":"application/x-7z-compressed"},e={text:l,image:d,audio:x,video:f,font:r,model:g,application:v},M=i=>i.toLowerCase().split(".").pop()||void 0,u=(i,t)=>{let n=M(i);if(!n)return;if(t){let a=e[t];if(a)return a[n]}let p;return Object.values(e).forEach(a=>{let o=a[n];o&&(p=o);}),p},E=i=>i.includes("/")&&i.substring(0,i.indexOf("/"))in e,_=i=>{if(!i||i==="*")return ["*"];let t=[];return i.replace(/\s|\./g,"").split(",").filter(Boolean).forEach(p=>{let a=p.substring(p.indexOf("/")+1);if(a==="*"||a in e){let s=a in e?a:p.substring(0,p.indexOf("/")),c=e[s];if(c)return t.push(...Object.values(c))}let o=E(p)?p:u(a);if(o)return t.push(o)}),webUtils.arrayUnique(t)};exports.APPLICATION_MIME_TYPES=v;exports.AUDIO_MIME_TYPES=x;exports.FONT_MIME_TYPES=r;exports.IMAGE_MIME_TYPES=d;exports.MIME_TYPES_MAP=e;exports.MODEL_MIME_TYPES=g;exports.TEXT_MIME_TYPES=l;exports.VIDEO_MIME_TYPES=f;exports.getAllowedMimeTypes=_;exports.getFileExtension=M;exports.getMimeType=u;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {arrayUnique}from'@alessiofrittoli/web-utils';var l={body:"text/html",css:"text/css",csv:"text/csv",etx:"text/x-setext",htc:"text/x-component",htm:"text/html",html:"text/html",ics:"text/calendar",jad:"text/vnd.sun.j2me.app-descriptor",java:"text/x-java-source",jsf:"text/plain",jspf:"text/plain",man:"text/troff",me:"text/troff",mjs:"text/javascript",roff:"text/troff",rtx:"text/richtext",t:"text/troff",tr:"text/troff",tsv:"text/tab-separated-values",txt:"text/plain",wml:"text/vnd.wap.wml",wmls:"text/vnd.wap.wmlsc",md:"text/markdown"},d={art:"image/x-jg",avif:"image/avif",bmp:"image/bmp",dib:"image/bmp",gif:"image/gif",ico:"image/vnd.microsoft.icon",ief:"image/ief",jpe:"image/jpeg",jpeg:"image/jpeg",jpg:"image/jpeg",mac:"image/x-macpaint",pbm:"image/x-portable-bitmap",pct:"image/pict",pgm:"image/x-portable-graymap",pic:"image/pict",pict:"image/pict",png:"image/png",apng:"image/apng",pnm:"image/x-portable-anymap",pnt:"image/x-macpaint",ppm:"image/x-portable-pixmap",psd:"image/vnd.adobe.photoshop",qti:"image/x-quicktime",qtif:"image/x-quicktime",ras:"image/x-cmu-raster",rgb:"image/x-rgb",svg:"image/svg+xml",svgz:"image/svg+xml",tif:"image/tiff",tiff:"image/tiff",xbm:"image/x-xbitmap",xpm:"image/x-xpixmap",xwd:"image/x-xwindowdump",webp:"image/webp",wbmp:"image/vnd.wap.wbmp"},x={aac:"audio/aac",abs:"audio/x-mpeg",aif:"audio/x-aiff",aifc:"audio/x-aiff",aiff:"audio/x-aiff",au:"audio/basic",kar:"audio/midi",m3u:"audio/x-mpegurl",mid:"audio/midi",midi:"audio/midi",m4a:"audio/x-m4a",mp1:"audio/mpeg",mp2:"audio/mpeg",mp3:"audio/mpeg",mpa:"audio/mpeg",mp4:"audio/mp4",mpega:"audio/x-mpeg",oga:"audio/ogg",ogg:"audio/ogg",opus:"audio/ogg",spx:"audio/ogg",flac:"audio/flac",axa:"audio/annodex",snd:"audio/basic",pls:"audio/x-scpls",ulw:"audio/basic",wav:"audio/wav",weba:"audio/webm",wma:"audio/x-ms-wma","3gp":"audio/3gpp","3g2":"audio/3gpp2"},f={asf:"video/x-ms-asf",asx:"video/x-ms-asf",avi:"video/x-msvideo",avx:"video/x-rad-screenplay",dv:"video/x-dv",mov:"video/quicktime",movie:"video/x-sgi-movie",mp4:"video/mp4",mpe:"video/mpeg",mpeg:"video/mpeg",mpg:"video/mpeg",mpv2:"video/mpeg2",ogv:"video/ogg",axv:"video/annodex",qt:"video/quicktime",ts:"video/mp2t",webm:"video/webm",wmv:"video/x-ms-wmv","3gp":"video/3gpp","3g2":"video/3gpp2"},r={ttf:"font/ttf",otf:"font/otf",woff:"font/woff",woff2:"font/woff2"},g={wrl:"model/vrml"},v={abw:"application/x-abiword",ai:"application/postscript",aim:"application/x-aim",arc:"application/x-freearc",azw:"application/vnd.amazon.ebook",bcpio:"application/x-bcpio",bin:"application/octet-stream",bz:"application/x-bzip",bz2:"application/x-bzip2",cda:"application/x-cdf",cdf:"application/x-cdf",cer:"application/pkix-cert",class:"application/java",cpio:"application/x-cpio",csh:"application/x-csh",dll:"application/x-msdownload",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",dtd:"application/xml-dtd",dvi:"application/x-dvi",eot:"application/vnd.ms-fontobject",eps:"application/postscript",epub:"application/epub+zip",exe:"application/octet-stream",gtar:"application/x-gtar",gz:"application/gzip",hdf:"application/x-hdf",hqx:"application/mac-binhex40",jar:"application/java-archive",jnlp:"application/x-java-jnlp-file",js:"application/javascript",json:"application/json",jsonld:"application/ld+json",jsx:"application/javascript",latex:"application/x-latex",mathml:"application/mathml+xml",mif:"application/x-mif",mpkg:"application/vnd.apple.installer+xml",ms:"application/x-wais-source",nc:"application/x-netcdf",oda:"application/oda",odb:"application/vnd.oasis.opendocument.database",odc:"application/vnd.oasis.opendocument.chart",odf:"application/vnd.oasis.opendocument.formula",odg:"application/vnd.oasis.opendocument.graphics",odi:"application/vnd.oasis.opendocument.image",odm:"application/vnd.oasis.opendocument.text-master",odp:"application/vnd.oasis.opendocument.presentation",ods:"application/vnd.oasis.opendocument.spreadsheet",odt:"application/vnd.oasis.opendocument.text",otg:"application/vnd.oasis.opendocument.graphics-template",oth:"application/vnd.oasis.opendocument.text-web",otp:"application/vnd.oasis.opendocument.presentation-template",ots:"application/vnd.oasis.opendocument.spreadsheet-template",ott:"application/vnd.oasis.opendocument.text-template",ogx:"application/ogg",otf:"application/x-font-opentype",anx:"application/annodex",xspf:"application/xspf+xml",pdf:"application/pdf",php:"application/x-httpd-php",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",pps:"application/vnd.ms-powerpoint",ps:"application/postscript",rar:"application/vnd.rar",rdf:"application/rdf+xml",rm:"application/vnd.rn-realmedia",rtf:"application/rtf",sfnt:"application/font-sfnt",sh:"application/x-sh",shar:"application/x-shar",sit:"application/x-stuffit",src:"application/x-wais-source",sv4cpio:"application/x-sv4cpio",sv4crc:"application/x-sv4crc",swf:"application/x-shockwave-flash",tar:"application/x-tar",tcl:"application/x-tcl",tex:"application/x-tex",texi:"application/x-texinfo",texinfo:"application/x-texinfo",ustar:"application/x-ustar",vxml:"application/voicexml+xml",xht:"application/xhtml+xml",xhtml:"application/xhtml+xml",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xml:"application/xml",xsl:"application/xml",xslt:"application/xslt+xml",xul:"application/vnd.mozilla.xul+xml",vsd:"application/vnd.visio",wmlc:"application/vnd.wap.wmlc",wmlscriptc:"application/vnd.wap.wmlscriptc",wspolicy:"application/wspolicy+xml",z:"application/x-compress",zip:"application/zip",manifest:"application/manifest+json","7z":"application/x-7z-compressed"},e={text:l,image:d,audio:x,video:f,font:r,model:g,application:v},M=i=>i.toLowerCase().split(".").pop()||void 0,u=(i,t)=>{let n=M(i);if(!n)return;if(t){let a=e[t];if(a)return a[n]}let p;return Object.values(e).forEach(a=>{let o=a[n];o&&(p=o);}),p},E=i=>i.includes("/")&&i.substring(0,i.indexOf("/"))in e,_=i=>{if(!i||i==="*")return ["*"];let t=[];return i.replace(/\s|\./g,"").split(",").filter(Boolean).forEach(p=>{let a=p.substring(p.indexOf("/")+1);if(a==="*"||a in e){let s=a in e?a:p.substring(0,p.indexOf("/")),c=e[s];if(c)return t.push(...Object.values(c))}let o=E(p)?p:u(a);if(o)return t.push(o)}),arrayUnique(t)};export{v as APPLICATION_MIME_TYPES,x as AUDIO_MIME_TYPES,r as FONT_MIME_TYPES,d as IMAGE_MIME_TYPES,e as MIME_TYPES_MAP,g as MODEL_MIME_TYPES,l as TEXT_MIME_TYPES,f as VIDEO_MIME_TYPES,_ as getAllowedMimeTypes,M as getFileExtension,u as getMimeType};
|