Skip to content

charset function #2

@v1rtl

Description

@v1rtl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions