initial commit
migrate files over from github
This commit is contained in:
226
node_modules/serve-favicon/index.js
generated
vendored
Normal file
226
node_modules/serve-favicon/index.js
generated
vendored
Normal file
@ -0,0 +1,226 @@
|
||||
/*!
|
||||
* serve-favicon
|
||||
* Copyright(c) 2010 Sencha Inc.
|
||||
* Copyright(c) 2011 TJ Holowaychuk
|
||||
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var etag = require('etag')
|
||||
var fresh = require('fresh')
|
||||
var fs = require('fs')
|
||||
var ms = require('ms')
|
||||
var parseUrl = require('parseurl')
|
||||
var path = require('path')
|
||||
var resolve = path.resolve
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
* @public
|
||||
*/
|
||||
|
||||
module.exports = favicon
|
||||
|
||||
/**
|
||||
* Module variables.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var ONE_YEAR_MS = 60 * 60 * 24 * 365 * 1000 // 1 year
|
||||
|
||||
/**
|
||||
* Serves the favicon located by the given `path`.
|
||||
*
|
||||
* @public
|
||||
* @param {String|Buffer} path
|
||||
* @param {Object} [options]
|
||||
* @return {Function} middleware
|
||||
*/
|
||||
|
||||
function favicon (path, options) {
|
||||
var opts = options || {}
|
||||
|
||||
var icon // favicon cache
|
||||
var maxAge = calcMaxAge(opts.maxAge)
|
||||
|
||||
if (!path) {
|
||||
throw new TypeError('path to favicon.ico is required')
|
||||
}
|
||||
|
||||
if (Buffer.isBuffer(path)) {
|
||||
icon = createIcon(Buffer.from(path), maxAge)
|
||||
} else if (typeof path === 'string') {
|
||||
path = resolveSync(path)
|
||||
} else {
|
||||
throw new TypeError('path to favicon.ico must be string or buffer')
|
||||
}
|
||||
|
||||
return function favicon (req, res, next) {
|
||||
if (getPathname(req) !== '/favicon.ico') {
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
||||
res.statusCode = req.method === 'OPTIONS' ? 200 : 405
|
||||
res.setHeader('Allow', 'GET, HEAD, OPTIONS')
|
||||
res.setHeader('Content-Length', '0')
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
|
||||
if (icon) {
|
||||
send(req, res, icon)
|
||||
return
|
||||
}
|
||||
|
||||
fs.readFile(path, function (err, buf) {
|
||||
if (err) return next(err)
|
||||
icon = createIcon(buf, maxAge)
|
||||
send(req, res, icon)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the max-age from a configured value.
|
||||
*
|
||||
* @private
|
||||
* @param {string|number} val
|
||||
* @return {number}
|
||||
*/
|
||||
|
||||
function calcMaxAge (val) {
|
||||
var num = typeof val === 'string'
|
||||
? ms(val)
|
||||
: val
|
||||
|
||||
return num != null
|
||||
? Math.min(Math.max(0, num), ONE_YEAR_MS)
|
||||
: ONE_YEAR_MS
|
||||
}
|
||||
|
||||
/**
|
||||
* Create icon data from Buffer and max-age.
|
||||
*
|
||||
* @private
|
||||
* @param {Buffer} buf
|
||||
* @param {number} maxAge
|
||||
* @return {object}
|
||||
*/
|
||||
|
||||
function createIcon (buf, maxAge) {
|
||||
return {
|
||||
body: buf,
|
||||
headers: {
|
||||
'Cache-Control': 'public, max-age=' + Math.floor(maxAge / 1000),
|
||||
'ETag': etag(buf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EISDIR error.
|
||||
*
|
||||
* @private
|
||||
* @param {string} path
|
||||
* @return {Error}
|
||||
*/
|
||||
|
||||
function createIsDirError (path) {
|
||||
var error = new Error('EISDIR, illegal operation on directory \'' + path + '\'')
|
||||
error.code = 'EISDIR'
|
||||
error.errno = 28
|
||||
error.path = path
|
||||
error.syscall = 'open'
|
||||
return error
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request pathname.
|
||||
*
|
||||
* @param {object} req
|
||||
* @return {string}
|
||||
*/
|
||||
|
||||
function getPathname (req) {
|
||||
try {
|
||||
return parseUrl(req).pathname
|
||||
} catch (e) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the cached representation is fresh.
|
||||
*
|
||||
* @param {object} req
|
||||
* @param {object} res
|
||||
* @return {boolean}
|
||||
* @private
|
||||
*/
|
||||
|
||||
function isFresh (req, res) {
|
||||
return fresh(req.headers, {
|
||||
'etag': res.getHeader('ETag'),
|
||||
'last-modified': res.getHeader('Last-Modified')
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the path to icon.
|
||||
*
|
||||
* @param {string} iconPath
|
||||
* @private
|
||||
*/
|
||||
|
||||
function resolveSync (iconPath) {
|
||||
var path = resolve(iconPath)
|
||||
var stat = fs.statSync(path)
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
throw createIsDirError(path)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
/**
|
||||
* Send icon data in response to a request.
|
||||
*
|
||||
* @private
|
||||
* @param {IncomingMessage} req
|
||||
* @param {OutgoingMessage} res
|
||||
* @param {object} icon
|
||||
*/
|
||||
|
||||
function send (req, res, icon) {
|
||||
// Set headers
|
||||
var headers = icon.headers
|
||||
var keys = Object.keys(headers)
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i]
|
||||
res.setHeader(key, headers[key])
|
||||
}
|
||||
|
||||
// Validate freshness
|
||||
if (isFresh(req, res)) {
|
||||
res.statusCode = 304
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
|
||||
// Send icon
|
||||
res.statusCode = 200
|
||||
res.setHeader('Content-Length', icon.body.length)
|
||||
res.setHeader('Content-Type', 'image/x-icon')
|
||||
res.end(icon.body)
|
||||
}
|
162
node_modules/serve-favicon/node_modules/ms/index.js
generated
vendored
Normal file
162
node_modules/serve-favicon/node_modules/ms/index.js
generated
vendored
Normal file
@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
|
||||
var s = 1000;
|
||||
var m = s * 60;
|
||||
var h = m * 60;
|
||||
var d = h * 24;
|
||||
var w = d * 7;
|
||||
var y = d * 365.25;
|
||||
|
||||
/**
|
||||
* Parse or format the given `val`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `long` verbose formatting [false]
|
||||
*
|
||||
* @param {String|Number} val
|
||||
* @param {Object} [options]
|
||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
||||
* @return {String|Number}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function(val, options) {
|
||||
options = options || {};
|
||||
var type = typeof val;
|
||||
if (type === 'string' && val.length > 0) {
|
||||
return parse(val);
|
||||
} else if (type === 'number' && isNaN(val) === false) {
|
||||
return options.long ? fmtLong(val) : fmtShort(val);
|
||||
}
|
||||
throw new Error(
|
||||
'val is not a non-empty string or a valid number. val=' +
|
||||
JSON.stringify(val)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` and return milliseconds.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parse(str) {
|
||||
str = String(str);
|
||||
if (str.length > 100) {
|
||||
return;
|
||||
}
|
||||
var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
||||
str
|
||||
);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
var n = parseFloat(match[1]);
|
||||
var type = (match[2] || 'ms').toLowerCase();
|
||||
switch (type) {
|
||||
case 'years':
|
||||
case 'year':
|
||||
case 'yrs':
|
||||
case 'yr':
|
||||
case 'y':
|
||||
return n * y;
|
||||
case 'weeks':
|
||||
case 'week':
|
||||
case 'w':
|
||||
return n * w;
|
||||
case 'days':
|
||||
case 'day':
|
||||
case 'd':
|
||||
return n * d;
|
||||
case 'hours':
|
||||
case 'hour':
|
||||
case 'hrs':
|
||||
case 'hr':
|
||||
case 'h':
|
||||
return n * h;
|
||||
case 'minutes':
|
||||
case 'minute':
|
||||
case 'mins':
|
||||
case 'min':
|
||||
case 'm':
|
||||
return n * m;
|
||||
case 'seconds':
|
||||
case 'second':
|
||||
case 'secs':
|
||||
case 'sec':
|
||||
case 's':
|
||||
return n * s;
|
||||
case 'milliseconds':
|
||||
case 'millisecond':
|
||||
case 'msecs':
|
||||
case 'msec':
|
||||
case 'ms':
|
||||
return n;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtShort(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return Math.round(ms / d) + 'd';
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return Math.round(ms / h) + 'h';
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return Math.round(ms / m) + 'm';
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return Math.round(ms / s) + 's';
|
||||
}
|
||||
return ms + 'ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Long format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtLong(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return plural(ms, msAbs, d, 'day');
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return plural(ms, msAbs, h, 'hour');
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return plural(ms, msAbs, m, 'minute');
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return plural(ms, msAbs, s, 'second');
|
||||
}
|
||||
return ms + ' ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluralization helper.
|
||||
*/
|
||||
|
||||
function plural(ms, msAbs, n, name) {
|
||||
var isPlural = msAbs >= n * 1.5;
|
||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
||||
}
|
37
node_modules/serve-favicon/node_modules/ms/package.json
generated
vendored
Normal file
37
node_modules/serve-favicon/node_modules/ms/package.json
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "ms",
|
||||
"version": "2.1.1",
|
||||
"description": "Tiny millisecond conversion utility",
|
||||
"repository": "zeit/ms",
|
||||
"main": "./index",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"scripts": {
|
||||
"precommit": "lint-staged",
|
||||
"lint": "eslint lib/* bin/*",
|
||||
"test": "mocha tests.js"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"npm run lint",
|
||||
"prettier --single-quote --write",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"eslint": "4.12.1",
|
||||
"expect.js": "0.3.1",
|
||||
"husky": "0.14.3",
|
||||
"lint-staged": "5.0.0",
|
||||
"mocha": "4.0.1"
|
||||
}
|
||||
}
|
62
node_modules/serve-favicon/node_modules/safe-buffer/index.js
generated
vendored
Normal file
62
node_modules/serve-favicon/node_modules/safe-buffer/index.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
/* eslint-disable node/no-deprecated-api */
|
||||
var buffer = require('buffer')
|
||||
var Buffer = buffer.Buffer
|
||||
|
||||
// alternative to using Object.keys for old browsers
|
||||
function copyProps (src, dst) {
|
||||
for (var key in src) {
|
||||
dst[key] = src[key]
|
||||
}
|
||||
}
|
||||
if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
|
||||
module.exports = buffer
|
||||
} else {
|
||||
// Copy properties from require('buffer')
|
||||
copyProps(buffer, exports)
|
||||
exports.Buffer = SafeBuffer
|
||||
}
|
||||
|
||||
function SafeBuffer (arg, encodingOrOffset, length) {
|
||||
return Buffer(arg, encodingOrOffset, length)
|
||||
}
|
||||
|
||||
// Copy static methods from Buffer
|
||||
copyProps(Buffer, SafeBuffer)
|
||||
|
||||
SafeBuffer.from = function (arg, encodingOrOffset, length) {
|
||||
if (typeof arg === 'number') {
|
||||
throw new TypeError('Argument must not be a number')
|
||||
}
|
||||
return Buffer(arg, encodingOrOffset, length)
|
||||
}
|
||||
|
||||
SafeBuffer.alloc = function (size, fill, encoding) {
|
||||
if (typeof size !== 'number') {
|
||||
throw new TypeError('Argument must be a number')
|
||||
}
|
||||
var buf = Buffer(size)
|
||||
if (fill !== undefined) {
|
||||
if (typeof encoding === 'string') {
|
||||
buf.fill(fill, encoding)
|
||||
} else {
|
||||
buf.fill(fill)
|
||||
}
|
||||
} else {
|
||||
buf.fill(0)
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
SafeBuffer.allocUnsafe = function (size) {
|
||||
if (typeof size !== 'number') {
|
||||
throw new TypeError('Argument must be a number')
|
||||
}
|
||||
return Buffer(size)
|
||||
}
|
||||
|
||||
SafeBuffer.allocUnsafeSlow = function (size) {
|
||||
if (typeof size !== 'number') {
|
||||
throw new TypeError('Argument must be a number')
|
||||
}
|
||||
return buffer.SlowBuffer(size)
|
||||
}
|
37
node_modules/serve-favicon/node_modules/safe-buffer/package.json
generated
vendored
Normal file
37
node_modules/serve-favicon/node_modules/safe-buffer/package.json
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "safe-buffer",
|
||||
"description": "Safer Node.js Buffer API",
|
||||
"version": "5.1.1",
|
||||
"author": {
|
||||
"name": "Feross Aboukhadijeh",
|
||||
"email": "feross@feross.org",
|
||||
"url": "http://feross.org"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/feross/safe-buffer/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"standard": "*",
|
||||
"tape": "^4.0.0",
|
||||
"zuul": "^3.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/feross/safe-buffer",
|
||||
"keywords": [
|
||||
"buffer",
|
||||
"buffer allocate",
|
||||
"node security",
|
||||
"safe",
|
||||
"safe-buffer",
|
||||
"security",
|
||||
"uninitialized"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/feross/safe-buffer.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && tape test.js"
|
||||
}
|
||||
}
|
47
node_modules/serve-favicon/package.json
generated
vendored
Normal file
47
node_modules/serve-favicon/package.json
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "serve-favicon",
|
||||
"description": "favicon serving middleware with caching",
|
||||
"version": "2.5.0",
|
||||
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"express",
|
||||
"favicon",
|
||||
"middleware"
|
||||
],
|
||||
"repository": "expressjs/serve-favicon",
|
||||
"dependencies": {
|
||||
"etag": "~1.8.1",
|
||||
"fresh": "0.5.2",
|
||||
"ms": "2.1.1",
|
||||
"parseurl": "~1.3.2",
|
||||
"safe-buffer": "5.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "4.19.1",
|
||||
"eslint-config-standard": "11.0.0",
|
||||
"eslint-plugin-import": "2.9.0",
|
||||
"eslint-plugin-markdown": "1.0.0-beta.6",
|
||||
"eslint-plugin-node": "6.0.1",
|
||||
"eslint-plugin-promise": "3.7.0",
|
||||
"eslint-plugin-standard": "3.0.1",
|
||||
"istanbul": "0.4.5",
|
||||
"mocha": "2.5.3",
|
||||
"supertest": "1.1.0",
|
||||
"temp-path": "1.0.0"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"HISTORY.md",
|
||||
"index.js"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --plugin markdown --ext js,md .",
|
||||
"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/"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user