@tinyhttp/type-is 2.0.5 → 2.0.6

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/index.js CHANGED
@@ -1,84 +1,62 @@
1
- import { lookup } from 'es-mime-types';
2
- import * as typer from 'es-content-type';
3
-
1
+ import { lookup } from "es-mime-types";
2
+ import * as typer from "es-content-type";
4
3
  function normalizeType(value) {
5
- // parse the type
6
- const type = typer.parse(value);
7
- type.parameters = {};
8
- // reformat it
9
- return typer.format(type);
4
+ const type = typer.parse(value);
5
+ type.parameters = {};
6
+ return typer.format(type);
10
7
  }
11
8
  function tryNormalizeType(value) {
12
- if (!value)
13
- return null;
14
- try {
15
- return normalizeType(value);
16
- }
17
- catch (err) {
18
- return null;
19
- }
9
+ if (!value)
10
+ return null;
11
+ try {
12
+ return normalizeType(value);
13
+ } catch (err) {
14
+ return null;
15
+ }
20
16
  }
21
17
  function mimeMatch(expected, actual) {
22
- // invalid type
23
- if (expected === false)
24
- return false;
25
- // split types
26
- const actualParts = actual.split('/');
27
- const expectedParts = expected.split('/');
28
- // invalid format
29
- if (actualParts.length !== 2 || expectedParts.length !== 2)
30
- return false;
31
- // validate type
32
- if (expectedParts[0] !== '*' && expectedParts[0] !== actualParts[0])
33
- return false;
34
- // validate suffix wildcard
35
- if (expectedParts[1].substr(0, 2) === '*+')
36
- return (expectedParts[1].length <= actualParts[1].length + 1 &&
37
- expectedParts[1].substr(1) === actualParts[1].substr(1 - expectedParts[1].length));
38
- // validate subtype
39
- if (expectedParts[1] !== '*' && expectedParts[1] !== actualParts[1])
40
- return false;
41
- return true;
18
+ if (expected === false)
19
+ return false;
20
+ const actualParts = actual.split("/");
21
+ const expectedParts = expected.split("/");
22
+ if (actualParts.length !== 2 || expectedParts.length !== 2)
23
+ return false;
24
+ if (expectedParts[0] !== "*" && expectedParts[0] !== actualParts[0])
25
+ return false;
26
+ if (expectedParts[1].substr(0, 2) === "*+")
27
+ return expectedParts[1].length <= actualParts[1].length + 1 && expectedParts[1].substr(1) === actualParts[1].substr(1 - expectedParts[1].length);
28
+ if (expectedParts[1] !== "*" && expectedParts[1] !== actualParts[1])
29
+ return false;
30
+ return true;
42
31
  }
43
32
  function normalize(type) {
44
- // invalid type
45
- if (typeof type !== 'string')
46
- return false;
47
- switch (type) {
48
- case 'urlencoded':
49
- return 'application/x-www-form-urlencoded';
50
- case 'multipart':
51
- return 'multipart/*';
52
- }
53
- // "+json" -> "*/*+json" expando
54
- if (type[0] === '+')
55
- return '*/*' + type;
56
- return type.indexOf('/') === -1 ? lookup(type) : type;
33
+ if (typeof type !== "string")
34
+ return false;
35
+ switch (type) {
36
+ case "urlencoded":
37
+ return "application/x-www-form-urlencoded";
38
+ case "multipart":
39
+ return "multipart/*";
40
+ }
41
+ if (type[0] === "+")
42
+ return "*/*" + type;
43
+ return type.indexOf("/") === -1 ? lookup(type) : type;
57
44
  }
58
- /**
59
- * Compare a `value` content-type with `types`.
60
- * Each `type` can be an extension like `html`,
61
- * a special shortcut like `multipart` or `urlencoded`,
62
- * or a mime type.
63
- */
64
45
  const typeIs = (value, ...types) => {
65
- let i;
66
- // remove parameters and normalize
67
- const val = tryNormalizeType(value);
68
- // no type or invalid
69
- if (!val)
70
- return false;
71
- // no types, return the content type
72
- if (!types || !types.length)
73
- return val;
74
- let type;
75
- for (i = 0; i < types.length; i++) {
76
- if (mimeMatch(normalize((type = types[i])), val)) {
77
- return type[0] === '+' || type.indexOf('*') !== -1 ? val : type;
78
- }
79
- }
80
- // no matches
46
+ let i;
47
+ const val = tryNormalizeType(value);
48
+ if (!val)
81
49
  return false;
50
+ if (!types || !types.length)
51
+ return val;
52
+ let type;
53
+ for (i = 0; i < types.length; i++) {
54
+ if (mimeMatch(normalize(type = types[i]), val)) {
55
+ return type[0] === "+" || type.indexOf("*") !== -1 ? val : type;
56
+ }
57
+ }
58
+ return false;
59
+ };
60
+ export {
61
+ typeIs
82
62
  };
83
-
84
- export { typeIs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinyhttp/type-is",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "type": "module",
5
5
  "description": "TypeScript rewrite of type-is with CJS and ESM targets",
6
6
  "homepage": "https://tinyhttp.v1rtl.site",
@@ -32,6 +32,8 @@
32
32
  "es-mime-types": "^0.1.4"
33
33
  },
34
34
  "scripts": {
35
- "build": "rollup -c"
35
+ "dev": "vite",
36
+ "build": "vite build",
37
+ "postbuild": "tsc --emitDeclarationOnly"
36
38
  }
37
39
  }
package/vite.config.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { build } from '../../config/build'
2
+ import { dependencies } from './package.json'
3
+
4
+ export default build(dependencies)