@depup/type-is 2.0.1-depup.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/HISTORY.md +292 -0
- package/LICENSE +23 -0
- package/README.md +31 -0
- package/changes.json +10 -0
- package/index.js +250 -0
- package/package.json +68 -0
package/HISTORY.md
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
2.0.1 / 2025-03-27
|
|
2
|
+
==========
|
|
3
|
+
|
|
4
|
+
2.0.0 / 2024-08-31
|
|
5
|
+
==========
|
|
6
|
+
|
|
7
|
+
* Drop node <18
|
|
8
|
+
* Use `content-type@^1.0.5` and `media-typer@^1.0.0` for type validation
|
|
9
|
+
- No behavior changes, upgrades `media-typer`
|
|
10
|
+
* deps: mime-types@^3.0.0
|
|
11
|
+
- Add `application/toml` with extension `.toml`
|
|
12
|
+
- Add `application/ubjson` with extension `.ubj`
|
|
13
|
+
- Add `application/x-keepass2` with extension `.kdbx`
|
|
14
|
+
- Add deprecated iWorks mime types and extensions
|
|
15
|
+
- Add extension `.amr` to `audio/amr`
|
|
16
|
+
- Add extension `.cjs` to `application/node`
|
|
17
|
+
- Add extension `.dbf` to `application/vnd.dbf`
|
|
18
|
+
- Add extension `.m4s` to `video/iso.segment`
|
|
19
|
+
- Add extension `.mvt` to `application/vnd.mapbox-vector-tile`
|
|
20
|
+
- Add extension `.mxmf` to `audio/mobile-xmf`
|
|
21
|
+
- Add extension `.opus` to `audio/ogg`
|
|
22
|
+
- Add extension `.rar` to `application/vnd.rar`
|
|
23
|
+
- Add extension `.td` to `application/urc-targetdesc+xml`
|
|
24
|
+
- Add extension `.trig` to `application/trig`
|
|
25
|
+
- Add extensions from IANA for `application/*+xml` types
|
|
26
|
+
- Add `image/avif` with extension `.avif`
|
|
27
|
+
- Add `image/ktx2` with extension `.ktx2`
|
|
28
|
+
- Add `image/vnd.ms-dds` with extension `.dds`
|
|
29
|
+
- Add new upstream MIME types
|
|
30
|
+
- Fix extension of `application/vnd.apple.keynote` to be `.key`
|
|
31
|
+
- Remove ambigious extensions from IANA for `application/*+xml` types
|
|
32
|
+
- Update primary extension to `.es` for `application/ecmascript`
|
|
33
|
+
|
|
34
|
+
1.6.18 / 2019-04-26
|
|
35
|
+
===================
|
|
36
|
+
|
|
37
|
+
* Fix regression passing request object to `typeis.is`
|
|
38
|
+
|
|
39
|
+
1.6.17 / 2019-04-25
|
|
40
|
+
===================
|
|
41
|
+
|
|
42
|
+
* deps: mime-types@~2.1.24
|
|
43
|
+
- Add Apple file extensions from IANA
|
|
44
|
+
- Add extension `.csl` to `application/vnd.citationstyles.style+xml`
|
|
45
|
+
- Add extension `.es` to `application/ecmascript`
|
|
46
|
+
- Add extension `.nq` to `application/n-quads`
|
|
47
|
+
- Add extension `.nt` to `application/n-triples`
|
|
48
|
+
- Add extension `.owl` to `application/rdf+xml`
|
|
49
|
+
- Add extensions `.siv` and `.sieve` to `application/sieve`
|
|
50
|
+
- Add extensions from IANA for `image/*` types
|
|
51
|
+
- Add extensions from IANA for `model/*` types
|
|
52
|
+
- Add extensions to HEIC image types
|
|
53
|
+
- Add new mime types
|
|
54
|
+
- Add `text/mdx` with extension `.mdx`
|
|
55
|
+
* perf: prevent internal `throw` on invalid type
|
|
56
|
+
|
|
57
|
+
1.6.16 / 2018-02-16
|
|
58
|
+
===================
|
|
59
|
+
|
|
60
|
+
* deps: mime-types@~2.1.18
|
|
61
|
+
- Add `application/raml+yaml` with extension `.raml`
|
|
62
|
+
- Add `application/wasm` with extension `.wasm`
|
|
63
|
+
- Add `text/shex` with extension `.shex`
|
|
64
|
+
- Add extensions for JPEG-2000 images
|
|
65
|
+
- Add extensions from IANA for `message/*` types
|
|
66
|
+
- Add extension `.mjs` to `application/javascript`
|
|
67
|
+
- Add extension `.wadl` to `application/vnd.sun.wadl+xml`
|
|
68
|
+
- Add extension `.gz` to `application/gzip`
|
|
69
|
+
- Add glTF types and extensions
|
|
70
|
+
- Add new mime types
|
|
71
|
+
- Update extensions `.md` and `.markdown` to be `text/markdown`
|
|
72
|
+
- Update font MIME types
|
|
73
|
+
- Update `text/hjson` to registered `application/hjson`
|
|
74
|
+
|
|
75
|
+
1.6.15 / 2017-03-31
|
|
76
|
+
===================
|
|
77
|
+
|
|
78
|
+
* deps: mime-types@~2.1.15
|
|
79
|
+
- Add new mime types
|
|
80
|
+
|
|
81
|
+
1.6.14 / 2016-11-18
|
|
82
|
+
===================
|
|
83
|
+
|
|
84
|
+
* deps: mime-types@~2.1.13
|
|
85
|
+
- Add new mime types
|
|
86
|
+
|
|
87
|
+
1.6.13 / 2016-05-18
|
|
88
|
+
===================
|
|
89
|
+
|
|
90
|
+
* deps: mime-types@~2.1.11
|
|
91
|
+
- Add new mime types
|
|
92
|
+
|
|
93
|
+
1.6.12 / 2016-02-28
|
|
94
|
+
===================
|
|
95
|
+
|
|
96
|
+
* deps: mime-types@~2.1.10
|
|
97
|
+
- Add new mime types
|
|
98
|
+
- Fix extension of `application/dash+xml`
|
|
99
|
+
- Update primary extension for `audio/mp4`
|
|
100
|
+
|
|
101
|
+
1.6.11 / 2016-01-29
|
|
102
|
+
===================
|
|
103
|
+
|
|
104
|
+
* deps: mime-types@~2.1.9
|
|
105
|
+
- Add new mime types
|
|
106
|
+
|
|
107
|
+
1.6.10 / 2015-12-01
|
|
108
|
+
===================
|
|
109
|
+
|
|
110
|
+
* deps: mime-types@~2.1.8
|
|
111
|
+
- Add new mime types
|
|
112
|
+
|
|
113
|
+
1.6.9 / 2015-09-27
|
|
114
|
+
==================
|
|
115
|
+
|
|
116
|
+
* deps: mime-types@~2.1.7
|
|
117
|
+
- Add new mime types
|
|
118
|
+
|
|
119
|
+
1.6.8 / 2015-09-04
|
|
120
|
+
==================
|
|
121
|
+
|
|
122
|
+
* deps: mime-types@~2.1.6
|
|
123
|
+
- Add new mime types
|
|
124
|
+
|
|
125
|
+
1.6.7 / 2015-08-20
|
|
126
|
+
==================
|
|
127
|
+
|
|
128
|
+
* Fix type error when given invalid type to match against
|
|
129
|
+
* deps: mime-types@~2.1.5
|
|
130
|
+
- Add new mime types
|
|
131
|
+
|
|
132
|
+
1.6.6 / 2015-07-31
|
|
133
|
+
==================
|
|
134
|
+
|
|
135
|
+
* deps: mime-types@~2.1.4
|
|
136
|
+
- Add new mime types
|
|
137
|
+
|
|
138
|
+
1.6.5 / 2015-07-16
|
|
139
|
+
==================
|
|
140
|
+
|
|
141
|
+
* deps: mime-types@~2.1.3
|
|
142
|
+
- Add new mime types
|
|
143
|
+
|
|
144
|
+
1.6.4 / 2015-07-01
|
|
145
|
+
==================
|
|
146
|
+
|
|
147
|
+
* deps: mime-types@~2.1.2
|
|
148
|
+
- Add new mime types
|
|
149
|
+
* perf: enable strict mode
|
|
150
|
+
* perf: remove argument reassignment
|
|
151
|
+
|
|
152
|
+
1.6.3 / 2015-06-08
|
|
153
|
+
==================
|
|
154
|
+
|
|
155
|
+
* deps: mime-types@~2.1.1
|
|
156
|
+
- Add new mime types
|
|
157
|
+
* perf: reduce try block size
|
|
158
|
+
* perf: remove bitwise operations
|
|
159
|
+
|
|
160
|
+
1.6.2 / 2015-05-10
|
|
161
|
+
==================
|
|
162
|
+
|
|
163
|
+
* deps: mime-types@~2.0.11
|
|
164
|
+
- Add new mime types
|
|
165
|
+
|
|
166
|
+
1.6.1 / 2015-03-13
|
|
167
|
+
==================
|
|
168
|
+
|
|
169
|
+
* deps: mime-types@~2.0.10
|
|
170
|
+
- Add new mime types
|
|
171
|
+
|
|
172
|
+
1.6.0 / 2015-02-12
|
|
173
|
+
==================
|
|
174
|
+
|
|
175
|
+
* fix false-positives in `hasBody` `Transfer-Encoding` check
|
|
176
|
+
* support wildcard for both type and subtype (`*/*`)
|
|
177
|
+
|
|
178
|
+
1.5.7 / 2015-02-09
|
|
179
|
+
==================
|
|
180
|
+
|
|
181
|
+
* fix argument reassignment
|
|
182
|
+
* deps: mime-types@~2.0.9
|
|
183
|
+
- Add new mime types
|
|
184
|
+
|
|
185
|
+
1.5.6 / 2015-01-29
|
|
186
|
+
==================
|
|
187
|
+
|
|
188
|
+
* deps: mime-types@~2.0.8
|
|
189
|
+
- Add new mime types
|
|
190
|
+
|
|
191
|
+
1.5.5 / 2014-12-30
|
|
192
|
+
==================
|
|
193
|
+
|
|
194
|
+
* deps: mime-types@~2.0.7
|
|
195
|
+
- Add new mime types
|
|
196
|
+
- Fix missing extensions
|
|
197
|
+
- Fix various invalid MIME type entries
|
|
198
|
+
- Remove example template MIME types
|
|
199
|
+
- deps: mime-db@~1.5.0
|
|
200
|
+
|
|
201
|
+
1.5.4 / 2014-12-10
|
|
202
|
+
==================
|
|
203
|
+
|
|
204
|
+
* deps: mime-types@~2.0.4
|
|
205
|
+
- Add new mime types
|
|
206
|
+
- deps: mime-db@~1.3.0
|
|
207
|
+
|
|
208
|
+
1.5.3 / 2014-11-09
|
|
209
|
+
==================
|
|
210
|
+
|
|
211
|
+
* deps: mime-types@~2.0.3
|
|
212
|
+
- Add new mime types
|
|
213
|
+
- deps: mime-db@~1.2.0
|
|
214
|
+
|
|
215
|
+
1.5.2 / 2014-09-28
|
|
216
|
+
==================
|
|
217
|
+
|
|
218
|
+
* deps: mime-types@~2.0.2
|
|
219
|
+
- Add new mime types
|
|
220
|
+
- deps: mime-db@~1.1.0
|
|
221
|
+
|
|
222
|
+
1.5.1 / 2014-09-07
|
|
223
|
+
==================
|
|
224
|
+
|
|
225
|
+
* Support Node.js 0.6
|
|
226
|
+
* deps: media-typer@0.3.0
|
|
227
|
+
* deps: mime-types@~2.0.1
|
|
228
|
+
- Support Node.js 0.6
|
|
229
|
+
|
|
230
|
+
1.5.0 / 2014-09-05
|
|
231
|
+
==================
|
|
232
|
+
|
|
233
|
+
* fix `hasbody` to be true for `content-length: 0`
|
|
234
|
+
|
|
235
|
+
1.4.0 / 2014-09-02
|
|
236
|
+
==================
|
|
237
|
+
|
|
238
|
+
* update mime-types
|
|
239
|
+
|
|
240
|
+
1.3.2 / 2014-06-24
|
|
241
|
+
==================
|
|
242
|
+
|
|
243
|
+
* use `~` range on mime-types
|
|
244
|
+
|
|
245
|
+
1.3.1 / 2014-06-19
|
|
246
|
+
==================
|
|
247
|
+
|
|
248
|
+
* fix global variable leak
|
|
249
|
+
|
|
250
|
+
1.3.0 / 2014-06-19
|
|
251
|
+
==================
|
|
252
|
+
|
|
253
|
+
* improve type parsing
|
|
254
|
+
|
|
255
|
+
- invalid media type never matches
|
|
256
|
+
- media type not case-sensitive
|
|
257
|
+
- extra LWS does not affect results
|
|
258
|
+
|
|
259
|
+
1.2.2 / 2014-06-19
|
|
260
|
+
==================
|
|
261
|
+
|
|
262
|
+
* fix behavior on unknown type argument
|
|
263
|
+
|
|
264
|
+
1.2.1 / 2014-06-03
|
|
265
|
+
==================
|
|
266
|
+
|
|
267
|
+
* switch dependency from `mime` to `mime-types@1.0.0`
|
|
268
|
+
|
|
269
|
+
1.2.0 / 2014-05-11
|
|
270
|
+
==================
|
|
271
|
+
|
|
272
|
+
* support suffix matching:
|
|
273
|
+
|
|
274
|
+
- `+json` matches `application/vnd+json`
|
|
275
|
+
- `*/vnd+json` matches `application/vnd+json`
|
|
276
|
+
- `application/*+json` matches `application/vnd+json`
|
|
277
|
+
|
|
278
|
+
1.1.0 / 2014-04-12
|
|
279
|
+
==================
|
|
280
|
+
|
|
281
|
+
* add non-array values support
|
|
282
|
+
* expose internal utilities:
|
|
283
|
+
|
|
284
|
+
- `.is()`
|
|
285
|
+
- `.hasBody()`
|
|
286
|
+
- `.normalize()`
|
|
287
|
+
- `.match()`
|
|
288
|
+
|
|
289
|
+
1.0.1 / 2014-03-30
|
|
290
|
+
==================
|
|
291
|
+
|
|
292
|
+
* add `multipart` as a shorthand
|
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
|
|
4
|
+
Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
+
a copy of this software and associated documentation files (the
|
|
8
|
+
'Software'), to deal in the Software without restriction, including
|
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
12
|
+
the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @depup/type-is
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [type-is](https://www.npmjs.com/package/type-is)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/type-is
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [type-is](https://www.npmjs.com/package/type-is) @ 2.0.1 |
|
|
17
|
+
| Processed | 2026-03-19 |
|
|
18
|
+
| Smoke test | passed |
|
|
19
|
+
| Deps updated | 1 |
|
|
20
|
+
|
|
21
|
+
## Dependency Changes
|
|
22
|
+
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| mime-types | ^3.0.0 | ^3.0.2 |
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/type-is
|
|
30
|
+
|
|
31
|
+
License inherited from the original package.
|
package/changes.json
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* type-is
|
|
3
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
4
|
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Module dependencies.
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
var contentType = require('content-type')
|
|
16
|
+
var mime = require('mime-types')
|
|
17
|
+
var typer = require('media-typer')
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Module exports.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
module.exports = typeofrequest
|
|
25
|
+
module.exports.is = typeis
|
|
26
|
+
module.exports.hasBody = hasbody
|
|
27
|
+
module.exports.normalize = normalize
|
|
28
|
+
module.exports.match = mimeMatch
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Compare a `value` content-type with `types`.
|
|
32
|
+
* Each `type` can be an extension like `html`,
|
|
33
|
+
* a special shortcut like `multipart` or `urlencoded`,
|
|
34
|
+
* or a mime type.
|
|
35
|
+
*
|
|
36
|
+
* If no types match, `false` is returned.
|
|
37
|
+
* Otherwise, the first `type` that matches is returned.
|
|
38
|
+
*
|
|
39
|
+
* @param {String} value
|
|
40
|
+
* @param {Array} types
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
function typeis (value, types_) {
|
|
45
|
+
var i
|
|
46
|
+
var types = types_
|
|
47
|
+
|
|
48
|
+
// remove parameters and normalize
|
|
49
|
+
var val = tryNormalizeType(value)
|
|
50
|
+
|
|
51
|
+
// no type or invalid
|
|
52
|
+
if (!val) {
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// support flattened arguments
|
|
57
|
+
if (types && !Array.isArray(types)) {
|
|
58
|
+
types = new Array(arguments.length - 1)
|
|
59
|
+
for (i = 0; i < types.length; i++) {
|
|
60
|
+
types[i] = arguments[i + 1]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// no types, return the content type
|
|
65
|
+
if (!types || !types.length) {
|
|
66
|
+
return val
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var type
|
|
70
|
+
for (i = 0; i < types.length; i++) {
|
|
71
|
+
if (mimeMatch(normalize(type = types[i]), val)) {
|
|
72
|
+
return type[0] === '+' || type.indexOf('*') !== -1
|
|
73
|
+
? val
|
|
74
|
+
: type
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// no matches
|
|
79
|
+
return false
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Check if a request has a request body.
|
|
84
|
+
* A request with a body __must__ either have `transfer-encoding`
|
|
85
|
+
* or `content-length` headers set.
|
|
86
|
+
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3
|
|
87
|
+
*
|
|
88
|
+
* @param {Object} request
|
|
89
|
+
* @return {Boolean}
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
function hasbody (req) {
|
|
94
|
+
return req.headers['transfer-encoding'] !== undefined ||
|
|
95
|
+
!isNaN(req.headers['content-length'])
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Check if the incoming request contains the "Content-Type"
|
|
100
|
+
* header field, and it contains any of the give mime `type`s.
|
|
101
|
+
* If there is no request body, `null` is returned.
|
|
102
|
+
* If there is no content type, `false` is returned.
|
|
103
|
+
* Otherwise, it returns the first `type` that matches.
|
|
104
|
+
*
|
|
105
|
+
* Examples:
|
|
106
|
+
*
|
|
107
|
+
* // With Content-Type: text/html; charset=utf-8
|
|
108
|
+
* this.is('html'); // => 'html'
|
|
109
|
+
* this.is('text/html'); // => 'text/html'
|
|
110
|
+
* this.is('text/*', 'application/json'); // => 'text/html'
|
|
111
|
+
*
|
|
112
|
+
* // When Content-Type is application/json
|
|
113
|
+
* this.is('json', 'urlencoded'); // => 'json'
|
|
114
|
+
* this.is('application/json'); // => 'application/json'
|
|
115
|
+
* this.is('html', 'application/*'); // => 'application/json'
|
|
116
|
+
*
|
|
117
|
+
* this.is('html'); // => false
|
|
118
|
+
*
|
|
119
|
+
* @param {Object} req
|
|
120
|
+
* @param {(String|Array)} types...
|
|
121
|
+
* @return {(String|false|null)}
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
function typeofrequest (req, types_) {
|
|
126
|
+
// no body
|
|
127
|
+
if (!hasbody(req)) return null
|
|
128
|
+
// support flattened arguments
|
|
129
|
+
var types = arguments.length > 2
|
|
130
|
+
? Array.prototype.slice.call(arguments, 1)
|
|
131
|
+
: types_
|
|
132
|
+
// request content type
|
|
133
|
+
var value = req.headers['content-type']
|
|
134
|
+
|
|
135
|
+
return typeis(value, types)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Normalize a mime type.
|
|
140
|
+
* If it's a shorthand, expand it to a valid mime type.
|
|
141
|
+
*
|
|
142
|
+
* In general, you probably want:
|
|
143
|
+
*
|
|
144
|
+
* var type = is(req, ['urlencoded', 'json', 'multipart']);
|
|
145
|
+
*
|
|
146
|
+
* Then use the appropriate body parsers.
|
|
147
|
+
* These three are the most common request body types
|
|
148
|
+
* and are thus ensured to work.
|
|
149
|
+
*
|
|
150
|
+
* @param {String} type
|
|
151
|
+
* @return {String|false|null}
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
function normalize (type) {
|
|
156
|
+
if (typeof type !== 'string') {
|
|
157
|
+
// invalid type
|
|
158
|
+
return false
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
switch (type) {
|
|
162
|
+
case 'urlencoded':
|
|
163
|
+
return 'application/x-www-form-urlencoded'
|
|
164
|
+
case 'multipart':
|
|
165
|
+
return 'multipart/*'
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (type[0] === '+') {
|
|
169
|
+
// "+json" -> "*/*+json" expando
|
|
170
|
+
return '*/*' + type
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return type.indexOf('/') === -1
|
|
174
|
+
? mime.lookup(type)
|
|
175
|
+
: type
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Check if `expected` mime type
|
|
180
|
+
* matches `actual` mime type with
|
|
181
|
+
* wildcard and +suffix support.
|
|
182
|
+
*
|
|
183
|
+
* @param {String} expected
|
|
184
|
+
* @param {String} actual
|
|
185
|
+
* @return {Boolean}
|
|
186
|
+
* @public
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
function mimeMatch (expected, actual) {
|
|
190
|
+
// invalid type
|
|
191
|
+
if (expected === false) {
|
|
192
|
+
return false
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// split types
|
|
196
|
+
var actualParts = actual.split('/')
|
|
197
|
+
var expectedParts = expected.split('/')
|
|
198
|
+
|
|
199
|
+
// invalid format
|
|
200
|
+
if (actualParts.length !== 2 || expectedParts.length !== 2) {
|
|
201
|
+
return false
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// validate type
|
|
205
|
+
if (expectedParts[0] !== '*' && expectedParts[0] !== actualParts[0]) {
|
|
206
|
+
return false
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// validate suffix wildcard
|
|
210
|
+
if (expectedParts[1].slice(0, 2) === '*+') {
|
|
211
|
+
return expectedParts[1].length <= actualParts[1].length + 1 &&
|
|
212
|
+
expectedParts[1].slice(1) === actualParts[1].slice(1 - expectedParts[1].length)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// validate subtype
|
|
216
|
+
if (expectedParts[1] !== '*' && expectedParts[1] !== actualParts[1]) {
|
|
217
|
+
return false
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return true
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Normalize a type and remove parameters.
|
|
225
|
+
*
|
|
226
|
+
* @param {string} value
|
|
227
|
+
* @return {(string|null)}
|
|
228
|
+
* @private
|
|
229
|
+
*/
|
|
230
|
+
function normalizeType (value) {
|
|
231
|
+
// Parse the type
|
|
232
|
+
var type = contentType.parse(value).type
|
|
233
|
+
|
|
234
|
+
return typer.test(type) ? type : null
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Try to normalize a type and remove parameters.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} value
|
|
241
|
+
* @return {(string|null)}
|
|
242
|
+
* @private
|
|
243
|
+
*/
|
|
244
|
+
function tryNormalizeType (value) {
|
|
245
|
+
try {
|
|
246
|
+
return value ? normalizeType(value) : null
|
|
247
|
+
} catch (err) {
|
|
248
|
+
return null
|
|
249
|
+
}
|
|
250
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/type-is",
|
|
3
|
+
"description": "Infer the content-type of a request. (with updated dependencies)",
|
|
4
|
+
"version": "2.0.1-depup.0",
|
|
5
|
+
"contributors": [
|
|
6
|
+
"Douglas Christopher Wilson <doug@somethingdoug.com>",
|
|
7
|
+
"Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": "jshttp/type-is",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"content-type": "^1.0.5",
|
|
13
|
+
"media-typer": "^1.1.0",
|
|
14
|
+
"mime-types": "^3.0.2"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"eslint": "7.32.0",
|
|
18
|
+
"eslint-config-standard": "14.1.1",
|
|
19
|
+
"eslint-plugin-import": "2.25.4",
|
|
20
|
+
"eslint-plugin-markdown": "2.2.1",
|
|
21
|
+
"eslint-plugin-node": "11.1.0",
|
|
22
|
+
"eslint-plugin-promise": "5.2.0",
|
|
23
|
+
"eslint-plugin-standard": "4.1.0",
|
|
24
|
+
"mocha": "9.2.1",
|
|
25
|
+
"nyc": "15.1.0"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">= 0.6"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"HISTORY.md",
|
|
33
|
+
"index.js",
|
|
34
|
+
"changes.json",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"lint": "eslint .",
|
|
39
|
+
"test": "mocha --reporter spec --check-leaks --bail test/",
|
|
40
|
+
"test:debug": "mocha --reporter spec --check-leaks --inspect --inspect-brk test/",
|
|
41
|
+
"test-ci": "nyc --reporter=lcovonly --reporter=text npm test",
|
|
42
|
+
"test-cov": "nyc --reporter=html --reporter=text npm test"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"type-is",
|
|
46
|
+
"depup",
|
|
47
|
+
"updated-dependencies",
|
|
48
|
+
"security",
|
|
49
|
+
"latest",
|
|
50
|
+
"patched",
|
|
51
|
+
"content",
|
|
52
|
+
"type",
|
|
53
|
+
"checking"
|
|
54
|
+
],
|
|
55
|
+
"depup": {
|
|
56
|
+
"changes": {
|
|
57
|
+
"mime-types": {
|
|
58
|
+
"from": "^3.0.0",
|
|
59
|
+
"to": "^3.0.2"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"depsUpdated": 1,
|
|
63
|
+
"originalPackage": "type-is",
|
|
64
|
+
"originalVersion": "2.0.1",
|
|
65
|
+
"processedAt": "2026-03-19T03:02:27.156Z",
|
|
66
|
+
"smokeTest": "passed"
|
|
67
|
+
}
|
|
68
|
+
}
|