Skip to content

mah0x211/lua-mediatypes

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
January 14, 2022 12:10
lib
September 1, 2015 08:05
January 14, 2022 12:15
January 14, 2022 12:10
January 14, 2022 12:10
January 14, 2022 12:10
January 14, 2022 12:10

lua-mediatypes

test Coverage Status

MIME type utility module.

Installation

luarocks install mediatypes

Creating a MediaTypes Object

mt = mediatypes.new( [mimetypes] )

Parameters

  • mimetypes:string: mime types definition string. (default: mediatype.default)

Returns

  1. mt:table: mediatypes object

Example

local MediaTypes = require('mediatypes');
local mt = MediaTypes.new([[
    my/mimetype     my myfile;    # this is my example mime type definition
]]);

Methods

mt:read( mimetypes )

add new mime types from a mime types definition string.

Parameters

  • mimetypes:string: mime string.

Example

mt:read([[
# JavaScript
application/javascript js;
application/json json;
]]);

mime = mt:getmime( ext )

returns a MIME type string associated with ext argument.

Parameters

  • ext:string: extension string.

Returns

  • mime:string: mime type string or nil.

Example

print( mt:getmime('my') ); -- 'my/mimetype'
print( mt:getmime('myfile') ); -- 'my/mimetype'

exts = mt:getexts( mime )

returns a extension strings table associated with mime argument.

Parameters

  • mime:string: mime string.

Returns

  • exts:table: extension strings table or nil.

Example

--[[ output
1	my
2	myfile
--]]
for i, ext in ipairs( mt:getExt('my/mimetype') ) do
    print( i, ext );
end

About

MIME type utility module

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages