Socket
Socket
Sign inDemoInstall

mime

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mime - npm Package Compare versions

Comparing version 2.4.7 to 2.5.0

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [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)

@@ -7,0 +14,0 @@

42

cli.js

@@ -5,7 +5,43 @@ #!/usr/bin/env node

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

index.js
'use strict';
var Mime = require('./Mime');
let Mime = require('./Mime');
module.exports = new Mime(require('./types/standard'), require('./types/other'));
'use strict';
var Mime = require('./Mime');
let Mime = require('./Mime');
module.exports = new Mime(require('./types/standard'));

@@ -11,3 +11,3 @@ 'use strict';

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

@@ -41,12 +41,14 @@ }

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;

@@ -69,4 +71,4 @@ }

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);
}

@@ -81,7 +83,7 @@ }

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;

@@ -88,0 +90,0 @@ return (hasDot || !hasPath) && this._types[ext] || null;

@@ -24,3 +24,3 @@ {

"mime-types": "2.1.27",
"mocha": "8.2.1",
"mocha": "7.2.0",
"runmd": "*",

@@ -52,3 +52,3 @@ "standard-version": "9.0.0"

},
"version": "2.4.7"
"version": "2.5.0"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc