Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested improvement to the charset API #52

Closed
tyler-johnson opened this issue Feb 10, 2013 · 3 comments
Closed

Suggested improvement to the charset API #52

tyler-johnson opened this issue Feb 10, 2013 · 3 comments

Comments

@tyler-johnson
Copy link

First off, thanks for the mime library. It's so simple and exactly what I need every time.

Recently, I've been working on a project that uses character sets base on custom mime types. This is similar to the API I have been using and I would like to suggest it as an addition to this library.

mime.charsets.lookup(mime, fallback)

Same as current implementation in terms of arguments and what it returns. Like Apache's AddDefaultCharset, this should return "UTF-8" if and only if mime is either text/plain or text/html. This, however, is only for the sake of convention.

mime.charsets.lookup("text/plain") -> "UTF-8"
mime.charsets.lookup("image/png") -> fallback or undefined

mime.charsets.define(obj)

The keys of obj are mime types and values of obj are charsets. Unlike mime.define(), values must be a String, not an Array. Previously declared mime types should be overridden.

mime.charsets.define({
    "application/x-my-type": "UTF-16"
})
mime.charsets.lookup("application/x-my-type") -> "UTF-16"

mime.charsets.add(mime, charset)

Sets a charset based on the mime. Not in the spirit node-mime however this is an attempt to (somewhat) follow Apache's addCharset. This is obviously optional as mime.charsets.define(obj) duplicates this functionality.

mime.charsets.add("application/x-my-type", "UTF-16")
mime.charsets.lookup("application/x-my-type") -> "UTF-16"

Additionally, one could easily replicate Apache's addCharset by running:

mime.charsets.add(mime.lookup("x-mt"), "UTF-16")

Notes

Internally, node-mime should hold an Object of mime types pointing to a specific charset. Node-mime should also set mime.default_charset to 'UTF-8'. Whether or not this is the default for all mimes starting in text/* or just text/plain and text/html is up to you.

If you have neither the time nor the will, I would be happy to whip up a simple implementation and submit a pull-request.

@Baggz
Copy link

Baggz commented Mar 5, 2013

👍

1 similar comment
@Almad
Copy link

Almad commented Mar 5, 2013

👍

@broofa
Copy link
Owner

broofa commented Jul 25, 2013

Closing - see #56

@broofa broofa closed this as completed Jul 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants