lukeed / lukeed/mrmime

`charset` function

Open
#2 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
346
Forks
9
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the linked mime-types implementation and inspect mrmime's existing exports and tests to find the appropriate entry point. Add the requested charset function with the shown handling for invalid input, MIME database matches, and text/* defaults, then verify its behavior alongside the existing utility tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.