chore: update dependencies and remove unused files

refactor: migrate from nodemon to http-server for development
build: add type module and update package.json scripts
This commit is contained in:
你的名字
2025-07-21 18:19:22 +08:00
parent 6f3b0d4aac
commit c449a4fabd
433 changed files with 31743 additions and 48683 deletions

View File

@@ -1,13 +1,3 @@
0.5.4 / 2021-12-10
==================
* deps: safe-buffer@5.2.1
0.5.3 / 2018-12-17
==================
* Use `safe-buffer` for improved Buffer API
0.5.2 / 2016-12-08
==================

View File

@@ -1,6 +1,6 @@
(The MIT License)
Copyright (c) 2014-2017 Douglas Christopher Wilson
Copyright (c) 2014 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -3,7 +3,7 @@
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Build Status][github-actions-ci-image]][github-actions-ci-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
Create and parse HTTP `Content-Disposition` header
@@ -67,7 +67,7 @@ it). The type is normalized to lower-case.
### contentDisposition.parse(string)
```js
var disposition = contentDisposition.parse('attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt')
var disposition = contentDisposition.parse('attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt');
```
Parse a `Content-Disposition` header string. This automatically handles extended
@@ -88,13 +88,12 @@ are shown for the string `'attachment; filename="EURO rates.txt"; filename*=UTF-
```js
var contentDisposition = require('content-disposition')
var destroy = require('destroy')
var fs = require('fs')
var http = require('http')
var onFinished = require('on-finished')
var filePath = '/path/to/public/plans.pdf'
http.createServer(function onRequest (req, res) {
http.createServer(function onRequest(req, res) {
// set headers
res.setHeader('Content-Type', 'application/pdf')
res.setHeader('Content-Disposition', contentDisposition(filePath))
@@ -102,7 +101,7 @@ http.createServer(function onRequest (req, res) {
// send file
var stream = fs.createReadStream(filePath)
stream.pipe(res)
onFinished(res, function () {
onFinished(res, function (err) {
destroy(stream)
})
})
@@ -130,13 +129,13 @@ $ npm test
[MIT](LICENSE)
[npm-image]: https://img.shields.io/npm/v/content-disposition.svg
[npm-image]: https://img.shields.io/npm/v/content-disposition.svg?style=flat
[npm-url]: https://npmjs.org/package/content-disposition
[node-version-image]: https://img.shields.io/node/v/content-disposition.svg
[node-version-image]: https://img.shields.io/node/v/content-disposition.svg?style=flat
[node-version-url]: https://nodejs.org/en/download
[coveralls-image]: https://img.shields.io/coveralls/jshttp/content-disposition.svg
[travis-image]: https://img.shields.io/travis/jshttp/content-disposition.svg?style=flat
[travis-url]: https://travis-ci.org/jshttp/content-disposition
[coveralls-image]: https://img.shields.io/coveralls/jshttp/content-disposition.svg?style=flat
[coveralls-url]: https://coveralls.io/r/jshttp/content-disposition?branch=master
[downloads-image]: https://img.shields.io/npm/dm/content-disposition.svg
[downloads-image]: https://img.shields.io/npm/dm/content-disposition.svg?style=flat
[downloads-url]: https://npmjs.org/package/content-disposition
[github-actions-ci-image]: https://img.shields.io/github/workflow/status/jshttp/content-disposition/ci/master?label=ci
[github-actions-ci-url]: https://github.com/jshttp/content-disposition?query=workflow%3Aci

View File

@@ -1,6 +1,6 @@
/*!
* content-disposition
* Copyright(c) 2014-2017 Douglas Christopher Wilson
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
@@ -8,7 +8,6 @@
/**
* Module exports.
* @public
*/
module.exports = contentDisposition
@@ -16,22 +15,18 @@ module.exports.parse = parse
/**
* Module dependencies.
* @private
*/
var basename = require('path').basename
var Buffer = require('safe-buffer').Buffer
/**
* RegExp to match non attr-char, *after* encodeURIComponent (i.e. not including "%")
* @private
*/
var ENCODE_URL_ATTR_CHAR_REGEXP = /[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g // eslint-disable-line no-control-regex
/**
* RegExp to match percent encoding escape.
* @private
*/
var HEX_ESCAPE_REGEXP = /%[0-9A-Fa-f]{2}/
@@ -39,7 +34,6 @@ var HEX_ESCAPE_REPLACE_REGEXP = /%([0-9A-Fa-f]{2})/g
/**
* RegExp to match non-latin1 characters.
* @private
*/
var NON_LATIN1_REGEXP = /[^\x20-\x7e\xa0-\xff]/g
@@ -49,14 +43,12 @@ var NON_LATIN1_REGEXP = /[^\x20-\x7e\xa0-\xff]/g
*
* quoted-pair = "\" CHAR
* CHAR = <any US-ASCII character (octets 0 - 127)>
* @private
*/
var QESC_REGEXP = /\\([\u0000-\u007f])/g // eslint-disable-line no-control-regex
var QESC_REGEXP = /\\([\u0000-\u007f])/g
/**
* RegExp to match chars that must be quoted-pair in RFC 2616
* @private
*/
var QUOTE_REGEXP = /([\\"])/g
@@ -83,7 +75,6 @@ var QUOTE_REGEXP = /([\\"])/g
* HT = <US-ASCII HT, horizontal-tab (9)>
* CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
* OCTET = <any 8-bit sequence of data>
* @private
*/
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
@@ -109,7 +100,6 @@ var TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/
* attr-char = ALPHA / DIGIT
* / "!" / "#" / "$" / "&" / "+" / "-" / "."
* / "^" / "_" / "`" / "|" / "~"
* @private
*/
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!#$&+.^_`|~-])+)$/
@@ -125,7 +115,6 @@ var EXT_VALUE_REGEXP = /^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-
* disp-ext-parm = token "=" value
* | ext-token "=" ext-value
* ext-token = <the characters in token, followed by "*">
* @private
*/
var DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/ // eslint-disable-line no-control-regex
@@ -138,7 +127,7 @@ var DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/
* @param {string} [options.type=attachment]
* @param {string|boolean} [options.fallback=true]
* @return {string}
* @public
* @api public
*/
function contentDisposition (filename, options) {
@@ -160,7 +149,7 @@ function contentDisposition (filename, options) {
* @param {string} [filename]
* @param {string|boolean} [fallback=true]
* @return {object}
* @private
* @api private
*/
function createparams (filename, fallback) {
@@ -221,7 +210,7 @@ function createparams (filename, fallback) {
* @param {string} obj.type
* @param {object} [obj.parameters]
* @return {string}
* @private
* @api private
*/
function format (obj) {
@@ -255,11 +244,11 @@ function format (obj) {
}
/**
* Decode a RFC 5987 field value (gracefully).
* Decode a RFC 6987 field value (gracefully).
*
* @param {string} str
* @return {string}
* @private
* @api private
*/
function decodefield (str) {
@@ -281,7 +270,7 @@ function decodefield (str) {
value = getlatin1(binary)
break
case 'utf-8':
value = Buffer.from(binary, 'binary').toString('utf8')
value = new Buffer(binary, 'binary').toString('utf8')
break
default:
throw new TypeError('unsupported charset in extended field')
@@ -295,7 +284,7 @@ function decodefield (str) {
*
* @param {string} val
* @return {string}
* @private
* @api private
*/
function getlatin1 (val) {
@@ -308,7 +297,7 @@ function getlatin1 (val) {
*
* @param {string} string
* @return {object}
* @public
* @api private
*/
function parse (string) {
@@ -389,7 +378,7 @@ function parse (string) {
* @param {string} str
* @param {string} hex
* @return {string}
* @private
* @api private
*/
function pdecode (str, hex) {
@@ -401,14 +390,17 @@ function pdecode (str, hex) {
*
* @param {string} char
* @return {string}
* @private
* @api private
*/
function pencode (char) {
return '%' + String(char)
var hex = String(char)
.charCodeAt(0)
.toString(16)
.toUpperCase()
return hex.length === 1
? '%0' + hex
: '%' + hex
}
/**
@@ -416,7 +408,7 @@ function pencode (char) {
*
* @param {string} val
* @return {string}
* @private
* @api private
*/
function qstring (val) {
@@ -430,7 +422,7 @@ function qstring (val) {
*
* @param {string} val
* @return {string}
* @private
* @api private
*/
function ustring (val) {
@@ -445,11 +437,6 @@ function ustring (val) {
/**
* Class for parsed Content-Disposition header for v8 optimization
*
* @public
* @param {string} type
* @param {object} parameters
* @constructor
*/
function ContentDisposition (type, parameters) {

View File

@@ -1,8 +1,10 @@
{
"name": "content-disposition",
"description": "Create and parse Content-Disposition header",
"version": "0.5.4",
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
"version": "0.5.2",
"contributors": [
"Douglas Christopher Wilson <doug@somethingdoug.com>"
],
"license": "MIT",
"keywords": [
"content-disposition",
@@ -11,20 +13,13 @@
"res"
],
"repository": "jshttp/content-disposition",
"dependencies": {
"safe-buffer": "5.2.1"
},
"devDependencies": {
"deep-equal": "1.0.1",
"eslint": "7.32.0",
"eslint-config-standard": "13.0.1",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-markdown": "2.2.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.2.0",
"eslint-plugin-standard": "4.1.0",
"eslint": "3.11.1",
"eslint-config-standard": "6.2.1",
"eslint-plugin-promise": "3.3.0",
"eslint-plugin-standard": "2.0.1",
"istanbul": "0.4.5",
"mocha": "9.1.3"
"mocha": "1.21.5"
},
"files": [
"LICENSE",
@@ -38,7 +33,7 @@
"scripts": {
"lint": "eslint .",
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/"
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
}
}