{"id":15437099,"url":"https://github.com/awwright/contenttype","last_synced_at":"2025-04-19T18:25:54.903Z","repository":{"id":7571468,"uuid":"8925856","full_name":"awwright/contenttype","owner":"awwright","description":"Javascript/ECMAScript library for parsing Content-Type and Media/MIME type strings","archived":false,"fork":false,"pushed_at":"2016-05-23T17:54:20.000Z","size":103,"stargazers_count":8,"open_issues_count":4,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T04:09:59.375Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/awwright.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-21T09:58:54.000Z","updated_at":"2016-10-08T04:17:02.000Z","dependencies_parsed_at":"2022-08-30T03:12:00.620Z","dependency_job_id":null,"html_url":"https://github.com/awwright/contenttype","commit_stats":null,"previous_names":["acubed/contenttype"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awwright%2Fcontenttype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awwright%2Fcontenttype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awwright%2Fcontenttype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awwright%2Fcontenttype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awwright","download_url":"https://codeload.github.com/awwright/contenttype/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249762605,"owners_count":21321964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T18:55:04.637Z","updated_at":"2025-04-19T18:25:54.887Z","avatar_url":"https://github.com/awwright.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Content-Type parsing\n\n## new MediaType(type, [parameters])\n\nThe MediaType represents a parsed Media Type. For use in HTTP, the first (but only the first) `q` parameter will be parsed as a float.\nOther parameters are available through the `params` object.\nThe first argument is the full media type, the second argument, if provided, is strictly a list of parameters.\n\nThe `toString` method converts the object back into a Media type.\n\n```javascript\nvar p = new MediaType('text/html;level=1;q=0.5');\np.q === 0.5;\np.params.level === \"1\"\n\nvar q = new MediaType('application/json', {profile: 'http://example.com/schema.json'});\nq.type === \"application/json\";\nq.params.profile === \"http://example.com/schema.json\";\n\nq.q = 1;\nq.toString() === 'application/json;q=1;profile=\"http://example.com/schema.json\"';\n```\n\n## parseMedia(type)\nReturns a new instance of MediaType.\n\n## splitQuotedString(str, delimiter, quote)\nSplits a string by a delimiter character (default: semicolon), ignoring quoted sections (default: double quote).\n\n\n## splitContentTypes(str)\nSplits an Accept (or similar) header into an Array of strings of content-types.\n\n```javascript\nsplitContentType('application/json, text/html').map(parseMedia)\n```\n\n## select(reps, accept)\nPick an ideal representation to send, given an Array of representations to choose from, and the client-preferred list as an Array.\n\nSee example.js for an example.\n\n## mediaCmp(a, b)\n\nAccepts two MediaType instances and tests them for being a subset/superset.\n\nIf a is a superset of b (b is smaller than a), return 1.\nIf b is a superset of a, return -1.\nIf they are the exact same, return 0.\nIf they are disjoint, return null.\n\nThe q-value, if any, is ignored.\n\n```javascript\nmediaCmp(parseMedia('text/html'), parseMedia('text/html')) === 0\nmediaCmp(parseMedia('*/*'), parseMedia('text/html')) === 1\nmediaCmp(parseMedia('text/html;level=1'), parseMedia('text/html')) === -1\nmediaCmp(parseMedia('application/json;profile=\"v1.json\"'), parseMedia('application/json;profile=\"v2.json\"')) === null\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawwright%2Fcontenttype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawwright%2Fcontenttype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawwright%2Fcontenttype/lists"}