
Research
/Security News
npm Author Qix Compromised via Phishing Email in Major Supply Chain Attack
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
mime-db-lite
Advanced tools
A tiny, lightweight JavaScript API to query mime-db (Media-type / MIME-type database).
A tiny, lightweight, portable JavaScript module to query the complete mime-db (a popular Media-type / MIME-type / Content-type database). Data is actually sourced from mime-db-cdn, which mirrors mime-db with added features.
🚀 Consumes less run-time memory by fetching data as and when needed, with optional caching. Ideal for low footprint applications.
🚀 Cross-platform: Runs on browsers, server-side (e.g. NodeJS) or serverless (e.g. Cloudflare Workers V8 isolates).
🚀 Standard: ESM.
🚀 Promise-based; exports async
methods.
🚀 Accepts custom fetch()
method, if any.
import
For browsers:
<script type="module">
import DB from 'https://cdn.jsdelivr.net/npm/mime-db-lite@2.0.0/index.min.js';
// Above, replace 2.0.0 with the actual version you'd be using, or use 'latest'
// Your code here ...
</script>
For Node.js:
Install as
npm install mime-db-lite
Import as
import DB from 'mime-db-lite';
fetch()
and LRU cacheCreate an instance of the imported DB class to use the fetch() API provided by the runtime and forgo caching.
👉 For browsers, the native fetch()
will still use the HTTP-cache.
const db = new DB();
To use an in-memory cache, instantiate as:
const db = new DB({ cacheMaxEntries: <Integer> });
<Integer>
denotes the maximum number of entries the cache can store, beyond which the LRU entries will be evicted to make just enough space.
👉 Using an LRU cache claims more run-time memory in return for faster lookups. For browsers this may be unnecessary, because browser-native fetch()
already uses HTTP-cache by default.
To use a custom fetch()
method, e.g. async function custFetch (url) { ... }
, instantiate as:
const db = new DB({ fetch: custFetch });
or, use an arrow function
const db = new DB({
fetch: async (url) => {
// Your code here
}
});
db.mimeToExtensions(mimeType)
or its alias db.getExtensions(mimeType)
Returns a promise that fulfills with an array of file-extensions.
mimeType
String representing a MIME-type with structure:
type/subtype
type/subtype;parameter=value
👉 The returned promise is rejected with Not Found
error if the provided mimeType
is unavailable in mime-db.
Examples:
console.log(await db.mimeToExtensions('application/mp4'));
// Prints [ 'mp4', 'mpg4', 'mp4s', 'm4p' ]
console.log(await db.getExtensions('application/javascript; charset=utf-8'));
// Prints [ 'js' ]
db.extensionToMimes(extension)
or its alias db.getTypes(extension)
Returns a promise that fulfills with an array of MIME-types. Note that this array of MIME-types is sorted in descending order of importance according to the same logic used by mime-types. If only one MIME-type is required, simply choose the first element from the array, or use the db.getType()
method.
extension
String representing either of
dir/subdir/file.ext
mp4
, .mp4
file.mp4
, file.version.1.2.0.mp4
👉 The returned promise is rejected with Not Found
error if the provided mimeType
is unavailable in mime-db.
Examples:
console.log(await db.extensionToMimes('dir/subdir/path.version.js'));
console.log(await db.getTypes('js'));
console.log(await db.getTypes('.js'));
// Prints [ 'application/javascript', 'text/javascript' ]
db.extensionToMime(extension)
or its alias db.getType(extension)
Same as db.getTypes()
above but the returned promise resolves with only a single MIME-type instead of an array. The returned MIME-type has the highest score according to the logic used by mime-types.
Examples:
console.log(await db.getType('.deb'));
// Prints 'application/x-debian-package'
db.query(mimeType)
Returns a promise that fulfills with the mime-db data object for the provided MIME-type.
mimeType
String representing a MIME-type in the form: type/subtype
👉 The returned promise is rejected with Not Found
error if the provided mimeType
is unavailable in mime-db.
Examples:
console.log(JSON.stringify(await db.query('application/javascript')));
// Prints '{"source":"apache","charset":"UTF-8","compressible":true,"extensions":["js"]}'
DB.mimeDbCdnVersion
A constant that stores the mime-db-cdn release version data is fetched from.
DB.cdnBase
A constant that stores the CDN via which data is accessed.
To register new media types in the database, contribute directly to mime-db.
If you like this project, you can show your appreciation by
Thank you 💚.
FAQs
A tiny, lightweight JavaScript API to query mime-db (Media-type / MIME-type database).
The npm package mime-db-lite receives a total of 3 weekly downloads. As such, mime-db-lite popularity was classified as not popular.
We found that mime-db-lite demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.