@takeshape/util 11.143.0 → 11.144.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/dist/common/mime.js +30 -5
- package/package.json +4 -5
package/dist/common/mime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import mime from 'mime
|
|
1
|
+
import mime from 'mime';
|
|
2
2
|
const compressedMimeTypes = new Set([
|
|
3
3
|
'application/atom+xml',
|
|
4
4
|
'application/javascript',
|
|
@@ -35,15 +35,40 @@ const compressedMimeTypes = new Set([
|
|
|
35
35
|
'text/xml'
|
|
36
36
|
]);
|
|
37
37
|
// Application/octetstream
|
|
38
|
-
const DEFAULT_TYPE = mime.
|
|
38
|
+
const DEFAULT_TYPE = mime.getType('bin');
|
|
39
|
+
/**
|
|
40
|
+
* Extracted from implementation https://github.com/jshttp/mime-types/blob/541f9c57b3e418fc449fa84be4a69a1e1a7835db/index.js#L51
|
|
41
|
+
* It returns for all types defined in mime-db https://github.com/jshttp/mime-db/blob/master/db.json
|
|
42
|
+
* @param mimeType
|
|
43
|
+
*/
|
|
44
|
+
function getDefaultCharset(mimeType) {
|
|
45
|
+
const [type, subtype] = mimeType.toLowerCase().split('/');
|
|
46
|
+
if (type === 'text') {
|
|
47
|
+
return 'UTF-8';
|
|
48
|
+
}
|
|
49
|
+
if (type === 'application') {
|
|
50
|
+
if (subtype.includes('+xml') ||
|
|
51
|
+
subtype.includes('+json') ||
|
|
52
|
+
subtype === 'json' ||
|
|
53
|
+
subtype === 'javascript' ||
|
|
54
|
+
subtype === 'vnd.syncml.dm+wbxml' ||
|
|
55
|
+
subtype === 'vnd.wap.wbxml') {
|
|
56
|
+
return 'UTF-8';
|
|
57
|
+
}
|
|
58
|
+
if (subtype === 'news-checkgroups' || subtype === 'news-groupinfo')
|
|
59
|
+
return 'US-ASCII';
|
|
60
|
+
if (subtype === 'prs.cyn')
|
|
61
|
+
return '7-BIT';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
39
64
|
/**
|
|
40
65
|
* Gets the content type of the file, based on it's extension.
|
|
41
66
|
* @param {String} src Path to file fow which content type should be evaluated.
|
|
42
67
|
* @return {String} Returns string with content type and charset.
|
|
43
68
|
*/
|
|
44
69
|
export function contentType(src) {
|
|
45
|
-
let type = (mime.
|
|
46
|
-
const charset =
|
|
70
|
+
let type = (mime.getType(src) || DEFAULT_TYPE).replace('-', '');
|
|
71
|
+
const charset = getDefaultCharset(type);
|
|
47
72
|
if (charset) {
|
|
48
73
|
type += `; charset=${charset}`;
|
|
49
74
|
}
|
|
@@ -55,6 +80,6 @@ export function contentType(src) {
|
|
|
55
80
|
* @return {Boolean} Returns true if we should compress
|
|
56
81
|
*/
|
|
57
82
|
export function shouldCompress(src) {
|
|
58
|
-
const mimeType = mime.
|
|
83
|
+
const mimeType = mime.getType(src);
|
|
59
84
|
return Boolean(mimeType && compressedMimeTypes.has(mimeType));
|
|
60
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/util",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.144.1",
|
|
4
4
|
"description": "Shared utilities",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"htmlparser2": "9.1.0",
|
|
41
41
|
"lodash": "4.17.21",
|
|
42
42
|
"markdown-draft-js": "github:incompl/markdown-draft-js#deterministic-entity-keys-with-lib",
|
|
43
|
-
"mime
|
|
43
|
+
"mime": "4.1.0",
|
|
44
44
|
"shortid": "2.2.16",
|
|
45
45
|
"tiny-invariant": "1.3.3",
|
|
46
46
|
"uint8array-extras": "1.4.0",
|
|
47
47
|
"url-parse": "1.5.3",
|
|
48
|
-
"@takeshape/prism": "11.
|
|
49
|
-
"@takeshape/routing": "11.
|
|
48
|
+
"@takeshape/prism": "11.144.1",
|
|
49
|
+
"@takeshape/routing": "11.144.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/classnames": "2.2.11",
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
"@types/he": "1.2.0",
|
|
55
55
|
"@types/lodash": "4.17.20",
|
|
56
56
|
"@types/markdown-draft-js": "2.2.4",
|
|
57
|
-
"@types/mime-types": "2.1.0",
|
|
58
57
|
"@types/shortid": "0.0.29",
|
|
59
58
|
"domhandler": "5.0.3",
|
|
60
59
|
"stripe": "13.8.0"
|