Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: broofa/mime
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.4.7
Choose a base ref
...
head repository: broofa/mime
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.5.0
Choose a head ref
  • 4 commits
  • 14 files changed
  • 2 contributors

Commits on Jan 16, 2021

  1. feat: improved CLI (#244)

    * Added in version flag and name flag
    
    * Improved CLI
    Yash-Singh1 authored and broofa committed Jan 16, 2021
    Copy the full SHA
    c8a8356 View commit details
  2. Copy the full SHA
    4a548b7 View commit details
  3. Cli tests (#252)

    * chore: downgrade to mocha@7 for node 8 testing
    
    * chore: CLI test
    
    * chore: eslint
    
    * chore: switch to github actions for CI
    broofa committed Jan 16, 2021
    Copy the full SHA
    082342e View commit details
  4. chore(release): 2.5.0

    broofa committed Jan 16, 2021
    Copy the full SHA
    c95d7ab View commit details
Showing with 545 additions and 249 deletions.
  1. +2 −0 .eslintrc.json
  2. +23 −0 .github/workflows/ci.yml
  3. +0 −6 .travis.yml
  4. +7 −0 CHANGELOG.md
  5. +14 −12 Mime.js
  6. +39 −3 cli.js
  7. +1 −1 index.js
  8. +1 −1 lite.js
  9. +7 −0 mime.code-workspace
  10. +395 −186 package-lock.json
  11. +2 −2 package.json
  12. +2 −0 src/benchmark.js
  13. +20 −18 src/build.js
  14. +32 −20 src/test.js
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
"node": true,
"mocha": true
},
"ignorePatterns": ["types/"],
"extends": ["eslint:recommended"],
"rules": {
"array-bracket-spacing": ["warn", "never"],
@@ -37,6 +38,7 @@
"no-undef": "error",
"no-unused-vars": ["warn", {"args": "none"}],
"one-var": ["warn", "never"],
"no-var": "warn",
"padded-blocks": ["warn", "never"],
"object-curly-spacing": ["warn", "never"],
"quotes": ["warn", "single"],
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Mime CI

on:
[push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [8.x, 10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,13 @@

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.

## [2.5.0](https://github.com/broofa/mime/compare/v2.4.7...v2.5.0) (2021-01-16)


### Features

* improved CLI ([#244](https://github.com/broofa/mime/issues/244)) ([c8a8356](https://github.com/broofa/mime/commit/c8a8356e3b27f3ef46b64b89b428fdb547b14d5f))

### [2.4.7](https://github.com/broofa/mime/compare/v2.4.6...v2.4.7) (2020-12-16)


26 changes: 14 additions & 12 deletions Mime.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ function Mime() {
this._types = Object.create(null);
this._extensions = Object.create(null);

for (var i = 0; i < arguments.length; i++) {
for (let i = 0; i < arguments.length; i++) {
this.define(arguments[i]);
}

@@ -37,16 +37,18 @@ function Mime() {
* @param force (Boolean) if true, force overriding of existing definitions
*/
Mime.prototype.define = function(typeMap, force) {
for (var type in typeMap) {
var extensions = typeMap[type].map(function(t) {return t.toLowerCase()});
for (let type in typeMap) {
let extensions = typeMap[type].map(function(t) {
return t.toLowerCase();
});
type = type.toLowerCase();

for (var i = 0; i < extensions.length; i++) {
var ext = extensions[i];
for (let i = 0; i < extensions.length; i++) {
const ext = extensions[i];

// '*' prefix = not the preferred type for this extension. So fixup the
// extension, and skip it.
if (ext[0] == '*') {
if (ext[0] === '*') {
continue;
}

@@ -64,8 +66,8 @@ Mime.prototype.define = function(typeMap, force) {

// Use first extension as default
if (force || !this._extensions[type]) {
var ext = extensions[0];
this._extensions[type] = (ext[0] != '*') ? ext : ext.substr(1)
const ext = extensions[0];
this._extensions[type] = (ext[0] !== '*') ? ext : ext.substr(1);
}
}
};
@@ -75,11 +77,11 @@ Mime.prototype.define = function(typeMap, force) {
*/
Mime.prototype.getType = function(path) {
path = String(path);
var last = path.replace(/^.*[/\\]/, '').toLowerCase();
var ext = last.replace(/^.*\./, '').toLowerCase();
let last = path.replace(/^.*[/\\]/, '').toLowerCase();
let ext = last.replace(/^.*\./, '').toLowerCase();

var hasPath = last.length < path.length;
var hasDot = ext.length < last.length - 1;
let hasPath = last.length < path.length;
let hasDot = ext.length < last.length - 1;

return (hasDot || !hasPath) && this._types[ext] || null;
};
42 changes: 39 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
@@ -2,9 +2,45 @@

'use strict';

var mime = require('.');
var file = process.argv[2];
var type = mime.getType(file);
process.title = 'mime';
let mime = require('.');
let pkg = require('./package.json');
let args = process.argv.splice(2);

if (args.includes('--version') || args.includes('-v') || args.includes('--v')) {
console.log(pkg.version);
process.exit(0);
} else if (args.includes('--name') || args.includes('-n') || args.includes('--n')) {
console.log(pkg.name);
process.exit(0);
} else if (args.includes('--help') || args.includes('-h') || args.includes('--h')) {
console.log(pkg.name + ' - ' + pkg.description + '\n');
console.log(`Usage:
mime [flags] [path_or_extension]
Flags:
--help, -h Show this message
--version, -v Display the version
--name, -n Print the name of the program
Note: the command will exit after it executes if a command is specified
The path_or_extension is the path to the file or the extension of the file.
Examples:
mime --help
mime --version
mime --name
mime -v
mime src/log.js
mime new.py
mime foo.sh
`);
process.exit(0);
}

let file = args[0];
let type = mime.getType(file);

process.stdout.write(type + '\n');

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

var Mime = require('./Mime');
let Mime = require('./Mime');
module.exports = new Mime(require('./types/standard'), require('./types/other'));
2 changes: 1 addition & 1 deletion lite.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

var Mime = require('./Mime');
let Mime = require('./Mime');
module.exports = new Mime(require('./types/standard'));
7 changes: 7 additions & 0 deletions mime.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": "."
}
]
}
Loading