Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es-mime-types

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-mime-types - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

dist/index.cjs

284

dist/index.js

@@ -1,131 +0,36 @@

'use strict';
import db from 'mime-db';
import { extname } from 'path';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var db = _interopDefault(require('mime-db'));
var path = require('path');
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _createForOfIteratorHelper(o, allowArrayLike) {
var it;
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
var F = function () {};
return {
s: F,
n: function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
},
e: function (e) {
throw e;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var normalCompletion = true,
didErr = false,
err;
return {
s: function () {
it = o[Symbol.iterator]();
},
n: function () {
var step = it.next();
normalCompletion = step.done;
return step;
},
e: function (e) {
didErr = true;
err = e;
},
f: function () {
try {
if (!normalCompletion && it.return != null) it.return();
} finally {
if (didErr) throw err;
}
}
};
}
var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
var TEXT_TYPE_REGEXP = /^text\//i;
const EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
const TEXT_TYPE_REGEXP = /^text\//i;
function populateMaps(extensions, types) {
// source preference (least -> most)
var preference = ['nginx', 'apache', undefined, 'iana'];
Object.keys(db).forEach(function (type) {
var mime = db[type];
var exts = mime.extensions;
if (!exts || !exts.length) {
return;
} // mime -> extensions
extensions[type] = exts; // extension -> mime
var _iterator = _createForOfIteratorHelper(exts),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _extension = _step.value;
if (types[_extension]) {
var from = preference.indexOf(db[types[_extension]].source);
var to = preference.indexOf(mime.source);
if (types[_extension] !== 'application/octet-stream' && (from > to || from === to && types[_extension].substr(0, 12) === 'application/')) {
// skip the remapping
continue;
}
} // set the extension -> mime
types[_extension] = type;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
});
// source preference (least -> most)
const preference = ['nginx', 'apache', undefined, 'iana'];
Object.keys(db).forEach((type) => {
const mime = db[type];
const exts = mime.extensions;
if (!exts || !exts.length) {
return;
}
// mime -> extensions
extensions[type] = exts;
// extension -> mime
for (const extension of exts) {
if (types[extension]) {
const from = preference.indexOf(db[types[extension]].source);
const to = preference.indexOf(mime.source);
if (types[extension] !== 'application/octet-stream' &&
(from > to ||
(from === to && types[extension].substr(0, 12) === 'application/'))) {
// skip the remapping
continue;
}
}
// set the extension -> mime
types[extension] = type;
}
});
}
var extensions = Object.create(null);
var types = Object.create(null);
const extensions = Object.create(null);
const types = Object.create(null);
populateMaps(extensions, types);

@@ -135,22 +40,17 @@ /**

*/
function charset(type) {
if (!type || typeof type !== 'string') {
if (!type || typeof type !== 'string') {
return false;
}
// TODO: use media-typer
const match = EXTRACT_TYPE_REGEXP.exec(type);
const mime = match && db[match[1].toLowerCase()];
if (mime && mime.charset) {
return mime.charset;
}
// default text/* to utf-8
if (match && TEXT_TYPE_REGEXP.test(match[1])) {
return 'UTF-8';
}
return false;
} // TODO: use media-typer
var match = EXTRACT_TYPE_REGEXP.exec(type);
var mime = match && db[match[1].toLowerCase()];
if (mime && mime.charset) {
return mime.charset;
} // default text/* to utf-8
if (match && TEXT_TYPE_REGEXP.test(match[1])) {
return 'UTF-8';
}
return false;
}

@@ -160,23 +60,18 @@ /**

*/
function contentType(str) {
// TODO: should this even be in this module?
if (!str || typeof str !== 'string') {
return false;
}
var mime = str.indexOf('/') === -1 ? exports.lookup(str) : str;
if (!mime) {
return false;
} // TODO: use content-type or other module
if (mime.indexOf('charset') === -1) {
var _charset = exports.charset(mime);
if (_charset) mime += '; charset=' + _charset.toLowerCase();
}
return mime;
// TODO: should this even be in this module?
if (!str || typeof str !== 'string') {
return false;
}
let mime = str.indexOf('/') === -1 ? exports.lookup(str) : str;
if (!mime) {
return false;
}
// TODO: use content-type or other module
if (mime.indexOf('charset') === -1) {
const charset = exports.charset(mime);
if (charset)
mime += '; charset=' + charset.toLowerCase();
}
return mime;
}

@@ -186,18 +81,14 @@ /**

*/
function extension(type) {
if (!type || typeof type !== 'string') {
return false;
} // TODO: use media-typer
var match = EXTRACT_TYPE_REGEXP.exec(type); // get extensions
var exts = match && exports.extensions[match[1].toLowerCase()];
if (!exts || !exts.length) {
return false;
}
return exts[0];
if (!type || typeof type !== 'string') {
return false;
}
// TODO: use media-typer
const match = EXTRACT_TYPE_REGEXP.exec(type);
// get extensions
const exts = match && exports.extensions[match[1].toLowerCase()];
if (!exts || !exts.length) {
return false;
}
return exts[0];
}

@@ -207,23 +98,16 @@ /**

*/
function lookup(path$1) {
if (!path$1 || typeof path$1 !== 'string') {
return false;
} // get the extension ("ext" or ".ext" or full path)
var extension = path.extname('x.' + path$1).toLowerCase().substr(1);
if (!extension) {
return false;
}
return exports.types[extension] || false;
function lookup(path) {
if (!path || typeof path !== 'string') {
return false;
}
// get the extension ("ext" or ".ext" or full path)
const extension = extname('x.' + path)
.toLowerCase()
.substr(1);
if (!extension) {
return false;
}
return exports.types[extension] || false;
}
exports.charset = charset;
exports.contentType = contentType;
exports.extension = extension;
exports.extensions = extensions;
exports.lookup = lookup;
exports.types = types;
export { charset, contentType, extension, extensions, lookup, types };
{
"name": "es-mime-types",
"description": "mime-types rewrite in TypeScript with ESM and CommonJS targets",
"version": "0.0.4",
"version": "0.0.5",
"repository": "https://github.com/talentlessguy/es-mime-types.git",

@@ -15,4 +15,5 @@ "engines": {

"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",

@@ -29,3 +30,4 @@ "exports": {

"@types/mime-db": "^1.43.0",
"bili": "^5.0.5",
"@types/node": "^14.0.22",
"rollup": "^2.21.0",
"rollup-plugin-typescript2": "^0.27.1",

@@ -35,3 +37,3 @@ "typescript": "^3.9.6"

"scripts": {
"build": "bili --format esm --format cjs src/index.ts"
"build": "rollup -c"
},

@@ -38,0 +40,0 @@ "dependencies": {

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