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

charset function #2

Open
talentlessguy opened this issue Oct 23, 2021 · 0 comments
Open

charset function #2

talentlessguy opened this issue Oct 23, 2021 · 0 comments

Comments

@talentlessguy
Copy link

talentlessguy commented Oct 23, 2021

Would be cool to have a charset function from mime-types:

const EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/
const TEXT_TYPE_REGEXP = /^text\//i

export function charset (type) {
  if (!type || typeof type !== 'string') return false
  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
}

https://github.com/jshttp/mime-types/blob/c6ff9b224577f0cd49f1155f421b24c24a57bc3e/index.js#L49-L68

thiagotognoli pushed a commit to thiagotognoli/mrmime-2way that referenced this issue Apr 20, 2024
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

1 participant