@robinpath/mime
0.1.2Node.jsPublicMIME type detection from extensions and file content, type classification, Content-Type building
Mime
MIME type detection from extensions and file content, type classification, Content-Type building
Package: @robinpath/mime | Category: Utility | Type: Utility
Authentication
No authentication required. All functions are available immediately.
Use Cases
Use the mime module when you need to:
- Get MIME type from file extension -- Use
mime.lookupto perform this operation - Get extension from MIME type -- Use
mime.extensionto perform this operation - Detect MIME type from file content (magic bytes) -- Use
mime.detectto perform this operation - Get charset for MIME type -- Use
mime.charsetto perform this operation - Check if MIME type is text-based -- Use
mime.isTextto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
lookup | Get MIME type from file extension | MIME type or null |
extension | Get extension from MIME type | Extension or null |
detect | Detect MIME type from file content (magic bytes) | Detected MIME type |
charset | Get charset for MIME type | UTF-8 or null |
isText | Check if MIME type is text-based | true if text |
isImage | Check if MIME type is image | true if image |
isAudio | Check if MIME type is audio | true if audio |
isVideo | Check if MIME type is video | true if video |
isFont | Check if MIME type is font | true if font |
isArchive | Check if MIME type is archive | true if archive |
contentType | Build Content-Type header with charset | Content-Type header value |
allTypes | Get all known MIME type mappings | Extension-to-MIME map |
Functions
lookup
Get MIME type from file extension
Module: mime | Returns: string -- MIME type or null
mime.lookup "photo.png"
| Parameter | Type | Required | Description |
|---|---|---|---|
pathOrExt | string | Yes | File path or extension |
extension
Get extension from MIME type
Module: mime | Returns: string -- Extension or null
mime.extension "image/png"
| Parameter | Type | Required | Description |
|---|---|---|---|
mimeType | string | Yes | MIME type |
detect
Detect MIME type from file content (magic bytes)
Module: mime | Returns: string -- Detected MIME type
mime.detect "./unknown_file"
| Parameter | Type | Required | Description |
|---|---|---|---|
filePath | string | Yes | File path |
charset
Get charset for MIME type
Module: mime | Returns: string -- UTF-8 or null
mime.charset "text/html"
| Parameter | Type | Required | Description |
|---|---|---|---|
mimeType | string | Yes | MIME type |
isText
Check if MIME type is text-based
Module: mime | Returns: boolean -- true if text
mime.isText "application/json"
| Parameter | Type | Required | Description |
|---|---|---|---|
mimeType | string | Yes | MIME type |
isImage
Check if MIME type is image
Module: mime | Returns: boolean -- true if image
mime.isImage "image/png"
| Parameter | Type | Required | Description |
|---|---|---|---|
mimeType | string | Yes | MIME type |
isAudio
Check if MIME type is audio
Module: mime | Returns: boolean -- true if audio
mime.isAudio "audio/mpeg"
| Parameter | Type | Required | Description |
|---|---|---|---|
mimeType | string | Yes | MIME type |
isVideo
Check if MIME type is video
Module: mime | Returns: boolean -- true if video
mime.isVideo "video/mp4"
| Parameter | Type | Required | Description |
|---|---|---|---|
mimeType | string | Yes | MIME type |
isFont
Check if MIME type is font
Module: mime | Returns: boolean -- true if font
mime.isFont "font/woff2"
| Parameter | Type | Required | Description |
|---|---|---|---|
mimeType | string | Yes | MIME type |
isArchive
Check if MIME type is archive
Module: mime | Returns: boolean -- true if archive
mime.isArchive "application/zip"
| Parameter | Type | Required | Description |
|---|---|---|---|
mimeType | string | Yes | MIME type |
contentType
Build Content-Type header with charset
Module: mime | Returns: string -- Content-Type header value
mime.contentType "index.html"
| Parameter | Type | Required | Description |
|---|---|---|---|
pathOrExt | string | Yes | File path or extension |
allTypes
Get all known MIME type mappings
Module: mime | Returns: object -- Extension-to-MIME map
mime.allTypes
| Parameter | Type | Required | Description |
|---|---|---|---|
| (none) | No | Call with no arguments |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
| (standard errors) | Check function parameters and authentication |
@desc "Lookup and validate result"
do
set $result as mime.lookup "photo.png"
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. Multi-step Mime workflow
Chain multiple mime operations together.
@desc "Lookup, extension, and more"
do
set $r_lookup as mime.lookup "photo.png"
set $r_extension as mime.extension "image/png"
set $r_detect as mime.detect "./unknown_file"
print "All operations complete"
enddo
2. Safe lookup with validation
Check results before proceeding.
@desc "Lookup and validate result"
do
set $result as mime.lookup "photo.png"
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- json -- JSON module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.2 | latest | 1 months ago |
Related Modules
@robinpathv0.1.4
SMTP email sending and address parsing for RobinPath
hash
JS@robinpathv0.1.3
Cryptographic hashing utilities: MD5, SHA family, HMAC, CRC32, file hashing, UUID v5 generation, secure random bytes, and content fingerprinting
csv
JS@robinpathv0.1.2
Parse and stringify CSV data
apollo
JS@robinpathv0.1.2
Apollo module for RobinPath.
$ robinpath add @robinpath/mime
