All files / mime_type.ts

100.00% Branches 2/2
100.00% Lines 51/51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
x1
 
x5
 
x5
x5
x5
x5
x7
x7
 
x5
x5
x7
x7
x5
 
x5
x5
x5
x14
x14
x14
x14
x14
 
x5
x5
x11
x11
 
x5
x7
x7
 
x5
 
x14
x14
x17
x17
 
x14
x16
x16
 
x14
 
x14
x14
x17
x17
 
x14
x16
x16
 
x5
 
x5
x5
x5
x6
x6
x5






























































// Imports
import type { Nullable } from "@libs/typing"
import { type _MimeType, type _MimeTypeArray, illegal, Indexable, internal, unimplemented } from "./_.ts"

/** https://developer.mozilla.org/en-US/docs/Web/API/MimeTypeArray */
export class MimeTypeArray extends Indexable<MimeType> implements _MimeTypeArray {
  // https://developer.mozilla.org/en-US/docs/Web/API/MimeTypeArray/item
  item(index: number): Nullable<MimeType> {
    return this[index] ?? null
  }

  // https://developer.mozilla.org/en-US/docs/Web/API/MimeTypeArray/namedItem
  namedItem(name: string): Nullable<MimeType> {
    return this[internal].find((mimeType) => mimeType.type === name) ?? null
  }
}

/** https://developer.mozilla.org/en-US/docs/Web/API/MimeType */
export class MimeType implements _MimeType {
  constructor({ type, description, suffixes } = {} as { [internal]?: boolean; type?: string; description?: string; suffixes?: string }) {
    illegal(arguments)
    this.#type = type!
    this.#description = description!
    this.#suffixes = suffixes!
  }

  // https://developer.mozilla.org/en-US/docs/Web/API/MimeType/type
  get type(): string {
    return this.#type
  }

  set type(_: string) {
    return
  }

  readonly #type

  // https://developer.mozilla.org/en-US/docs/Web/API/MimeType/description
  get description(): string {
    return this.#description
  }

  set description(_: string) {
    return
  }

  readonly #description

  // https://developer.mozilla.org/en-US/docs/Web/API/MimeType/suffixes
  get suffixes(): string {
    return this.#suffixes
  }

  set suffixes(_: string) {
    return
  }

  readonly #suffixes

  // https://developer.mozilla.org/en-US/docs/Web/API/MimeType/enabledPlugin
  // Depends: Plugin implementation
  get enabledPlugin(): Plugin {
    return unimplemented.getter<"immutable">()
  }
}