@tinyhttp/type-is 1.3.0 → 2.0.3

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.
Files changed (2) hide show
  1. package/package.json +8 -17
  2. package/dist/index.cjs +0 -110
package/package.json CHANGED
@@ -1,25 +1,16 @@
1
1
  {
2
2
  "name": "@tinyhttp/type-is",
3
- "version": "1.3.0",
3
+ "version": "2.0.3",
4
4
  "type": "module",
5
5
  "description": "TypeScript rewrite of type-is with CJS and ESM targets",
6
6
  "homepage": "https://tinyhttp.v1rtl.site",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/talentlessguy/tinyhttp.git",
9
+ "url": "https://github.com/tinyhttp/tinyhttp.git",
10
10
  "directory": "packages/type-is"
11
11
  },
12
- "main": "./dist/index.cjs",
13
12
  "types": "./dist/index.d.ts",
14
- "module": "./dist/index.js",
15
- "exports": {
16
- ".": {
17
- "import": "./dist/index.js",
18
- "require": "./dist/index.cjs"
19
- },
20
- "./package.json": "./package.json",
21
- "./": "./"
22
- },
13
+ "exports": "./dist/index.js",
23
14
  "keywords": [
24
15
  "tinyhttp",
25
16
  "node.js",
@@ -36,11 +27,11 @@
36
27
  },
37
28
  "author": "v1rtl",
38
29
  "license": "MIT",
30
+ "dependencies": {
31
+ "es-content-type": "^0.1.0",
32
+ "es-mime-types": "^0.1.4"
33
+ },
39
34
  "scripts": {
40
35
  "build": "rollup -c"
41
- },
42
- "dependencies": {
43
- "es-content-type": "^0.0.10",
44
- "es-mime-types": "^0.0.16"
45
36
  }
46
- }
37
+ }
package/dist/index.cjs DELETED
@@ -1,110 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var esMimeTypes = require('es-mime-types');
6
- var typer = require('es-content-type');
7
-
8
- function _interopNamespace(e) {
9
- if (e && e.__esModule) return e;
10
- var n = Object.create(null);
11
- if (e) {
12
- Object.keys(e).forEach(function (k) {
13
- if (k !== 'default') {
14
- var d = Object.getOwnPropertyDescriptor(e, k);
15
- Object.defineProperty(n, k, d.get ? d : {
16
- enumerable: true,
17
- get: function () {
18
- return e[k];
19
- }
20
- });
21
- }
22
- });
23
- }
24
- n['default'] = e;
25
- return Object.freeze(n);
26
- }
27
-
28
- var typer__namespace = /*#__PURE__*/_interopNamespace(typer);
29
-
30
- function normalizeType(value) {
31
- // parse the type
32
- const type = typer__namespace.parse(value);
33
- type.parameters = {};
34
- // reformat it
35
- return typer__namespace.format(type);
36
- }
37
- function tryNormalizeType(value) {
38
- if (!value)
39
- return null;
40
- try {
41
- return normalizeType(value);
42
- }
43
- catch (err) {
44
- return null;
45
- }
46
- }
47
- function mimeMatch(expected, actual) {
48
- // invalid type
49
- if (expected === false)
50
- return false;
51
- // split types
52
- const actualParts = actual.split('/');
53
- const expectedParts = expected.split('/');
54
- // invalid format
55
- if (actualParts.length !== 2 || expectedParts.length !== 2)
56
- return false;
57
- // validate type
58
- if (expectedParts[0] !== '*' && expectedParts[0] !== actualParts[0])
59
- return false;
60
- // validate suffix wildcard
61
- if (expectedParts[1].substr(0, 2) === '*+')
62
- return (expectedParts[1].length <= actualParts[1].length + 1 &&
63
- expectedParts[1].substr(1) === actualParts[1].substr(1 - expectedParts[1].length));
64
- // validate subtype
65
- if (expectedParts[1] !== '*' && expectedParts[1] !== actualParts[1])
66
- return false;
67
- return true;
68
- }
69
- function normalize(type) {
70
- // invalid type
71
- if (typeof type !== 'string')
72
- return false;
73
- switch (type) {
74
- case 'urlencoded':
75
- return 'application/x-www-form-urlencoded';
76
- case 'multipart':
77
- return 'multipart/*';
78
- }
79
- // "+json" -> "*/*+json" expando
80
- if (type[0] === '+')
81
- return '*/*' + type;
82
- return type.indexOf('/') === -1 ? esMimeTypes.lookup(type) : type;
83
- }
84
- /**
85
- * Compare a `value` content-type with `types`.
86
- * Each `type` can be an extension like `html`,
87
- * a special shortcut like `multipart` or `urlencoded`,
88
- * or a mime type.
89
- */
90
- const typeIs = (value, ...types) => {
91
- let i;
92
- // remove parameters and normalize
93
- const val = tryNormalizeType(value);
94
- // no type or invalid
95
- if (!val)
96
- return false;
97
- // no types, return the content type
98
- if (!types || !types.length)
99
- return val;
100
- let type;
101
- for (i = 0; i < types.length; i++) {
102
- if (mimeMatch(normalize((type = types[i])), val)) {
103
- return type[0] === '+' || type.indexOf('*') !== -1 ? val : type;
104
- }
105
- }
106
- // no matches
107
- return false;
108
- };
109
-
110
- exports.typeIs = typeIs;