es6-crawler-detect 3.3.0 → 4.0.0-beta.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/.babelrc +1 -1
- package/.mocharc.json +5 -0
- package/README.md +1 -0
- package/dist/main.bundle.js +1 -1
- package/eslint.config.mjs +62 -0
- package/example/node/package.json +1 -1
- package/example/node/yarn.lock +222 -99
- package/package.json +30 -25
- package/src/index.js +20 -14
- package/src/index.ts +18 -0
- package/src/lib/crawler/crawlers.js +1399 -1403
- package/src/lib/crawler/crawlers.ts +1397 -0
- package/src/lib/crawler/exclusions.js +58 -62
- package/src/lib/crawler/exclusions.ts +56 -0
- package/src/lib/crawler/headers.js +6 -10
- package/src/lib/crawler/headers.ts +18 -0
- package/src/lib/crawler/provider.js +1 -10
- package/src/lib/crawler/provider.ts +3 -0
- package/src/lib/crawler.js +98 -130
- package/src/lib/crawler.ts +128 -0
- package/src/types.js +2 -0
- package/src/types.ts +15 -0
- package/test/lib/crawler.spec.js +149 -0
- package/test/lib/crawler.spec.ts +116 -0
- package/tsconfig.json +16 -0
- package/webpack.common.js +20 -20
- package/webpack.dev.js +7 -7
- package/webpack.prod.js +14 -14
- package/.eslintignore +0 -6
- package/.eslintrc.json +0 -30
- package/example/node/node_modules/.bin/mime +0 -15
- package/example/node/node_modules/.bin/mime.cmd +0 -7
- package/example/node/node_modules/.yarn-integrity +0 -67
- package/example/node/node_modules/accepts/HISTORY.md +0 -236
- package/example/node/node_modules/accepts/LICENSE +0 -23
- package/example/node/node_modules/accepts/README.md +0 -142
- package/example/node/node_modules/accepts/index.js +0 -238
- package/example/node/node_modules/accepts/package.json +0 -47
- package/example/node/node_modules/array-flatten/LICENSE +0 -21
- package/example/node/node_modules/array-flatten/README.md +0 -43
- package/example/node/node_modules/array-flatten/array-flatten.js +0 -64
- package/example/node/node_modules/array-flatten/package.json +0 -39
- package/example/node/node_modules/body-parser/HISTORY.md +0 -624
- package/example/node/node_modules/body-parser/LICENSE +0 -23
- package/example/node/node_modules/body-parser/README.md +0 -456
- package/example/node/node_modules/body-parser/index.js +0 -157
- package/example/node/node_modules/body-parser/lib/read.js +0 -181
- package/example/node/node_modules/body-parser/lib/types/json.js +0 -230
- package/example/node/node_modules/body-parser/lib/types/raw.js +0 -101
- package/example/node/node_modules/body-parser/lib/types/text.js +0 -121
- package/example/node/node_modules/body-parser/lib/types/urlencoded.js +0 -284
- package/example/node/node_modules/body-parser/package.json +0 -52
- package/example/node/node_modules/bytes/History.md +0 -92
- package/example/node/node_modules/bytes/LICENSE +0 -23
- package/example/node/node_modules/bytes/Readme.md +0 -152
- package/example/node/node_modules/bytes/index.js +0 -166
- package/example/node/node_modules/bytes/package.json +0 -42
- package/example/node/node_modules/content-disposition/HISTORY.md +0 -60
- package/example/node/node_modules/content-disposition/LICENSE +0 -22
- package/example/node/node_modules/content-disposition/README.md +0 -142
- package/example/node/node_modules/content-disposition/index.js +0 -458
- package/example/node/node_modules/content-disposition/package.json +0 -44
- package/example/node/node_modules/content-type/HISTORY.md +0 -24
- package/example/node/node_modules/content-type/LICENSE +0 -22
- package/example/node/node_modules/content-type/README.md +0 -92
- package/example/node/node_modules/content-type/index.js +0 -222
- package/example/node/node_modules/content-type/package.json +0 -40
- package/example/node/node_modules/cookie/HISTORY.md +0 -128
- package/example/node/node_modules/cookie/LICENSE +0 -24
- package/example/node/node_modules/cookie/README.md +0 -257
- package/example/node/node_modules/cookie/index.js +0 -202
- package/example/node/node_modules/cookie/package.json +0 -40
- package/example/node/node_modules/cookie-signature/History.md +0 -38
- package/example/node/node_modules/cookie-signature/Readme.md +0 -42
- package/example/node/node_modules/cookie-signature/index.js +0 -51
- package/example/node/node_modules/cookie-signature/package.json +0 -18
- package/example/node/node_modules/debug/.coveralls.yml +0 -1
- package/example/node/node_modules/debug/.eslintrc +0 -11
- package/example/node/node_modules/debug/.travis.yml +0 -14
- package/example/node/node_modules/debug/CHANGELOG.md +0 -362
- package/example/node/node_modules/debug/LICENSE +0 -19
- package/example/node/node_modules/debug/Makefile +0 -50
- package/example/node/node_modules/debug/README.md +0 -312
- package/example/node/node_modules/debug/component.json +0 -19
- package/example/node/node_modules/debug/karma.conf.js +0 -70
- package/example/node/node_modules/debug/node.js +0 -1
- package/example/node/node_modules/debug/package.json +0 -49
- package/example/node/node_modules/debug/src/browser.js +0 -185
- package/example/node/node_modules/debug/src/debug.js +0 -202
- package/example/node/node_modules/debug/src/index.js +0 -10
- package/example/node/node_modules/debug/src/inspector-log.js +0 -15
- package/example/node/node_modules/debug/src/node.js +0 -248
- package/example/node/node_modules/depd/History.md +0 -96
- package/example/node/node_modules/depd/LICENSE +0 -22
- package/example/node/node_modules/depd/Readme.md +0 -280
- package/example/node/node_modules/depd/index.js +0 -522
- package/example/node/node_modules/depd/lib/browser/index.js +0 -77
- package/example/node/node_modules/depd/lib/compat/callsite-tostring.js +0 -103
- package/example/node/node_modules/depd/lib/compat/event-listener-count.js +0 -22
- package/example/node/node_modules/depd/lib/compat/index.js +0 -79
- package/example/node/node_modules/depd/package.json +0 -41
- package/example/node/node_modules/destroy/LICENSE +0 -22
- package/example/node/node_modules/destroy/README.md +0 -60
- package/example/node/node_modules/destroy/index.js +0 -75
- package/example/node/node_modules/destroy/package.json +0 -37
- package/example/node/node_modules/ee-first/LICENSE +0 -22
- package/example/node/node_modules/ee-first/README.md +0 -80
- package/example/node/node_modules/ee-first/index.js +0 -95
- package/example/node/node_modules/ee-first/package.json +0 -29
- package/example/node/node_modules/encodeurl/HISTORY.md +0 -14
- package/example/node/node_modules/encodeurl/LICENSE +0 -22
- package/example/node/node_modules/encodeurl/README.md +0 -128
- package/example/node/node_modules/encodeurl/index.js +0 -60
- package/example/node/node_modules/encodeurl/package.json +0 -40
- package/example/node/node_modules/escape-html/LICENSE +0 -24
- package/example/node/node_modules/escape-html/Readme.md +0 -43
- package/example/node/node_modules/escape-html/index.js +0 -78
- package/example/node/node_modules/escape-html/package.json +0 -24
- package/example/node/node_modules/etag/HISTORY.md +0 -83
- package/example/node/node_modules/etag/LICENSE +0 -22
- package/example/node/node_modules/etag/README.md +0 -159
- package/example/node/node_modules/etag/index.js +0 -131
- package/example/node/node_modules/etag/package.json +0 -47
- package/example/node/node_modules/express/History.md +0 -3510
- package/example/node/node_modules/express/LICENSE +0 -24
- package/example/node/node_modules/express/Readme.md +0 -158
- package/example/node/node_modules/express/index.js +0 -11
- package/example/node/node_modules/express/lib/application.js +0 -644
- package/example/node/node_modules/express/lib/express.js +0 -116
- package/example/node/node_modules/express/lib/middleware/init.js +0 -43
- package/example/node/node_modules/express/lib/middleware/query.js +0 -47
- package/example/node/node_modules/express/lib/request.js +0 -525
- package/example/node/node_modules/express/lib/response.js +0 -1147
- package/example/node/node_modules/express/lib/router/index.js +0 -668
- package/example/node/node_modules/express/lib/router/layer.js +0 -181
- package/example/node/node_modules/express/lib/router/route.js +0 -216
- package/example/node/node_modules/express/lib/utils.js +0 -302
- package/example/node/node_modules/express/lib/view.js +0 -182
- package/example/node/node_modules/express/package.json +0 -99
- package/example/node/node_modules/finalhandler/HISTORY.md +0 -187
- package/example/node/node_modules/finalhandler/LICENSE +0 -22
- package/example/node/node_modules/finalhandler/README.md +0 -148
- package/example/node/node_modules/finalhandler/index.js +0 -331
- package/example/node/node_modules/finalhandler/package.json +0 -45
- package/example/node/node_modules/forwarded/HISTORY.md +0 -21
- package/example/node/node_modules/forwarded/LICENSE +0 -22
- package/example/node/node_modules/forwarded/README.md +0 -57
- package/example/node/node_modules/forwarded/index.js +0 -90
- package/example/node/node_modules/forwarded/package.json +0 -45
- package/example/node/node_modules/fresh/HISTORY.md +0 -70
- package/example/node/node_modules/fresh/LICENSE +0 -23
- package/example/node/node_modules/fresh/README.md +0 -119
- package/example/node/node_modules/fresh/index.js +0 -137
- package/example/node/node_modules/fresh/package.json +0 -46
- package/example/node/node_modules/http-errors/HISTORY.md +0 -165
- package/example/node/node_modules/http-errors/LICENSE +0 -23
- package/example/node/node_modules/http-errors/README.md +0 -169
- package/example/node/node_modules/http-errors/index.js +0 -299
- package/example/node/node_modules/http-errors/package.json +0 -49
- package/example/node/node_modules/iconv-lite/Changelog.md +0 -162
- package/example/node/node_modules/iconv-lite/LICENSE +0 -21
- package/example/node/node_modules/iconv-lite/README.md +0 -156
- package/example/node/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -555
- package/example/node/node_modules/iconv-lite/encodings/dbcs-data.js +0 -176
- package/example/node/node_modules/iconv-lite/encodings/index.js +0 -22
- package/example/node/node_modules/iconv-lite/encodings/internal.js +0 -188
- package/example/node/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -72
- package/example/node/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -451
- package/example/node/node_modules/iconv-lite/encodings/sbcs-data.js +0 -174
- package/example/node/node_modules/iconv-lite/encodings/tables/big5-added.json +0 -122
- package/example/node/node_modules/iconv-lite/encodings/tables/cp936.json +0 -264
- package/example/node/node_modules/iconv-lite/encodings/tables/cp949.json +0 -273
- package/example/node/node_modules/iconv-lite/encodings/tables/cp950.json +0 -177
- package/example/node/node_modules/iconv-lite/encodings/tables/eucjp.json +0 -182
- package/example/node/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +0 -1
- package/example/node/node_modules/iconv-lite/encodings/tables/gbk-added.json +0 -55
- package/example/node/node_modules/iconv-lite/encodings/tables/shiftjis.json +0 -125
- package/example/node/node_modules/iconv-lite/encodings/utf16.js +0 -177
- package/example/node/node_modules/iconv-lite/encodings/utf7.js +0 -290
- package/example/node/node_modules/iconv-lite/lib/bom-handling.js +0 -52
- package/example/node/node_modules/iconv-lite/lib/extend-node.js +0 -217
- package/example/node/node_modules/iconv-lite/lib/index.d.ts +0 -24
- package/example/node/node_modules/iconv-lite/lib/index.js +0 -153
- package/example/node/node_modules/iconv-lite/lib/streams.js +0 -121
- package/example/node/node_modules/iconv-lite/package.json +0 -46
- package/example/node/node_modules/inherits/LICENSE +0 -16
- package/example/node/node_modules/inherits/README.md +0 -42
- package/example/node/node_modules/inherits/inherits.js +0 -9
- package/example/node/node_modules/inherits/inherits_browser.js +0 -27
- package/example/node/node_modules/inherits/package.json +0 -29
- package/example/node/node_modules/ipaddr.js/LICENSE +0 -19
- package/example/node/node_modules/ipaddr.js/README.md +0 -233
- package/example/node/node_modules/ipaddr.js/ipaddr.min.js +0 -1
- package/example/node/node_modules/ipaddr.js/lib/ipaddr.js +0 -673
- package/example/node/node_modules/ipaddr.js/lib/ipaddr.js.d.ts +0 -68
- package/example/node/node_modules/ipaddr.js/package.json +0 -35
- package/example/node/node_modules/media-typer/HISTORY.md +0 -22
- package/example/node/node_modules/media-typer/LICENSE +0 -22
- package/example/node/node_modules/media-typer/README.md +0 -81
- package/example/node/node_modules/media-typer/index.js +0 -270
- package/example/node/node_modules/media-typer/package.json +0 -26
- package/example/node/node_modules/merge-descriptors/HISTORY.md +0 -21
- package/example/node/node_modules/merge-descriptors/LICENSE +0 -23
- package/example/node/node_modules/merge-descriptors/README.md +0 -48
- package/example/node/node_modules/merge-descriptors/index.js +0 -60
- package/example/node/node_modules/merge-descriptors/package.json +0 -32
- package/example/node/node_modules/methods/HISTORY.md +0 -29
- package/example/node/node_modules/methods/LICENSE +0 -24
- package/example/node/node_modules/methods/README.md +0 -51
- package/example/node/node_modules/methods/index.js +0 -69
- package/example/node/node_modules/methods/package.json +0 -36
- package/example/node/node_modules/mime/CHANGELOG.md +0 -164
- package/example/node/node_modules/mime/LICENSE +0 -21
- package/example/node/node_modules/mime/README.md +0 -90
- package/example/node/node_modules/mime/cli.js +0 -8
- package/example/node/node_modules/mime/mime.js +0 -108
- package/example/node/node_modules/mime/package.json +0 -44
- package/example/node/node_modules/mime/src/build.js +0 -53
- package/example/node/node_modules/mime/src/test.js +0 -60
- package/example/node/node_modules/mime/types.json +0 -1
- package/example/node/node_modules/mime-db/HISTORY.md +0 -499
- package/example/node/node_modules/mime-db/LICENSE +0 -22
- package/example/node/node_modules/mime-db/README.md +0 -100
- package/example/node/node_modules/mime-db/db.json +0 -8471
- package/example/node/node_modules/mime-db/index.js +0 -11
- package/example/node/node_modules/mime-db/package.json +0 -59
- package/example/node/node_modules/mime-types/HISTORY.md +0 -388
- package/example/node/node_modules/mime-types/LICENSE +0 -23
- package/example/node/node_modules/mime-types/README.md +0 -113
- package/example/node/node_modules/mime-types/index.js +0 -188
- package/example/node/node_modules/mime-types/package.json +0 -44
- package/example/node/node_modules/ms/index.js +0 -152
- package/example/node/node_modules/ms/license.md +0 -21
- package/example/node/node_modules/ms/package.json +0 -37
- package/example/node/node_modules/ms/readme.md +0 -51
- package/example/node/node_modules/negotiator/HISTORY.md +0 -103
- package/example/node/node_modules/negotiator/LICENSE +0 -24
- package/example/node/node_modules/negotiator/README.md +0 -203
- package/example/node/node_modules/negotiator/index.js +0 -124
- package/example/node/node_modules/negotiator/lib/charset.js +0 -169
- package/example/node/node_modules/negotiator/lib/encoding.js +0 -184
- package/example/node/node_modules/negotiator/lib/language.js +0 -179
- package/example/node/node_modules/negotiator/lib/mediaType.js +0 -294
- package/example/node/node_modules/negotiator/package.json +0 -42
- package/example/node/node_modules/on-finished/HISTORY.md +0 -88
- package/example/node/node_modules/on-finished/LICENSE +0 -23
- package/example/node/node_modules/on-finished/README.md +0 -154
- package/example/node/node_modules/on-finished/index.js +0 -196
- package/example/node/node_modules/on-finished/package.json +0 -31
- package/example/node/node_modules/parseurl/HISTORY.md +0 -58
- package/example/node/node_modules/parseurl/LICENSE +0 -24
- package/example/node/node_modules/parseurl/README.md +0 -133
- package/example/node/node_modules/parseurl/index.js +0 -158
- package/example/node/node_modules/parseurl/package.json +0 -40
- package/example/node/node_modules/path-to-regexp/History.md +0 -36
- package/example/node/node_modules/path-to-regexp/LICENSE +0 -21
- package/example/node/node_modules/path-to-regexp/Readme.md +0 -35
- package/example/node/node_modules/path-to-regexp/index.js +0 -129
- package/example/node/node_modules/path-to-regexp/package.json +0 -30
- package/example/node/node_modules/proxy-addr/HISTORY.md +0 -161
- package/example/node/node_modules/proxy-addr/LICENSE +0 -22
- package/example/node/node_modules/proxy-addr/README.md +0 -139
- package/example/node/node_modules/proxy-addr/index.js +0 -327
- package/example/node/node_modules/proxy-addr/package.json +0 -47
- package/example/node/node_modules/qs/.editorconfig +0 -39
- package/example/node/node_modules/qs/.eslintignore +0 -2
- package/example/node/node_modules/qs/.eslintrc +0 -35
- package/example/node/node_modules/qs/.github/FUNDING.yml +0 -12
- package/example/node/node_modules/qs/.nycrc +0 -13
- package/example/node/node_modules/qs/CHANGELOG.md +0 -359
- package/example/node/node_modules/qs/LICENSE.md +0 -29
- package/example/node/node_modules/qs/README.md +0 -604
- package/example/node/node_modules/qs/dist/qs.js +0 -832
- package/example/node/node_modules/qs/lib/formats.js +0 -23
- package/example/node/node_modules/qs/lib/index.js +0 -11
- package/example/node/node_modules/qs/lib/parse.js +0 -257
- package/example/node/node_modules/qs/lib/stringify.js +0 -278
- package/example/node/node_modules/qs/lib/utils.js +0 -251
- package/example/node/node_modules/qs/package.json +0 -69
- package/example/node/node_modules/qs/test/parse.js +0 -772
- package/example/node/node_modules/qs/test/stringify.js +0 -793
- package/example/node/node_modules/qs/test/utils.js +0 -136
- package/example/node/node_modules/range-parser/HISTORY.md +0 -56
- package/example/node/node_modules/range-parser/LICENSE +0 -23
- package/example/node/node_modules/range-parser/README.md +0 -84
- package/example/node/node_modules/range-parser/index.js +0 -162
- package/example/node/node_modules/range-parser/package.json +0 -44
- package/example/node/node_modules/raw-body/HISTORY.md +0 -284
- package/example/node/node_modules/raw-body/LICENSE +0 -22
- package/example/node/node_modules/raw-body/README.md +0 -217
- package/example/node/node_modules/raw-body/index.d.ts +0 -87
- package/example/node/node_modules/raw-body/index.js +0 -286
- package/example/node/node_modules/raw-body/package.json +0 -48
- package/example/node/node_modules/safe-buffer/LICENSE +0 -21
- package/example/node/node_modules/safe-buffer/README.md +0 -584
- package/example/node/node_modules/safe-buffer/index.d.ts +0 -187
- package/example/node/node_modules/safe-buffer/index.js +0 -65
- package/example/node/node_modules/safe-buffer/package.json +0 -51
- package/example/node/node_modules/safer-buffer/LICENSE +0 -21
- package/example/node/node_modules/safer-buffer/Porting-Buffer.md +0 -268
- package/example/node/node_modules/safer-buffer/Readme.md +0 -156
- package/example/node/node_modules/safer-buffer/dangerous.js +0 -58
- package/example/node/node_modules/safer-buffer/package.json +0 -34
- package/example/node/node_modules/safer-buffer/safer.js +0 -77
- package/example/node/node_modules/safer-buffer/tests.js +0 -406
- package/example/node/node_modules/send/HISTORY.md +0 -506
- package/example/node/node_modules/send/LICENSE +0 -23
- package/example/node/node_modules/send/README.md +0 -327
- package/example/node/node_modules/send/index.js +0 -1133
- package/example/node/node_modules/send/node_modules/.bin/mime +0 -15
- package/example/node/node_modules/send/node_modules/.bin/mime.cmd +0 -7
- package/example/node/node_modules/send/node_modules/ms/index.js +0 -162
- package/example/node/node_modules/send/node_modules/ms/license.md +0 -21
- package/example/node/node_modules/send/node_modules/ms/package.json +0 -38
- package/example/node/node_modules/send/node_modules/ms/readme.md +0 -59
- package/example/node/node_modules/send/package.json +0 -61
- package/example/node/node_modules/serve-static/HISTORY.md +0 -459
- package/example/node/node_modules/serve-static/LICENSE +0 -25
- package/example/node/node_modules/serve-static/README.md +0 -257
- package/example/node/node_modules/serve-static/index.js +0 -210
- package/example/node/node_modules/serve-static/package.json +0 -42
- package/example/node/node_modules/setprototypeof/LICENSE +0 -13
- package/example/node/node_modules/setprototypeof/README.md +0 -31
- package/example/node/node_modules/setprototypeof/index.d.ts +0 -2
- package/example/node/node_modules/setprototypeof/index.js +0 -17
- package/example/node/node_modules/setprototypeof/package.json +0 -38
- package/example/node/node_modules/setprototypeof/test/index.js +0 -24
- package/example/node/node_modules/statuses/HISTORY.md +0 -65
- package/example/node/node_modules/statuses/LICENSE +0 -23
- package/example/node/node_modules/statuses/README.md +0 -127
- package/example/node/node_modules/statuses/codes.json +0 -66
- package/example/node/node_modules/statuses/index.js +0 -113
- package/example/node/node_modules/statuses/package.json +0 -48
- package/example/node/node_modules/toidentifier/HISTORY.md +0 -9
- package/example/node/node_modules/toidentifier/LICENSE +0 -21
- package/example/node/node_modules/toidentifier/README.md +0 -61
- package/example/node/node_modules/toidentifier/index.js +0 -32
- package/example/node/node_modules/toidentifier/package.json +0 -38
- package/example/node/node_modules/type-is/HISTORY.md +0 -259
- package/example/node/node_modules/type-is/LICENSE +0 -23
- package/example/node/node_modules/type-is/README.md +0 -170
- package/example/node/node_modules/type-is/index.js +0 -266
- package/example/node/node_modules/type-is/package.json +0 -45
- package/example/node/node_modules/unpipe/HISTORY.md +0 -4
- package/example/node/node_modules/unpipe/LICENSE +0 -22
- package/example/node/node_modules/unpipe/README.md +0 -43
- package/example/node/node_modules/unpipe/index.js +0 -69
- package/example/node/node_modules/unpipe/package.json +0 -27
- package/example/node/node_modules/utils-merge/LICENSE +0 -20
- package/example/node/node_modules/utils-merge/README.md +0 -34
- package/example/node/node_modules/utils-merge/index.js +0 -23
- package/example/node/node_modules/utils-merge/package.json +0 -40
- package/example/node/node_modules/vary/HISTORY.md +0 -39
- package/example/node/node_modules/vary/LICENSE +0 -22
- package/example/node/node_modules/vary/README.md +0 -101
- package/example/node/node_modules/vary/index.js +0 -149
- package/example/node/node_modules/vary/package.json +0 -43
- package/test/lib/crawler.test.js +0 -94
@@ -1,458 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
* content-disposition
|
3
|
-
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
4
|
-
* MIT Licensed
|
5
|
-
*/
|
6
|
-
|
7
|
-
'use strict'
|
8
|
-
|
9
|
-
/**
|
10
|
-
* Module exports.
|
11
|
-
* @public
|
12
|
-
*/
|
13
|
-
|
14
|
-
module.exports = contentDisposition
|
15
|
-
module.exports.parse = parse
|
16
|
-
|
17
|
-
/**
|
18
|
-
* Module dependencies.
|
19
|
-
* @private
|
20
|
-
*/
|
21
|
-
|
22
|
-
var basename = require('path').basename
|
23
|
-
var Buffer = require('safe-buffer').Buffer
|
24
|
-
|
25
|
-
/**
|
26
|
-
* RegExp to match non attr-char, *after* encodeURIComponent (i.e. not including "%")
|
27
|
-
* @private
|
28
|
-
*/
|
29
|
-
|
30
|
-
var ENCODE_URL_ATTR_CHAR_REGEXP = /[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g // eslint-disable-line no-control-regex
|
31
|
-
|
32
|
-
/**
|
33
|
-
* RegExp to match percent encoding escape.
|
34
|
-
* @private
|
35
|
-
*/
|
36
|
-
|
37
|
-
var HEX_ESCAPE_REGEXP = /%[0-9A-Fa-f]{2}/
|
38
|
-
var HEX_ESCAPE_REPLACE_REGEXP = /%([0-9A-Fa-f]{2})/g
|
39
|
-
|
40
|
-
/**
|
41
|
-
* RegExp to match non-latin1 characters.
|
42
|
-
* @private
|
43
|
-
*/
|
44
|
-
|
45
|
-
var NON_LATIN1_REGEXP = /[^\x20-\x7e\xa0-\xff]/g
|
46
|
-
|
47
|
-
/**
|
48
|
-
* RegExp to match quoted-pair in RFC 2616
|
49
|
-
*
|
50
|
-
* quoted-pair = "\" CHAR
|
51
|
-
* CHAR = <any US-ASCII character (octets 0 - 127)>
|
52
|
-
* @private
|
53
|
-
*/
|
54
|
-
|
55
|
-
var QESC_REGEXP = /\\([\u0000-\u007f])/g // eslint-disable-line no-control-regex
|
56
|
-
|
57
|
-
/**
|
58
|
-
* RegExp to match chars that must be quoted-pair in RFC 2616
|
59
|
-
* @private
|
60
|
-
*/
|
61
|
-
|
62
|
-
var QUOTE_REGEXP = /([\\"])/g
|
63
|
-
|
64
|
-
/**
|
65
|
-
* RegExp for various RFC 2616 grammar
|
66
|
-
*
|
67
|
-
* parameter = token "=" ( token | quoted-string )
|
68
|
-
* token = 1*<any CHAR except CTLs or separators>
|
69
|
-
* separators = "(" | ")" | "<" | ">" | "@"
|
70
|
-
* | "," | ";" | ":" | "\" | <">
|
71
|
-
* | "/" | "[" | "]" | "?" | "="
|
72
|
-
* | "{" | "}" | SP | HT
|
73
|
-
* quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
|
74
|
-
* qdtext = <any TEXT except <">>
|
75
|
-
* quoted-pair = "\" CHAR
|
76
|
-
* CHAR = <any US-ASCII character (octets 0 - 127)>
|
77
|
-
* TEXT = <any OCTET except CTLs, but including LWS>
|
78
|
-
* LWS = [CRLF] 1*( SP | HT )
|
79
|
-
* CRLF = CR LF
|
80
|
-
* CR = <US-ASCII CR, carriage return (13)>
|
81
|
-
* LF = <US-ASCII LF, linefeed (10)>
|
82
|
-
* SP = <US-ASCII SP, space (32)>
|
83
|
-
* HT = <US-ASCII HT, horizontal-tab (9)>
|
84
|
-
* CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
|
85
|
-
* OCTET = <any 8-bit sequence of data>
|
86
|
-
* @private
|
87
|
-
*/
|
88
|
-
|
89
|
-
var PARAM_REGEXP = /;[\x09\x20]*([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*=[\x09\x20]*("(?:[\x20!\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*/g // eslint-disable-line no-control-regex
|
90
|
-
var TEXT_REGEXP = /^[\x20-\x7e\x80-\xff]+$/
|
91
|
-
var TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/
|
92
|
-
|
93
|
-
/**
|
94
|
-
* RegExp for various RFC 5987 grammar
|
95
|
-
*
|
96
|
-
* ext-value = charset "'" [ language ] "'" value-chars
|
97
|
-
* charset = "UTF-8" / "ISO-8859-1" / mime-charset
|
98
|
-
* mime-charset = 1*mime-charsetc
|
99
|
-
* mime-charsetc = ALPHA / DIGIT
|
100
|
-
* / "!" / "#" / "$" / "%" / "&"
|
101
|
-
* / "+" / "-" / "^" / "_" / "`"
|
102
|
-
* / "{" / "}" / "~"
|
103
|
-
* language = ( 2*3ALPHA [ extlang ] )
|
104
|
-
* / 4ALPHA
|
105
|
-
* / 5*8ALPHA
|
106
|
-
* extlang = *3( "-" 3ALPHA )
|
107
|
-
* value-chars = *( pct-encoded / attr-char )
|
108
|
-
* pct-encoded = "%" HEXDIG HEXDIG
|
109
|
-
* attr-char = ALPHA / DIGIT
|
110
|
-
* / "!" / "#" / "$" / "&" / "+" / "-" / "."
|
111
|
-
* / "^" / "_" / "`" / "|" / "~"
|
112
|
-
* @private
|
113
|
-
*/
|
114
|
-
|
115
|
-
var EXT_VALUE_REGEXP = /^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/
|
116
|
-
|
117
|
-
/**
|
118
|
-
* RegExp for various RFC 6266 grammar
|
119
|
-
*
|
120
|
-
* disposition-type = "inline" | "attachment" | disp-ext-type
|
121
|
-
* disp-ext-type = token
|
122
|
-
* disposition-parm = filename-parm | disp-ext-parm
|
123
|
-
* filename-parm = "filename" "=" value
|
124
|
-
* | "filename*" "=" ext-value
|
125
|
-
* disp-ext-parm = token "=" value
|
126
|
-
* | ext-token "=" ext-value
|
127
|
-
* ext-token = <the characters in token, followed by "*">
|
128
|
-
* @private
|
129
|
-
*/
|
130
|
-
|
131
|
-
var DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/ // eslint-disable-line no-control-regex
|
132
|
-
|
133
|
-
/**
|
134
|
-
* Create an attachment Content-Disposition header.
|
135
|
-
*
|
136
|
-
* @param {string} [filename]
|
137
|
-
* @param {object} [options]
|
138
|
-
* @param {string} [options.type=attachment]
|
139
|
-
* @param {string|boolean} [options.fallback=true]
|
140
|
-
* @return {string}
|
141
|
-
* @public
|
142
|
-
*/
|
143
|
-
|
144
|
-
function contentDisposition (filename, options) {
|
145
|
-
var opts = options || {}
|
146
|
-
|
147
|
-
// get type
|
148
|
-
var type = opts.type || 'attachment'
|
149
|
-
|
150
|
-
// get parameters
|
151
|
-
var params = createparams(filename, opts.fallback)
|
152
|
-
|
153
|
-
// format into string
|
154
|
-
return format(new ContentDisposition(type, params))
|
155
|
-
}
|
156
|
-
|
157
|
-
/**
|
158
|
-
* Create parameters object from filename and fallback.
|
159
|
-
*
|
160
|
-
* @param {string} [filename]
|
161
|
-
* @param {string|boolean} [fallback=true]
|
162
|
-
* @return {object}
|
163
|
-
* @private
|
164
|
-
*/
|
165
|
-
|
166
|
-
function createparams (filename, fallback) {
|
167
|
-
if (filename === undefined) {
|
168
|
-
return
|
169
|
-
}
|
170
|
-
|
171
|
-
var params = {}
|
172
|
-
|
173
|
-
if (typeof filename !== 'string') {
|
174
|
-
throw new TypeError('filename must be a string')
|
175
|
-
}
|
176
|
-
|
177
|
-
// fallback defaults to true
|
178
|
-
if (fallback === undefined) {
|
179
|
-
fallback = true
|
180
|
-
}
|
181
|
-
|
182
|
-
if (typeof fallback !== 'string' && typeof fallback !== 'boolean') {
|
183
|
-
throw new TypeError('fallback must be a string or boolean')
|
184
|
-
}
|
185
|
-
|
186
|
-
if (typeof fallback === 'string' && NON_LATIN1_REGEXP.test(fallback)) {
|
187
|
-
throw new TypeError('fallback must be ISO-8859-1 string')
|
188
|
-
}
|
189
|
-
|
190
|
-
// restrict to file base name
|
191
|
-
var name = basename(filename)
|
192
|
-
|
193
|
-
// determine if name is suitable for quoted string
|
194
|
-
var isQuotedString = TEXT_REGEXP.test(name)
|
195
|
-
|
196
|
-
// generate fallback name
|
197
|
-
var fallbackName = typeof fallback !== 'string'
|
198
|
-
? fallback && getlatin1(name)
|
199
|
-
: basename(fallback)
|
200
|
-
var hasFallback = typeof fallbackName === 'string' && fallbackName !== name
|
201
|
-
|
202
|
-
// set extended filename parameter
|
203
|
-
if (hasFallback || !isQuotedString || HEX_ESCAPE_REGEXP.test(name)) {
|
204
|
-
params['filename*'] = name
|
205
|
-
}
|
206
|
-
|
207
|
-
// set filename parameter
|
208
|
-
if (isQuotedString || hasFallback) {
|
209
|
-
params.filename = hasFallback
|
210
|
-
? fallbackName
|
211
|
-
: name
|
212
|
-
}
|
213
|
-
|
214
|
-
return params
|
215
|
-
}
|
216
|
-
|
217
|
-
/**
|
218
|
-
* Format object to Content-Disposition header.
|
219
|
-
*
|
220
|
-
* @param {object} obj
|
221
|
-
* @param {string} obj.type
|
222
|
-
* @param {object} [obj.parameters]
|
223
|
-
* @return {string}
|
224
|
-
* @private
|
225
|
-
*/
|
226
|
-
|
227
|
-
function format (obj) {
|
228
|
-
var parameters = obj.parameters
|
229
|
-
var type = obj.type
|
230
|
-
|
231
|
-
if (!type || typeof type !== 'string' || !TOKEN_REGEXP.test(type)) {
|
232
|
-
throw new TypeError('invalid type')
|
233
|
-
}
|
234
|
-
|
235
|
-
// start with normalized type
|
236
|
-
var string = String(type).toLowerCase()
|
237
|
-
|
238
|
-
// append parameters
|
239
|
-
if (parameters && typeof parameters === 'object') {
|
240
|
-
var param
|
241
|
-
var params = Object.keys(parameters).sort()
|
242
|
-
|
243
|
-
for (var i = 0; i < params.length; i++) {
|
244
|
-
param = params[i]
|
245
|
-
|
246
|
-
var val = param.substr(-1) === '*'
|
247
|
-
? ustring(parameters[param])
|
248
|
-
: qstring(parameters[param])
|
249
|
-
|
250
|
-
string += '; ' + param + '=' + val
|
251
|
-
}
|
252
|
-
}
|
253
|
-
|
254
|
-
return string
|
255
|
-
}
|
256
|
-
|
257
|
-
/**
|
258
|
-
* Decode a RFC 5987 field value (gracefully).
|
259
|
-
*
|
260
|
-
* @param {string} str
|
261
|
-
* @return {string}
|
262
|
-
* @private
|
263
|
-
*/
|
264
|
-
|
265
|
-
function decodefield (str) {
|
266
|
-
var match = EXT_VALUE_REGEXP.exec(str)
|
267
|
-
|
268
|
-
if (!match) {
|
269
|
-
throw new TypeError('invalid extended field value')
|
270
|
-
}
|
271
|
-
|
272
|
-
var charset = match[1].toLowerCase()
|
273
|
-
var encoded = match[2]
|
274
|
-
var value
|
275
|
-
|
276
|
-
// to binary string
|
277
|
-
var binary = encoded.replace(HEX_ESCAPE_REPLACE_REGEXP, pdecode)
|
278
|
-
|
279
|
-
switch (charset) {
|
280
|
-
case 'iso-8859-1':
|
281
|
-
value = getlatin1(binary)
|
282
|
-
break
|
283
|
-
case 'utf-8':
|
284
|
-
value = Buffer.from(binary, 'binary').toString('utf8')
|
285
|
-
break
|
286
|
-
default:
|
287
|
-
throw new TypeError('unsupported charset in extended field')
|
288
|
-
}
|
289
|
-
|
290
|
-
return value
|
291
|
-
}
|
292
|
-
|
293
|
-
/**
|
294
|
-
* Get ISO-8859-1 version of string.
|
295
|
-
*
|
296
|
-
* @param {string} val
|
297
|
-
* @return {string}
|
298
|
-
* @private
|
299
|
-
*/
|
300
|
-
|
301
|
-
function getlatin1 (val) {
|
302
|
-
// simple Unicode -> ISO-8859-1 transformation
|
303
|
-
return String(val).replace(NON_LATIN1_REGEXP, '?')
|
304
|
-
}
|
305
|
-
|
306
|
-
/**
|
307
|
-
* Parse Content-Disposition header string.
|
308
|
-
*
|
309
|
-
* @param {string} string
|
310
|
-
* @return {object}
|
311
|
-
* @public
|
312
|
-
*/
|
313
|
-
|
314
|
-
function parse (string) {
|
315
|
-
if (!string || typeof string !== 'string') {
|
316
|
-
throw new TypeError('argument string is required')
|
317
|
-
}
|
318
|
-
|
319
|
-
var match = DISPOSITION_TYPE_REGEXP.exec(string)
|
320
|
-
|
321
|
-
if (!match) {
|
322
|
-
throw new TypeError('invalid type format')
|
323
|
-
}
|
324
|
-
|
325
|
-
// normalize type
|
326
|
-
var index = match[0].length
|
327
|
-
var type = match[1].toLowerCase()
|
328
|
-
|
329
|
-
var key
|
330
|
-
var names = []
|
331
|
-
var params = {}
|
332
|
-
var value
|
333
|
-
|
334
|
-
// calculate index to start at
|
335
|
-
index = PARAM_REGEXP.lastIndex = match[0].substr(-1) === ';'
|
336
|
-
? index - 1
|
337
|
-
: index
|
338
|
-
|
339
|
-
// match parameters
|
340
|
-
while ((match = PARAM_REGEXP.exec(string))) {
|
341
|
-
if (match.index !== index) {
|
342
|
-
throw new TypeError('invalid parameter format')
|
343
|
-
}
|
344
|
-
|
345
|
-
index += match[0].length
|
346
|
-
key = match[1].toLowerCase()
|
347
|
-
value = match[2]
|
348
|
-
|
349
|
-
if (names.indexOf(key) !== -1) {
|
350
|
-
throw new TypeError('invalid duplicate parameter')
|
351
|
-
}
|
352
|
-
|
353
|
-
names.push(key)
|
354
|
-
|
355
|
-
if (key.indexOf('*') + 1 === key.length) {
|
356
|
-
// decode extended value
|
357
|
-
key = key.slice(0, -1)
|
358
|
-
value = decodefield(value)
|
359
|
-
|
360
|
-
// overwrite existing value
|
361
|
-
params[key] = value
|
362
|
-
continue
|
363
|
-
}
|
364
|
-
|
365
|
-
if (typeof params[key] === 'string') {
|
366
|
-
continue
|
367
|
-
}
|
368
|
-
|
369
|
-
if (value[0] === '"') {
|
370
|
-
// remove quotes and escapes
|
371
|
-
value = value
|
372
|
-
.substr(1, value.length - 2)
|
373
|
-
.replace(QESC_REGEXP, '$1')
|
374
|
-
}
|
375
|
-
|
376
|
-
params[key] = value
|
377
|
-
}
|
378
|
-
|
379
|
-
if (index !== -1 && index !== string.length) {
|
380
|
-
throw new TypeError('invalid parameter format')
|
381
|
-
}
|
382
|
-
|
383
|
-
return new ContentDisposition(type, params)
|
384
|
-
}
|
385
|
-
|
386
|
-
/**
|
387
|
-
* Percent decode a single character.
|
388
|
-
*
|
389
|
-
* @param {string} str
|
390
|
-
* @param {string} hex
|
391
|
-
* @return {string}
|
392
|
-
* @private
|
393
|
-
*/
|
394
|
-
|
395
|
-
function pdecode (str, hex) {
|
396
|
-
return String.fromCharCode(parseInt(hex, 16))
|
397
|
-
}
|
398
|
-
|
399
|
-
/**
|
400
|
-
* Percent encode a single character.
|
401
|
-
*
|
402
|
-
* @param {string} char
|
403
|
-
* @return {string}
|
404
|
-
* @private
|
405
|
-
*/
|
406
|
-
|
407
|
-
function pencode (char) {
|
408
|
-
return '%' + String(char)
|
409
|
-
.charCodeAt(0)
|
410
|
-
.toString(16)
|
411
|
-
.toUpperCase()
|
412
|
-
}
|
413
|
-
|
414
|
-
/**
|
415
|
-
* Quote a string for HTTP.
|
416
|
-
*
|
417
|
-
* @param {string} val
|
418
|
-
* @return {string}
|
419
|
-
* @private
|
420
|
-
*/
|
421
|
-
|
422
|
-
function qstring (val) {
|
423
|
-
var str = String(val)
|
424
|
-
|
425
|
-
return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"'
|
426
|
-
}
|
427
|
-
|
428
|
-
/**
|
429
|
-
* Encode a Unicode string for HTTP (RFC 5987).
|
430
|
-
*
|
431
|
-
* @param {string} val
|
432
|
-
* @return {string}
|
433
|
-
* @private
|
434
|
-
*/
|
435
|
-
|
436
|
-
function ustring (val) {
|
437
|
-
var str = String(val)
|
438
|
-
|
439
|
-
// percent encode as UTF-8
|
440
|
-
var encoded = encodeURIComponent(str)
|
441
|
-
.replace(ENCODE_URL_ATTR_CHAR_REGEXP, pencode)
|
442
|
-
|
443
|
-
return 'UTF-8\'\'' + encoded
|
444
|
-
}
|
445
|
-
|
446
|
-
/**
|
447
|
-
* Class for parsed Content-Disposition header for v8 optimization
|
448
|
-
*
|
449
|
-
* @public
|
450
|
-
* @param {string} type
|
451
|
-
* @param {object} parameters
|
452
|
-
* @constructor
|
453
|
-
*/
|
454
|
-
|
455
|
-
function ContentDisposition (type, parameters) {
|
456
|
-
this.type = type
|
457
|
-
this.parameters = parameters
|
458
|
-
}
|
@@ -1,44 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "content-disposition",
|
3
|
-
"description": "Create and parse Content-Disposition header",
|
4
|
-
"version": "0.5.4",
|
5
|
-
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
|
6
|
-
"license": "MIT",
|
7
|
-
"keywords": [
|
8
|
-
"content-disposition",
|
9
|
-
"http",
|
10
|
-
"rfc6266",
|
11
|
-
"res"
|
12
|
-
],
|
13
|
-
"repository": "jshttp/content-disposition",
|
14
|
-
"dependencies": {
|
15
|
-
"safe-buffer": "5.2.1"
|
16
|
-
},
|
17
|
-
"devDependencies": {
|
18
|
-
"deep-equal": "1.0.1",
|
19
|
-
"eslint": "7.32.0",
|
20
|
-
"eslint-config-standard": "13.0.1",
|
21
|
-
"eslint-plugin-import": "2.25.3",
|
22
|
-
"eslint-plugin-markdown": "2.2.1",
|
23
|
-
"eslint-plugin-node": "11.1.0",
|
24
|
-
"eslint-plugin-promise": "5.2.0",
|
25
|
-
"eslint-plugin-standard": "4.1.0",
|
26
|
-
"istanbul": "0.4.5",
|
27
|
-
"mocha": "9.1.3"
|
28
|
-
},
|
29
|
-
"files": [
|
30
|
-
"LICENSE",
|
31
|
-
"HISTORY.md",
|
32
|
-
"README.md",
|
33
|
-
"index.js"
|
34
|
-
],
|
35
|
-
"engines": {
|
36
|
-
"node": ">= 0.6"
|
37
|
-
},
|
38
|
-
"scripts": {
|
39
|
-
"lint": "eslint .",
|
40
|
-
"test": "mocha --reporter spec --bail --check-leaks test/",
|
41
|
-
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
|
42
|
-
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/"
|
43
|
-
}
|
44
|
-
}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
1.0.4 / 2017-09-11
|
2
|
-
==================
|
3
|
-
|
4
|
-
* perf: skip parameter parsing when no parameters
|
5
|
-
|
6
|
-
1.0.3 / 2017-09-10
|
7
|
-
==================
|
8
|
-
|
9
|
-
* perf: remove argument reassignment
|
10
|
-
|
11
|
-
1.0.2 / 2016-05-09
|
12
|
-
==================
|
13
|
-
|
14
|
-
* perf: enable strict mode
|
15
|
-
|
16
|
-
1.0.1 / 2015-02-13
|
17
|
-
==================
|
18
|
-
|
19
|
-
* Improve missing `Content-Type` header error message
|
20
|
-
|
21
|
-
1.0.0 / 2015-02-01
|
22
|
-
==================
|
23
|
-
|
24
|
-
* Initial implementation, derived from `media-typer@0.3.0`
|
@@ -1,22 +0,0 @@
|
|
1
|
-
(The MIT License)
|
2
|
-
|
3
|
-
Copyright (c) 2015 Douglas Christopher Wilson
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
'Software'), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,92 +0,0 @@
|
|
1
|
-
# content-type
|
2
|
-
|
3
|
-
[![NPM Version][npm-image]][npm-url]
|
4
|
-
[![NPM Downloads][downloads-image]][downloads-url]
|
5
|
-
[![Node.js Version][node-version-image]][node-version-url]
|
6
|
-
[![Build Status][travis-image]][travis-url]
|
7
|
-
[![Test Coverage][coveralls-image]][coveralls-url]
|
8
|
-
|
9
|
-
Create and parse HTTP Content-Type header according to RFC 7231
|
10
|
-
|
11
|
-
## Installation
|
12
|
-
|
13
|
-
```sh
|
14
|
-
$ npm install content-type
|
15
|
-
```
|
16
|
-
|
17
|
-
## API
|
18
|
-
|
19
|
-
```js
|
20
|
-
var contentType = require('content-type')
|
21
|
-
```
|
22
|
-
|
23
|
-
### contentType.parse(string)
|
24
|
-
|
25
|
-
```js
|
26
|
-
var obj = contentType.parse('image/svg+xml; charset=utf-8')
|
27
|
-
```
|
28
|
-
|
29
|
-
Parse a content type string. This will return an object with the following
|
30
|
-
properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`):
|
31
|
-
|
32
|
-
- `type`: The media type (the type and subtype, always lower case).
|
33
|
-
Example: `'image/svg+xml'`
|
34
|
-
|
35
|
-
- `parameters`: An object of the parameters in the media type (name of parameter
|
36
|
-
always lower case). Example: `{charset: 'utf-8'}`
|
37
|
-
|
38
|
-
Throws a `TypeError` if the string is missing or invalid.
|
39
|
-
|
40
|
-
### contentType.parse(req)
|
41
|
-
|
42
|
-
```js
|
43
|
-
var obj = contentType.parse(req)
|
44
|
-
```
|
45
|
-
|
46
|
-
Parse the `content-type` header from the given `req`. Short-cut for
|
47
|
-
`contentType.parse(req.headers['content-type'])`.
|
48
|
-
|
49
|
-
Throws a `TypeError` if the `Content-Type` header is missing or invalid.
|
50
|
-
|
51
|
-
### contentType.parse(res)
|
52
|
-
|
53
|
-
```js
|
54
|
-
var obj = contentType.parse(res)
|
55
|
-
```
|
56
|
-
|
57
|
-
Parse the `content-type` header set on the given `res`. Short-cut for
|
58
|
-
`contentType.parse(res.getHeader('content-type'))`.
|
59
|
-
|
60
|
-
Throws a `TypeError` if the `Content-Type` header is missing or invalid.
|
61
|
-
|
62
|
-
### contentType.format(obj)
|
63
|
-
|
64
|
-
```js
|
65
|
-
var str = contentType.format({type: 'image/svg+xml'})
|
66
|
-
```
|
67
|
-
|
68
|
-
Format an object into a content type string. This will return a string of the
|
69
|
-
content type for the given object with the following properties (examples are
|
70
|
-
shown that produce the string `'image/svg+xml; charset=utf-8'`):
|
71
|
-
|
72
|
-
- `type`: The media type (will be lower-cased). Example: `'image/svg+xml'`
|
73
|
-
|
74
|
-
- `parameters`: An object of the parameters in the media type (name of the
|
75
|
-
parameter will be lower-cased). Example: `{charset: 'utf-8'}`
|
76
|
-
|
77
|
-
Throws a `TypeError` if the object contains an invalid type or parameter names.
|
78
|
-
|
79
|
-
## License
|
80
|
-
|
81
|
-
[MIT](LICENSE)
|
82
|
-
|
83
|
-
[npm-image]: https://img.shields.io/npm/v/content-type.svg
|
84
|
-
[npm-url]: https://npmjs.org/package/content-type
|
85
|
-
[node-version-image]: https://img.shields.io/node/v/content-type.svg
|
86
|
-
[node-version-url]: http://nodejs.org/download/
|
87
|
-
[travis-image]: https://img.shields.io/travis/jshttp/content-type/master.svg
|
88
|
-
[travis-url]: https://travis-ci.org/jshttp/content-type
|
89
|
-
[coveralls-image]: https://img.shields.io/coveralls/jshttp/content-type/master.svg
|
90
|
-
[coveralls-url]: https://coveralls.io/r/jshttp/content-type
|
91
|
-
[downloads-image]: https://img.shields.io/npm/dm/content-type.svg
|
92
|
-
[downloads-url]: https://npmjs.org/package/content-type
|