0.1.1 • Published 1 year ago

@dashkite/media-type v0.1.1

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
1 year ago

Media Type

Parse HTTP media types.

import assert from "@dashkite/assert"
import { MediaType, Accept } from "@dashkite/media-type"

description = MediaType.parse "text/html; charset=utf-8"

assert.deepEqual description,
  type: "text"
  subtype: "html"
  parameters:
    charset: "utf-8"

description = MediaType.parse "application/atom+xml; q=0.5"

assert.deepEqual description,
  type: "application"
  subtype: "atom+xml"
  parameters: q: "0.5"
  mime:
    base: "atom"
    suffix: "xml"
    type: "application"
    subtype: "xml"

select = Accept.selector "text/*;q=0.3, text/html;q=0.7, text/html;level=1,
  text/html;level=2;q=0.4, */*;q=0.5"

assert.deepEqual select "text/html",
  type: 'text'
  subtype: 'html'
  parameters:
    q: '0.7'
0.1.1

1 year ago

0.1.0

2 years ago