mime-xdg 1.0.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/LICENSE +21 -0
- package/README.md +199 -0
- package/heads/index.d.ts +3 -0
- package/heads/index.js +16 -0
- package/heads/index.mjs +18 -0
- package/heads/package.json +10 -0
- package/index.d.ts +7 -0
- package/index.js +38 -0
- package/index.mjs +38 -0
- package/lib/heads/index.d.ts +2 -0
- package/lib/heads/index.js +539 -0
- package/lib/heads/index.mjs +537 -0
- package/lib/heads/package.json +10 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +10 -0
- package/lib/index.mjs +8 -0
- package/lib/mimes/index.d.ts +4 -0
- package/lib/mimes/index.js +1630 -0
- package/lib/mimes/index.mjs +1627 -0
- package/lib/mimes/package.json +10 -0
- package/lib/notes/index.d.ts +3 -0
- package/lib/notes/index.js +11 -0
- package/lib/notes/index.mjs +8 -0
- package/lib/notes/package.json +10 -0
- package/lib/package.json +13 -0
- package/notes/index.d.ts +3 -0
- package/notes/index.js +15 -0
- package/notes/index.mjs +17 -0
- package/notes/package.json +10 -0
- package/package.json +52 -0
- package/types/heads.d.ts +3 -0
- package/types/index.d.ts +47 -0
- package/types/lib/heads.d.ts +1052 -0
- package/types/lib/index.d.ts +1 -0
- package/types/lib/mimes.d.ts +7240 -0
- package/types/lib/notes.d.ts +1057 -0
- package/types/notes.d.ts +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# mime-xdg
|
|
2
|
+
mimetypes, mimeheads and mimenotes from xdg/shared-mime-info
|
|
3
|
+
|
|
4
|
+
## Note
|
|
5
|
+
|
|
6
|
+
This library contains mime types from two sources:
|
|
7
|
+
- [apache.mime.types](https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types) - have the highest priority
|
|
8
|
+
- [gitlab.freedesktop.org/xdg/shared-mime-info](https://gitlab.freedesktop.org/xdg/shared-mime-info) - included in packages for defining mime types in Linux systems
|
|
9
|
+
|
|
10
|
+
In addition to this, there are top-level types (mime heads) and mime descriptions (mime notes).
|
|
11
|
+
|
|
12
|
+
All mime types and their descriptions are contained in an optimized form. Therefore, the library does not weigh so much.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
### mimeType
|
|
16
|
+
basic library with all mime types
|
|
17
|
+
```js
|
|
18
|
+
import {
|
|
19
|
+
EXTENSIONS, MIME_TYPES,
|
|
20
|
+
ext, extname,
|
|
21
|
+
mimeType, mimeList
|
|
22
|
+
} from 'mime-xdg'
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// OBJECTS
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 1. EXTENSIONS
|
|
29
|
+
*/
|
|
30
|
+
console.log(EXTENSIONS)
|
|
31
|
+
// EXTENSIONS equal to:
|
|
32
|
+
{
|
|
33
|
+
"123": [
|
|
34
|
+
"application/vnd.lotus-1-2-3",
|
|
35
|
+
"application/x-lotus123",
|
|
36
|
+
"application/x-123",
|
|
37
|
+
"application/lotus123",
|
|
38
|
+
"application/wk1",
|
|
39
|
+
"zz-application/zz-winassoc-123"
|
|
40
|
+
],
|
|
41
|
+
"602": [
|
|
42
|
+
"application/x-t602"
|
|
43
|
+
],
|
|
44
|
+
"7z.001": [
|
|
45
|
+
"application/x-7z-compressed"
|
|
46
|
+
],
|
|
47
|
+
"svg.gz": [
|
|
48
|
+
"image/svg+xml-compressed"
|
|
49
|
+
],
|
|
50
|
+
"aw": [
|
|
51
|
+
"application/applixware",
|
|
52
|
+
"application/x-applix-word"
|
|
53
|
+
],
|
|
54
|
+
/* etc... */
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 2. MIME_TYPES
|
|
59
|
+
*/
|
|
60
|
+
console.log(MIME_TYPES)
|
|
61
|
+
// MIME_TYPES equal to:
|
|
62
|
+
{
|
|
63
|
+
application: {
|
|
64
|
+
"x-riff": true,
|
|
65
|
+
"x-matroska": true,
|
|
66
|
+
"x-iff": true,
|
|
67
|
+
"x-ole-storage": true,
|
|
68
|
+
/* etc... */
|
|
69
|
+
},
|
|
70
|
+
audio: {
|
|
71
|
+
"tta": true,
|
|
72
|
+
"x-tta": true,
|
|
73
|
+
"x-xi": true,
|
|
74
|
+
"x-voc": true,
|
|
75
|
+
/* etc... */
|
|
76
|
+
},
|
|
77
|
+
font: { /* etc... */ },
|
|
78
|
+
image: { /* etc... */ },
|
|
79
|
+
text: { /* etc... */ },
|
|
80
|
+
/* etc... */
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// FUNCTIONS
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 3. ext
|
|
87
|
+
*/
|
|
88
|
+
// returns the extname if it is in the EXTENSIONS or empty string
|
|
89
|
+
ext('test.js') // 'js'
|
|
90
|
+
ext('test.foobar') // '' - empty string
|
|
91
|
+
ext('test.abw.CRASHED') // 'abw.CRASHED' - because it exists exactly in this form
|
|
92
|
+
ext('test.abw.crashed') // '' - empty string
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 4. extname
|
|
96
|
+
*/
|
|
97
|
+
// works the same way as 'extname' from 'node:path', but
|
|
98
|
+
// returns the extname if it is in the EXTENSIONS or find it herself
|
|
99
|
+
extname('test.foobar') // '.foobar'
|
|
100
|
+
extname('test.abw.CRASHED') // '.abw.CRASHED'
|
|
101
|
+
extname('test.abw.crashed') // '.crashed'
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 5. mimeType
|
|
105
|
+
*/
|
|
106
|
+
// returns the mime type or empty string
|
|
107
|
+
mimeType('test.foobar') // '' - empty string
|
|
108
|
+
mimeType('test.js') // 'text/javascript'
|
|
109
|
+
mimeType('test.JS') // 'text/javascript'
|
|
110
|
+
// but, in the schema 'shared-mime-info', sometimes the register matters:
|
|
111
|
+
mimeType('test.c') // text/x-c
|
|
112
|
+
mimeType('test.C') // text/x-c++src
|
|
113
|
+
// I do not know if this is right or not,
|
|
114
|
+
// but I think the Linux developers know better
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 6. mimeList
|
|
118
|
+
*/
|
|
119
|
+
// returns an array of all mime types
|
|
120
|
+
mimeList('test.js')
|
|
121
|
+
/*
|
|
122
|
+
[
|
|
123
|
+
"text/javascript",
|
|
124
|
+
"application/x-javascript",
|
|
125
|
+
"application/javascript"
|
|
126
|
+
]
|
|
127
|
+
*/
|
|
128
|
+
mimeList('test.foobar') // []
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### mimeHead
|
|
132
|
+
many mime types have their own main mime type
|
|
133
|
+
```js
|
|
134
|
+
import {
|
|
135
|
+
MIME_HEADS,
|
|
136
|
+
mimeHead
|
|
137
|
+
} from 'mime-xdg/heads'
|
|
138
|
+
|
|
139
|
+
// OBJECT
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 1. MIME_HEADS
|
|
143
|
+
*/
|
|
144
|
+
console.log(MIME_HEADS)
|
|
145
|
+
// MIME_HEADS equal to:
|
|
146
|
+
{
|
|
147
|
+
"message/rfc822": "text/plain",
|
|
148
|
+
"font/otf": "font/ttf",
|
|
149
|
+
"video/x-theora+ogg": "video/ogg",
|
|
150
|
+
"video/x-theora": "video/ogg",
|
|
151
|
+
/* etc... */
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// FUNCTION
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 2. mimeHead
|
|
158
|
+
*/
|
|
159
|
+
// returns main mime type or empty string
|
|
160
|
+
mimeHead('foobar') // '' - empty string
|
|
161
|
+
mimeHead('text/javascript') // 'application/ecmascript'
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### mimeNote
|
|
165
|
+
some mime types have a short description
|
|
166
|
+
```js
|
|
167
|
+
import {
|
|
168
|
+
MIME_NOTES,
|
|
169
|
+
mimeNote
|
|
170
|
+
} from 'mime-xdg/notes'
|
|
171
|
+
|
|
172
|
+
// OBJECT
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 1. MIME_NOTES
|
|
176
|
+
*/
|
|
177
|
+
console.log(MIME_NOTES)
|
|
178
|
+
// MIME_NOTES equal to:
|
|
179
|
+
{
|
|
180
|
+
"flv-application/octet-stream": "Flash video",
|
|
181
|
+
"message/rfc822": "email message",
|
|
182
|
+
"font/woff2": "WOFF2 font",
|
|
183
|
+
"font/woff": "WOFF font",
|
|
184
|
+
/* etc... */
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// FUNCTION
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 2. mimeNote
|
|
191
|
+
*/
|
|
192
|
+
// returns note or empty string
|
|
193
|
+
mimeNote('foobar') // '' - empty string
|
|
194
|
+
mimeNote('text/javascript') // 'JavaScript program'
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
[MIT](LICENSE)
|
package/heads/index.d.ts
ADDED
package/heads/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/*
|
|
3
|
+
dester builds:
|
|
4
|
+
heads.ts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: !0
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
var e = require("../lib"), r = require("../lib/heads"), _ = require("../lib/mimes"), E = (() => {
|
|
11
|
+
for (var E, M = e.createObject(), A = r._HEADS_DATA.length; A--; ) for (var i in r._HEADS_DATA[A]) E = r._HEADS_DATA[A][i = +i],
|
|
12
|
+
M[_._MIME_TYPES[A] + "/" + _._MIME_NAMES[A][i]] = _._MIME_TYPES[E[0]] + "/" + _._MIME_NAMES[E[0]][E[1]];
|
|
13
|
+
return M;
|
|
14
|
+
})();
|
|
15
|
+
|
|
16
|
+
exports.MIME_HEADS = E, exports.mimeHead = e => E[e] || "";
|
package/heads/index.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/*
|
|
3
|
+
dester builds:
|
|
4
|
+
heads.ts
|
|
5
|
+
*/
|
|
6
|
+
import { createObject as r } from "../lib";
|
|
7
|
+
|
|
8
|
+
import { _HEADS_DATA as o } from "../lib/heads";
|
|
9
|
+
|
|
10
|
+
import { _MIME_TYPES as i, _MIME_NAMES as m } from "../lib/mimes";
|
|
11
|
+
|
|
12
|
+
var t = (() => {
|
|
13
|
+
for (var t, e = r(), f = o.length; f--; ) for (var a in o[f]) t = o[f][a = +a],
|
|
14
|
+
e[i[f] + "/" + m[f][a]] = i[t[0]] + "/" + m[t[0]][t[1]];
|
|
15
|
+
return e;
|
|
16
|
+
})(), e = r => t[r] || "";
|
|
17
|
+
|
|
18
|
+
export { t as MIME_HEADS, e as mimeHead };
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/*
|
|
3
|
+
dester builds:
|
|
4
|
+
index.ts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: !0
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
var e = require("./lib"), r = require("./lib/mimes"), t = (() => {
|
|
11
|
+
var t = e.createObject();
|
|
12
|
+
for (var E in r._EXTENSIONS) {
|
|
13
|
+
t[E] = [];
|
|
14
|
+
for (var M = r._EXTENSIONS[E], i = 0, _ = 0; _ < M.length; _++) t[E][i++] = r._MIME_TYPES[M[_]] + "/" + r._MIME_NAMES[M[_++]][M[_]];
|
|
15
|
+
}
|
|
16
|
+
return t;
|
|
17
|
+
})(), E = (() => {
|
|
18
|
+
for (var t = e.createObject(), E = r._MIME_TYPES.length; E-- > 0; ) {
|
|
19
|
+
t[r._MIME_TYPES[E]] = e.createObject();
|
|
20
|
+
for (var M = r._MIME_NAMES[E].length; M-- > 0; ) t[r._MIME_TYPES[E]][r._MIME_NAMES[E][M]] = !0;
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
})(), M = e => {
|
|
24
|
+
for (var r, E = "", M = "", i = "", _ = "", a = (e = e.trim()).length; a-- > 0; ) {
|
|
25
|
+
if ("." === (r = e[a])) M in t && (E = M) || i in t && (E = i) || _ in t && (E = _); else if ("/" === r || "\\" === r) break;
|
|
26
|
+
M = r + M, i = r.toUpperCase() + i, _ = r.toLowerCase() + _;
|
|
27
|
+
}
|
|
28
|
+
return E;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.EXTENSIONS = t, exports.MIME_TYPES = E, exports.ext = M, exports.extname = e => {
|
|
32
|
+
var r = M(e);
|
|
33
|
+
if (!r) {
|
|
34
|
+
var t = e.lastIndexOf(".");
|
|
35
|
+
t > -1 && (r = e.slice(t + 1));
|
|
36
|
+
}
|
|
37
|
+
return r ? "." + r : "";
|
|
38
|
+
}, exports.mimeList = e => (e = M(e)) ? t[e].slice(0) : [], exports.mimeType = e => (e = M(e)) ? t[e][0] : e;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/*
|
|
3
|
+
dester builds:
|
|
4
|
+
index.ts
|
|
5
|
+
*/
|
|
6
|
+
import { createObject as r } from "./lib";
|
|
7
|
+
|
|
8
|
+
import { _EXTENSIONS as e, _MIME_TYPES as i, _MIME_NAMES as t } from "./lib/mimes";
|
|
9
|
+
|
|
10
|
+
var a = (() => {
|
|
11
|
+
var a = r();
|
|
12
|
+
for (var n in e) {
|
|
13
|
+
a[n] = [];
|
|
14
|
+
for (var o = e[n], f = 0, l = 0; l < o.length; l++) a[n][f++] = i[o[l]] + "/" + t[o[l++]][o[l]];
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
})(), n = (() => {
|
|
18
|
+
for (var e = r(), a = i.length; a-- > 0; ) {
|
|
19
|
+
e[i[a]] = r();
|
|
20
|
+
for (var n = t[a].length; n-- > 0; ) e[i[a]][t[a][n]] = !0;
|
|
21
|
+
}
|
|
22
|
+
return e;
|
|
23
|
+
})(), o = r => {
|
|
24
|
+
for (var e, i = "", t = "", n = "", o = "", f = (r = r.trim()).length; f-- > 0; ) {
|
|
25
|
+
if ("." === (e = r[f])) t in a && (i = t) || n in a && (i = n) || o in a && (i = o); else if ("/" === e || "\\" === e) break;
|
|
26
|
+
t = e + t, n = e.toUpperCase() + n, o = e.toLowerCase() + o;
|
|
27
|
+
}
|
|
28
|
+
return i;
|
|
29
|
+
}, f = r => {
|
|
30
|
+
var e = o(r);
|
|
31
|
+
if (!e) {
|
|
32
|
+
var i = r.lastIndexOf(".");
|
|
33
|
+
i > -1 && (e = r.slice(i + 1));
|
|
34
|
+
}
|
|
35
|
+
return e ? "." + e : "";
|
|
36
|
+
}, l = r => (r = o(r)) ? a[r][0] : r, v = r => (r = o(r)) ? a[r].slice(0) : [];
|
|
37
|
+
|
|
38
|
+
export { a as EXTENSIONS, n as MIME_TYPES, o as ext, f as extname, v as mimeList, l as mimeType };
|