nav tabs on admin dashboard

This commit is contained in:
2019-03-07 00:20:34 -06:00
parent f73d6ae228
commit e4f473f376
11661 changed files with 216240 additions and 1544253 deletions

View File

@@ -1,10 +1,95 @@
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="2.4.0"></a>
# [2.4.0](https://github.com/broofa/node-mime/compare/v2.3.1...v2.4.0) (2018-11-26)
### Features
* Bind exported methods ([9d2a7b8](https://github.com/broofa/node-mime/commit/9d2a7b8))
* update to mime-db@1.37.0 ([49e6e41](https://github.com/broofa/node-mime/commit/49e6e41))
<a name="2.3.1"></a>
## [2.3.1](https://github.com/broofa/node-mime/compare/v2.3.0...v2.3.1) (2018-04-11)
### Bug Fixes
* fix [#198](https://github.com/broofa/node-mime/issues/198) ([25ca180](https://github.com/broofa/node-mime/commit/25ca180))
<a name="2.3.0"></a>
# [2.3.0](https://github.com/broofa/node-mime/compare/v2.2.2...v2.3.0) (2018-04-11)
### Bug Fixes
* fix [#192](https://github.com/broofa/node-mime/issues/192) ([5c35df6](https://github.com/broofa/node-mime/commit/5c35df6))
### Features
* add travis-ci testing ([d64160f](https://github.com/broofa/node-mime/commit/d64160f))
<a name="2.2.2"></a>
## [2.2.2](https://github.com/broofa/node-mime/compare/v2.2.1...v2.2.2) (2018-03-30)
### Bug Fixes
* update types files to mime-db@1.32.0 ([85aac16](https://github.com/broofa/node-mime/commit/85aac16))
<a name="2.2.1"></a>
## [2.2.1](https://github.com/broofa/node-mime/compare/v2.2.0...v2.2.1) (2018-03-30)
### Bug Fixes
* Retain type->extension mappings for non-default types. Fixes [#180](https://github.com/broofa/node-mime/issues/180) ([b5c83fb](https://github.com/broofa/node-mime/commit/b5c83fb))
<a name="2.2.0"></a>
# [2.2.0](https://github.com/broofa/node-mime/compare/v2.1.0...v2.2.0) (2018-01-04)
### Features
* Retain type->extension mappings for non-default types. Fixes [#180](https://github.com/broofa/node-mime/issues/180) ([10f82ac](https://github.com/broofa/node-mime/commit/10f82ac))
<a name="2.1.0"></a>
# [2.1.0](https://github.com/broofa/node-mime/compare/v2.0.5...v2.1.0) (2017-12-22)
### Features
* Upgrade to mime-db@1.32.0. Fixes [#185](https://github.com/broofa/node-mime/issues/185) ([3f775ba](https://github.com/broofa/node-mime/commit/3f775ba))
<a name="2.0.5"></a>
## [2.0.5](https://github.com/broofa/node-mime/compare/v2.0.1...v2.0.5) (2017-12-22)
### Bug Fixes
* ES5 support (back to node v0.4) ([f14ccb6](https://github.com/broofa/node-mime/commit/f14ccb6))
# Changelog
## v1.6.0 (24/11/2017)
*No changelog for this release.*
---
## v2.0.4 (24/11/2017)
- [**closed**] Switch to mime-score module for resolving extension contention issues. [#182](https://github.com/broofa/node-mime/issues/182)
- [**closed**] Update mime-db to 1.31.0 in v1.x branch [#181](https://github.com/broofa/node-mime/issues/181)
@@ -149,16 +234,3 @@
- [**closed**] Transfer ownership to @broofa [#36](https://github.com/broofa/node-mime/issues/36)
- [**closed**] it's wrong to set charset to UTF-8 for text [#30](https://github.com/broofa/node-mime/issues/30)
- [**closed**] Allow multiple instances of MIME types container [#27](https://github.com/broofa/node-mime/issues/27)
---
## v1.2.5 (16/02/2012)
- [**closed**] When looking up a types, check hasOwnProperty [#23](https://github.com/broofa/node-mime/issues/23)
- [**closed**] Bump version to 1.2.2 [#18](https://github.com/broofa/node-mime/issues/18)
- [**closed**] No license [#16](https://github.com/broofa/node-mime/issues/16)
- [**closed**] Some types missing that are used by html5/css3 [#13](https://github.com/broofa/node-mime/issues/13)
- [**closed**] npm install fails for 1.2.1 [#12](https://github.com/broofa/node-mime/issues/12)
- [**closed**] image/pjpeg + image/x-png [#10](https://github.com/broofa/node-mime/issues/10)
- [**closed**] symlink [#8](https://github.com/broofa/node-mime/issues/8)
- [**closed**] gzip [#2](https://github.com/broofa/node-mime/issues/2)
- [**closed**] ALL CAPS filenames return incorrect mime type [#1](https://github.com/broofa/node-mime/issues/1)

View File

@@ -1,90 +1,190 @@
# mime
<!--
-- This file is auto-generated from src/README_js.md. Changes should be made there.
-->
# Mime
Comprehensive MIME type mapping API based on mime-db module.
A comprehensive, compact MIME type module.
[![Build Status](https://travis-ci.org/broofa/node-mime.svg?branch=master)](https://travis-ci.org/broofa/node-mime)
## Version 2 Notes
Version 2 is a breaking change from 1.x as the semver implies. Specifically:
* `lookup()` renamed to `getType()`
* `extension()` renamed to `getExtension()`
* `charset()` and `load()` methods have been removed
If you prefer the legacy version of this module please `npm install mime@^1`. Version 1 docs may be found [here](https://github.com/broofa/node-mime/tree/v1.4.0).
## Install
Install with [npm](http://github.com/isaacs/npm):
### NPM
```
npm install mime
```
npm install mime
### Browser
## Contributing / Testing
It is recommended that you use a bundler such as
[webpack](https://webpack.github.io/) or [browserify](http://browserify.org/) to
package your code. However, browser-ready versions are available via wzrd.in.
E.g. For the full version:
npm run test
<script src="https://wzrd.in/standalone/mime@latest"></script>
<script>
mime.getType(...); // etc.
<script>
Or, for the `mime/lite` version:
<script src="https://wzrd.in/standalone/mime%2flite@latest"></script>
<script>
mimelite.getType(...); // (Note `mimelite` here)
<script>
## Quick Start
For the full version (800+ MIME types, 1,000+ extensions):
```javascript
const mime = require('mime');
mime.getType('txt'); // ⇨ 'text/plain'
mime.getExtension('text/plain'); // ⇨ 'txt'
```
See [Mime API](#mime-api) below for API details.
## Lite Version
There is also a "lite" version of this module that omits vendor-specific
(`*/vnd.*`) and experimental (`*/x-*`) types. It weighs in at ~2.5KB, compared
to 8KB for the full version. To load the lite version:
```javascript
const mime = require('mime/lite');
```
## Mime .vs. mime-types .vs. mime-db modules
For those of you wondering about the difference between these [popular] NPM modules,
here's a brief rundown ...
[`mime-db`](https://github.com/jshttp/mime-db) is "the source of
truth" for MIME type information. It is not an API. Rather, it is a canonical
dataset of mime type definitions pulled from IANA, Apache, NGINX, and custom mappings
submitted by the Node.js community.
[`mime-types`](https://github.com/jshttp/mime-types) is a thin
wrapper around mime-db that provides an API drop-in compatible(ish) with `mime @ < v1.3.6` API.
`mime` is, as of v2, a self-contained module bundled with a pre-optimized version
of the `mime-db` dataset. It provides a simplified API with the following characteristics:
* Intelligently resolved type conflicts (See [mime-score](https://github.com/broofa/mime-score) for details)
* Method naming consistent with industry best-practices
* Compact footprint. E.g. The minified+compressed sizes of the various modules:
Module | Size
--- | ---
`mime-db` | 18 KB
`mime-types` | same as mime-db
`mime` | 8 KB
`mime/lite` | 2 KB
## Mime API
Both `require('mime')` and `require('mime/lite')` return instances of the MIME
class, documented below.
### new Mime(typeMap, ... more maps)
Most users of this module will not need to create Mime instances directly.
However if you would like to create custom mappings, you may do so as follows
...
```javascript
// Require Mime class
const Mime = require('mime/Mime');
// Define mime type -> extensions map
const typeMap = {
'text/abc': ['abc', 'alpha', 'bet'],
'text/def': ['leppard']
};
// Create and use Mime instance
const myMime = new Mime(typeMap);
myMime.getType('abc'); // ⇨ 'text/abc'
myMime.getExtension('text/def'); // ⇨ 'leppard'
```
If more than one map argument is provided, each map is `define()`ed (see below), in order.
### mime.getType(pathOrExtension)
Get mime type for the given path or extension. E.g.
```javascript
mime.getType('js'); // ⇨ 'application/javascript'
mime.getType('json'); // ⇨ 'application/json'
mime.getType('txt'); // ⇨ 'text/plain'
mime.getType('dir/text.txt'); // ⇨ 'text/plain'
mime.getType('dir\\text.txt'); // ⇨ 'text/plain'
mime.getType('.text.txt'); // ⇨ 'text/plain'
mime.getType('.txt'); // ⇨ 'text/plain'
```
`null` is returned in cases where an extension is not detected or recognized
```javascript
mime.getType('foo/txt'); // ⇨ null
mime.getType('bogus_type'); // ⇨ null
```
### mime.getExtension(type)
Get extension for the given mime type. Charset options (often included in
Content-Type headers) are ignored.
```javascript
mime.getExtension('text/plain'); // ⇨ 'txt'
mime.getExtension('application/json'); // ⇨ 'json'
mime.getExtension('text/html; charset=utf8'); // ⇨ 'html'
```
### mime.define(typeMap[, force = false])
Define [more] type mappings.
`typeMap` is a map of type -> extensions, as documented in `new Mime`, above.
By default this method will throw an error if you try to map a type to an
extension that is already assigned to another type. Passing `true` for the
`force` argument will suppress this behavior (overriding any previous mapping).
```javascript
mime.define({'text/x-abc': ['abc', 'abcd']});
mime.getType('abcd'); // ⇨ 'text/x-abc'
mime.getExtension('text/x-abc') // ⇨ 'abc'
```
## Command Line
mime [path_string]
mime [path_or_extension]
E.g.
> mime scripts/jquery.js
application/javascript
## API - Queries
### mime.lookup(path)
Get the mime type associated with a file, if no mime type is found `application/octet-stream` is returned. Performs a case-insensitive lookup using the extension in `path` (the substring after the last '/' or '.'). E.g.
```js
var mime = require('mime');
mime.lookup('/path/to/file.txt'); // => 'text/plain'
mime.lookup('file.txt'); // => 'text/plain'
mime.lookup('.TXT'); // => 'text/plain'
mime.lookup('htm'); // => 'text/html'
```
### mime.default_type
Sets the mime type returned when `mime.lookup` fails to find the extension searched for. (Default is `application/octet-stream`.)
### mime.extension(type)
Get the default extension for `type`
```js
mime.extension('text/html'); // => 'html'
mime.extension('application/octet-stream'); // => 'bin'
```
### mime.charsets.lookup()
Map mime-type to charset
```js
mime.charsets.lookup('text/plain'); // => 'UTF-8'
```
(The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)
## API - Defining Custom Types
Custom type mappings can be added on a per-project basis via the following APIs.
### mime.define()
Add custom mime/extension mappings
```js
mime.define({
'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
'application/x-my-type': ['x-mt', 'x-mtt'],
// etc ...
});
mime.lookup('x-sft'); // => 'text/x-some-format'
```
The first entry in the extensions array is returned by `mime.extension()`. E.g.
```js
mime.extension('text/x-some-format'); // => 'x-sf'
```
### mime.load(filepath)
Load mappings from an Apache ".types" format file
```js
mime.load('./my_project.types');
```
The .types file format is simple - See the `types` dir for examples.
----
Markdown generated from [src/README_js.md](src/README_js.md) by [![RunMD Logo](http://i.imgur.com/h0FVyzU.png)](https://github.com/broofa/runmd)

View File

@@ -1,8 +1,10 @@
#!/usr/bin/env node
var mime = require('./mime.js');
'use strict';
var mime = require('.');
var file = process.argv[2];
var type = mime.lookup(file);
var type = mime.getType(file);
process.stdout.write(type + '\n');

View File

@@ -1,108 +1,93 @@
var path = require('path');
var fs = require('fs');
'use strict';
/**
* @param typeMap [Object] Map of MIME type -> Array[extensions]
* @param ...
*/
function Mime() {
// Map of extension -> mime type
this.types = Object.create(null);
this._types = Object.create(null);
this._extensions = Object.create(null);
// Map of mime type -> extension
this.extensions = Object.create(null);
for (var i = 0; i < arguments.length; i++) {
this.define(arguments[i]);
}
this.define = this.define.bind(this);
this.getType = this.getType.bind(this);
this.getExtension = this.getExtension.bind(this);
}
/**
* Define mimetype -> extension mappings. Each key is a mime-type that maps
* Define mimetype -> xtension mappings. Each key is a mime-type that maps
* to an array of extensions associated with the type. The first extension is
* used as the default extension for the type.
*
* e.g. mime.define({'audio/ogg', ['oga', 'ogg', 'spx']});
*
* If a type declares an extension that has already been defined, an error will
* be thrown. To suppress this error and force the extension to be associated
* with the new type, pass `force`=true. Alternatively, you may prefix the
* extension with "*" to map the type to extension, without mapping the
* extension to the type.
*
* e.g. mime.define({'audio/wav', ['wav']}, {'audio/x-wav', ['*wav']});
*
*
* @param map (Object) type definitions
* @param force (Boolean) if true, force overriding of existing definitions
*/
Mime.prototype.define = function (map) {
for (var type in map) {
var exts = map[type];
for (var i = 0; i < exts.length; i++) {
if (process.env.DEBUG_MIME && this.types[exts[i]]) {
console.warn((this._loading || "define()").replace(/.*\//, ''), 'changes "' + exts[i] + '" extension type from ' +
this.types[exts[i]] + ' to ' + type);
Mime.prototype.define = function(typeMap, force) {
for (var type in typeMap) {
var extensions = typeMap[type];
for (var i = 0; i < extensions.length; i++) {
var ext = extensions[i];
// '*' prefix = not the preferred type for this extension. So fixup the
// extension, and skip it.
if (ext[0] == '*') {
continue;
}
this.types[exts[i]] = type;
if (!force && (ext in this._types)) {
throw new Error(
'Attempt to change mapping for "' + ext +
'" extension from "' + this._types[ext] + '" to "' + type +
'". Pass `force=true` to allow this, otherwise remove "' + ext +
'" from the list of extensions for "' + type + '".'
);
}
this._types[ext] = type;
}
// Default extension is the first one we encounter
if (!this.extensions[type]) {
this.extensions[type] = exts[0];
// Use first extension as default
if (force || !this._extensions[type]) {
var ext = extensions[0];
this._extensions[type] = (ext[0] != '*') ? ext : ext.substr(1)
}
}
};
/**
* Load an Apache2-style ".types" file
*
* This may be called multiple times (it's expected). Where files declare
* overlapping types/extensions, the last file wins.
*
* @param file (String) path of file to load.
*/
Mime.prototype.load = function(file) {
this._loading = file;
// Read file and split into lines
var map = {},
content = fs.readFileSync(file, 'ascii'),
lines = content.split(/[\r\n]+/);
lines.forEach(function(line) {
// Clean up whitespace/comments, and split into fields
var fields = line.replace(/\s*#.*|^\s*|\s*$/g, '').split(/\s+/);
map[fields.shift()] = fields;
});
this.define(map);
this._loading = null;
};
/**
* Lookup a mime type based on extension
*/
Mime.prototype.lookup = function(path, fallback) {
var ext = path.replace(/^.*[\.\/\\]/, '').toLowerCase();
Mime.prototype.getType = function(path) {
path = String(path);
var last = path.replace(/^.*[/\\]/, '').toLowerCase();
var ext = last.replace(/^.*\./, '').toLowerCase();
return this.types[ext] || fallback || this.default_type;
var hasPath = last.length < path.length;
var hasDot = ext.length < last.length - 1;
return (hasDot || !hasPath) && this._types[ext] || null;
};
/**
* Return file extension associated with a mime type
*/
Mime.prototype.extension = function(mimeType) {
var type = mimeType.match(/^\s*([^;\s]*)(?:;|\s|$)/)[1].toLowerCase();
return this.extensions[type];
Mime.prototype.getExtension = function(type) {
type = /^\s*([^;\s]*)/.test(type) && RegExp.$1;
return type && this._extensions[type.toLowerCase()] || null;
};
// Default instance
var mime = new Mime();
// Define built-in types
mime.define(require('./types.json'));
// Default type
mime.default_type = mime.lookup('bin');
//
// Additional API specific to the default instance
//
mime.Mime = Mime;
/**
* Lookup a charset based on mime type.
*/
mime.charsets = {
lookup: function(mimeType, fallback) {
// Assume text types are utf8
return (/^text\/|^application\/(javascript|json)/).test(mimeType) ? 'UTF-8' : fallback;
}
};
module.exports = mime;
module.exports = Mime;

View File

@@ -1,26 +1,26 @@
{
"_from": "mime@^1.5.0",
"_id": "mime@1.6.0",
"_from": "mime@^2.3.1",
"_id": "mime@2.4.0",
"_inBundle": false,
"_integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
"_integrity": "sha512-ikBcWwyqXQSHKtciCcctu9YfPbFYZ4+gbHEmE0Q8jzcTYQg5dHCr3g2wwAZjPoJfQVXZq6KXAjpXOTf5/cjT7w==",
"_location": "/webpack-dev-middleware/mime",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "mime@^1.5.0",
"raw": "mime@^2.3.1",
"name": "mime",
"escapedName": "mime",
"rawSpec": "^1.5.0",
"rawSpec": "^2.3.1",
"saveSpec": null,
"fetchSpec": "^1.5.0"
"fetchSpec": "^2.3.1"
},
"_requiredBy": [
"/webpack-dev-middleware"
],
"_resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"_shasum": "32cd9e5c64553bd58d19a568af452acff04981b1",
"_spec": "mime@^1.5.0",
"_resolved": "https://registry.npmjs.org/mime/-/mime-2.4.0.tgz",
"_shasum": "e051fd881358585f3279df333fe694da0bcffdd6",
"_spec": "mime@^2.3.1",
"_where": "C:\\xampp\\htdocs\\w4rpservices\\node_modules\\webpack-dev-middleware",
"author": {
"name": "Robert Kieffer",
@@ -34,23 +34,22 @@
"url": "https://github.com/broofa/node-mime/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Benjamin Thomas",
"email": "benjamin@benjaminthomas.org",
"url": "http://github.com/bentomas"
}
],
"contributors": [],
"dependencies": {},
"deprecated": false,
"description": "A comprehensive library for mime-type mapping",
"devDependencies": {
"github-release-notes": "0.13.1",
"mime-db": "1.31.0",
"mime-score": "1.1.0"
"chalk": "1.1.3",
"eslint": "^5.9.0",
"mime-db": "^1.37.0",
"mime-score": "1.0.1",
"mime-types": "2.1.15",
"mocha": "5.2.0",
"runmd": "1.0.1",
"standard-version": "^4.4.0"
},
"engines": {
"node": ">=4"
"node": ">=4.0.0"
},
"homepage": "https://github.com/broofa/node-mime#readme",
"keywords": [
@@ -58,16 +57,16 @@
"mime"
],
"license": "MIT",
"main": "mime.js",
"name": "mime",
"repository": {
"url": "git+https://github.com/broofa/node-mime.git",
"type": "git"
},
"scripts": {
"changelog": "gren changelog --tags=all --generate --override",
"prepare": "node src/build.js",
"test": "node src/test.js"
"md": "runmd --watch --output README.md src/README_js.md",
"prepare": "node src/build.js && runmd --output README.md src/README_js.md",
"release": "standard-version",
"test": "mocha src/test.js"
},
"version": "1.6.0"
"version": "2.4.0"
}

View File

@@ -2,38 +2,47 @@
'use strict';
const fs = require('fs');
const path = require('path');
const mimeScore = require('mime-score');
var fs = require('fs');
var path = require('path');
var mimeScore = require('mime-score');
let db = require('mime-db');
let chalk = require('chalk');
var db = require('mime-db');
var chalk = require('chalk');
const STANDARD_FACET_SCORE = 900;
var STANDARD_FACET_SCORE = 900;
const byExtension = {};
var byExtension = {};
// Clear out any conflict extensions in mime-db
for (let type in db) {
let entry = db[type];
for (var type in db) {
var entry = db[type];
entry.type = type;
if (!entry.extensions) continue;
entry.extensions.forEach(ext => {
entry.extensions.forEach(function(ext) {
var drop;
var keep = entry;
if (ext in byExtension) {
const e0 = entry;
const e1 = byExtension[ext];
var e0 = entry;
var e1 = byExtension[ext];
e0.pri = mimeScore(e0.type, e0.source);
e1.pri = mimeScore(e1.type, e1.source);
let drop = e0.pri < e1.pri ? e0 : e1;
let keep = e0.pri >= e1.pri ? e0 : e1;
drop.extensions = drop.extensions.filter(e => e !== ext);
drop = e0.pri < e1.pri ? e0 : e1;
keep = e0.pri >= e1.pri ? e0 : e1;
console.log(`${ext}: Keeping ${chalk.green(keep.type)} (${keep.pri}), dropping ${chalk.red(drop.type)} (${drop.pri})`);
// Prefix lower-priority extensions with '*'
drop.extensions = drop.extensions.map(function(e) {return e == ext ? '*' + e : e});
console.log(
ext + ': Preferring ' + chalk.green(keep.type) + ' (' + keep.pri +
') over ' + chalk.red(drop.type) + ' (' + drop.pri + ')' + ' for ' + ext
);
}
byExtension[ext] = entry;
// Cache the hightest ranking type for this extension
if (keep == entry) byExtension[ext] = entry;
});
}
@@ -43,11 +52,20 @@ function writeTypesFile(types, path) {
// Segregate into standard and non-standard types based on facet per
// https://tools.ietf.org/html/rfc6838#section-3.1
const types = {};
var standard = {};
var other = {};
Object.keys(db).sort().forEach(k => {
const entry = db[k];
types[entry.type] = entry.extensions;
Object.keys(db).sort().forEach(function(k) {
var entry = db[k];
if (entry.extensions) {
if (mimeScore(entry.type, entry.source) >= STANDARD_FACET_SCORE) {
standard[entry.type] = entry.extensions;
} else {
other[entry.type] = entry.extensions;
}
}
});
writeTypesFile(types, path.join(__dirname, '..', 'types.json'));
writeTypesFile(standard, path.join(__dirname, '../types', 'standard.json'));
writeTypesFile(other, path.join(__dirname, '../types', 'other.json'));

View File

@@ -1,60 +1,257 @@
/**
* Usage: node test.js
*/
'use strict';
var mime = require('../mime');
var mime = require('..');
var mimeTypes = require('../node_modules/mime-types');
var assert = require('assert');
var path = require('path');
var chalk = require('chalk');
//
// Test mime lookups
//
describe('class Mime', function() {
it('mime and mime/lite coexist', function() {
assert.doesNotThrow(function() {
require('../lite');
});
});
assert.equal('text/plain', mime.lookup('text.txt')); // normal file
assert.equal('text/plain', mime.lookup('TEXT.TXT')); // uppercase
assert.equal('text/plain', mime.lookup('dir/text.txt')); // dir + file
assert.equal('text/plain', mime.lookup('.text.txt')); // hidden file
assert.equal('text/plain', mime.lookup('.txt')); // nameless
assert.equal('text/plain', mime.lookup('txt')); // extension-only
assert.equal('text/plain', mime.lookup('/txt')); // extension-less ()
assert.equal('text/plain', mime.lookup('\\txt')); // Windows, extension-less
assert.equal('application/octet-stream', mime.lookup('text.nope')); // unrecognized
assert.equal('fallback', mime.lookup('text.fallback', 'fallback')); // alternate default
it('new constructor()', function() {
var Mime = require('../Mime');
//
// Test extensions
//
var mime = new Mime(
{'text/a': ['a', 'a1']},
{'text/b': ['b', 'b1']}
);
assert.equal('txt', mime.extension(mime.types.text));
assert.equal('html', mime.extension(mime.types.htm));
assert.equal('bin', mime.extension('application/octet-stream'));
assert.equal('bin', mime.extension('application/octet-stream '));
assert.equal('html', mime.extension(' text/html; charset=UTF-8'));
assert.equal('html', mime.extension('text/html; charset=UTF-8 '));
assert.equal('html', mime.extension('text/html; charset=UTF-8'));
assert.equal('html', mime.extension('text/html ; charset=UTF-8'));
assert.equal('html', mime.extension('text/html;charset=UTF-8'));
assert.equal('html', mime.extension('text/Html;charset=UTF-8'));
assert.equal(undefined, mime.extension('unrecognized'));
assert.deepEqual(mime._types, {
a: 'text/a',
a1: 'text/a',
b: 'text/b',
b1: 'text/b',
});
//
// Test node.types lookups
//
assert.deepEqual(mime._extensions, {
'text/a': 'a',
'text/b': 'b',
});
});
assert.equal('font/woff', mime.lookup('file.woff'));
assert.equal('application/octet-stream', mime.lookup('file.buffer'));
// TODO: Uncomment once #157 is resolved
// assert.equal('audio/mp4', mime.lookup('file.m4a'));
assert.equal('font/otf', mime.lookup('file.otf'));
it('define()', function() {
var Mime = require('../Mime');
//
// Test charsets
//
var mime = new Mime({'text/a': ['a']}, {'text/b': ['b']});
assert.equal('UTF-8', mime.charsets.lookup('text/plain'));
assert.equal('UTF-8', mime.charsets.lookup(mime.types.js));
assert.equal('UTF-8', mime.charsets.lookup(mime.types.json));
assert.equal(undefined, mime.charsets.lookup(mime.types.bin));
assert.equal('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
assert.throws(function() {
mime.define({'text/c': ['b']});
});
console.log('\nAll tests passed');
assert.doesNotThrow(function() {
mime.define({'text/c': ['b']}, true);
});
assert.deepEqual(mime._types, {
a: 'text/a',
b: 'text/c',
});
assert.deepEqual(mime._extensions, {
'text/a': 'a',
'text/b': 'b',
'text/c': 'b',
});
});
it('define() *\'ed types', function() {
var Mime = require('../Mime');
var mime = new Mime(
{'text/a': ['*b']},
{'text/b': ['b']}
);
assert.deepEqual(mime._types, {
b: 'text/b',
});
assert.deepEqual(mime._extensions, {
'text/a': 'b',
'text/b': 'b',
});
});
it('getType()', function() {
// Upper/lower case
assert.equal(mime.getType('text.txt'), 'text/plain');
assert.equal(mime.getType('TEXT.TXT'), 'text/plain');
// Bare extension
assert.equal(mime.getType('txt'), 'text/plain');
assert.equal(mime.getType('.txt'), 'text/plain');
assert.strictEqual(mime.getType('.bogus'), null);
assert.strictEqual(mime.getType('bogus'), null);
// Non-sensical
assert.strictEqual(mime.getType(null), null);
assert.strictEqual(mime.getType(undefined), null);
assert.strictEqual(mime.getType(42), null);
assert.strictEqual(mime.getType({}), null);
// File paths
assert.equal(mime.getType('dir/text.txt'), 'text/plain');
assert.equal(mime.getType('dir\\text.txt'), 'text/plain');
assert.equal(mime.getType('.text.txt'), 'text/plain');
assert.equal(mime.getType('.txt'), 'text/plain');
assert.equal(mime.getType('txt'), 'text/plain');
assert.equal(mime.getType('/path/to/page.html'), 'text/html');
assert.equal(mime.getType('c:\\path\\to\\page.html'), 'text/html');
assert.equal(mime.getType('page.html'), 'text/html');
assert.equal(mime.getType('path/to/page.html'), 'text/html');
assert.equal(mime.getType('path\\to\\page.html'), 'text/html');
assert.strictEqual(mime.getType('/txt'), null);
assert.strictEqual(mime.getType('\\txt'), null);
assert.strictEqual(mime.getType('text.nope'), null);
assert.strictEqual(mime.getType('/path/to/file.bogus'), null);
assert.strictEqual(mime.getType('/path/to/json'), null);
assert.strictEqual(mime.getType('/path/to/.json'), null);
assert.strictEqual(mime.getType('/path/to/.config.json'), 'application/json');
assert.strictEqual(mime.getType('.config.json'), 'application/json');
});
it('getExtension()', function() {
assert.equal(mime.getExtension('text/html'), 'html');
assert.equal(mime.getExtension(' text/html'), 'html');
assert.equal(mime.getExtension('text/html '), 'html');
assert.strictEqual(mime.getExtension('application/x-bogus'), null);
assert.strictEqual(mime.getExtension('bogus'), null);
assert.strictEqual(mime.getExtension(null), null);
assert.strictEqual(mime.getExtension(undefined), null);
assert.strictEqual(mime.getExtension(42), null);
assert.strictEqual(mime.getExtension({}), null);
});
});
describe('DB', function() {
var diffs = [];
after(function() {
if (diffs.length) {
console.log('\n[INFO] The following inconsistencies with MDN (https://goo.gl/lHrFU6) and/or mime-types (https://github.com/jshttp/mime-types) are expected:');
diffs.forEach(function(d) {
console.warn(
' ' + d[0]+ '[' + chalk.blue(d[1]) + '] = ' + chalk.red(d[2]) +
', mime[' + d[1] + '] = ' + chalk.green(d[3])
);
});
}
});
it('Consistency', function() {
for (var ext in this.types) {
assert.equal(ext, this.extensions[this.types[ext]], '${ext} does not have consistent ext->type->ext mapping');
}
});
it('MDN types', function() {
// MDN types listed at https://goo.gl/lHrFU6
var MDN = {
'aac': 'audio/aac',
'abw': 'application/x-abiword',
'arc': 'application/octet-stream',
'avi': 'video/x-msvideo',
'azw': 'application/vnd.amazon.ebook',
'bin': 'application/octet-stream',
'bz': 'application/x-bzip',
'bz2': 'application/x-bzip2',
'csh': 'application/x-csh',
'css': 'text/css',
'csv': 'text/csv',
'doc': 'application/msword',
'epub': 'application/epub+zip',
'gif': 'image/gif',
'html': 'text/html',
'ico': 'image/x-icon',
'ics': 'text/calendar',
'jar': 'application/java-archive',
'jpg': 'image/jpeg',
'js': 'application/javascript',
'json': 'application/json',
'midi': 'audio/midi',
'mpeg': 'video/mpeg',
'mpkg': 'application/vnd.apple.installer+xml',
'odp': 'application/vnd.oasis.opendocument.presentation',
'ods': 'application/vnd.oasis.opendocument.spreadsheet',
'odt': 'application/vnd.oasis.opendocument.text',
'oga': 'audio/ogg',
'ogv': 'video/ogg',
'ogx': 'application/ogg',
'png': 'image/png',
'pdf': 'application/pdf',
'ppt': 'application/vnd.ms-powerpoint',
'rar': 'application/x-rar-compressed',
'rtf': 'application/rtf',
'sh': 'application/x-sh',
'svg': 'image/svg+xml',
'swf': 'application/x-shockwave-flash',
'tar': 'application/x-tar',
'tiff': 'image/tiff',
'ttf': 'font/ttf',
'vsd': 'application/vnd.visio',
'wav': 'audio/x-wav',
'weba': 'audio/webm',
'webm': 'video/webm',
'webp': 'image/webp',
'woff': 'font/woff',
'woff2': 'font/woff2',
'xhtml': 'application/xhtml+xml',
'xls': 'application/vnd.ms-excel',
'xml': 'application/xml',
'xul': 'application/vnd.mozilla.xul+xml',
'zip': 'application/zip',
'3gp': 'video/3gpp',
'3g2': 'video/3gpp2',
'7z': 'application/x-7z-compressed',
};
for (var ext in MDN) {
var expected = MDN[ext];
var actual = mime.getType(ext);
if (actual !== expected) diffs.push(['MDN', ext, expected, actual]);
}
for (var ext in mimeTypes.types) {
var expected = mimeTypes.types[ext];
var actual = mime.getType(ext);
if (actual !== expected) diffs.push(['mime-types', ext, expected, actual]);
}
});
it('Specific types', function() {
// Assortment of types we sanity check for good measure
assert.equal(mime.getType('html'), 'text/html');
assert.equal(mime.getType('js'), 'application/javascript');
assert.equal(mime.getType('json'), 'application/json');
assert.equal(mime.getType('rtf'), 'application/rtf');
assert.equal(mime.getType('txt'), 'text/plain');
assert.equal(mime.getType('xml'), 'application/xml');
assert.equal(mime.getType('wasm'), 'application/wasm');
});
it('Specific extensions', function() {
assert.equal(mime.getExtension('text/html;charset=UTF-8'), 'html');
assert.equal(mime.getExtension('text/HTML; charset=UTF-8'), 'html');
assert.equal(mime.getExtension('text/html; charset=UTF-8'), 'html');
assert.equal(mime.getExtension('text/html; charset=UTF-8 '), 'html');
assert.equal(mime.getExtension('text/html ; charset=UTF-8'), 'html');
assert.equal(mime.getExtension(mime._types.text), 'txt');
assert.equal(mime.getExtension(mime._types.htm), 'html');
assert.equal(mime.getExtension('application/octet-stream'), 'bin');
assert.equal(mime.getExtension('application/octet-stream '), 'bin');
assert.equal(mime.getExtension(' text/html; charset=UTF-8'), 'html');
assert.equal(mime.getExtension('text/html; charset=UTF-8 '), 'html');
assert.equal(mime.getExtension('text/html; charset=UTF-8'), 'html');
assert.equal(mime.getExtension('text/html ; charset=UTF-8'), 'html');
assert.equal(mime.getExtension('text/html;charset=UTF-8'), 'html');
assert.equal(mime.getExtension('text/Html;charset=UTF-8'), 'html');
assert.equal(mime.getExtension('unrecognized'), null);
assert.equal(mime.getExtension('text/xml'), 'xml'); // See #180
});
});

File diff suppressed because one or more lines are too long