import type { IObjectOf } from "@thi.ng/api" ; import { DB } from "./generated.js" ; export const MIME_TYPES = ( ( defs ) => { const res = { } ; for ( let groupID in defs ) { const group = defs [ groupID ] ; for ( let type in group ) { const mime = groupID + "/" + type ; for ( let e of group [ type ] . split ( "," ) ) { const isLowPri = e [ 0 ] === "*" ; const ext = isLowPri ? e . substr ( 1 ) : e ; let coll = res [ ext ] ; ! coll && ( coll = res [ ext ] = [ ] ) ; isLowPri ? coll . push ( mime ) : coll . unshift ( mime ) ; } } } return res ; } ) ( DB ) ; remarks Since v0.2.0 the extension can be given as either `".ext"` or `"ext"`.
 * Previously, only the latter was supported.
 *
 * Also see  preferredExtension for reverse operation.
 *
 *  param ext param fallback export const preferredType = ( ext , fallback = MIME_TYPES . bin [ 0 ] ) => { const type = MIME_TYPES [ ext [ 0 ] === "." ? ext . substr ( 1 ) : ext ] ; return type ? type [ 0 ] : fallback ; } ; /**
 * Reverse lookup to  preferredType . Takes MIME type string and returns
 * preferred file extension (or failing that) returns `fallback` (default:
 * "bin").
 *
 *  param mime param fallback returns export const preferredExtension = ( mime , fallback = "bin" ) => { const [ prefix , suffix ] = mime . split ( "/" ) ; const group = DB [ prefix ] ; const ext = group ? group [ suffix ] . split ( "," ) : undefined ; return ext ? ext . find ( ( x ) => x [ 0 ] !== "*" ) || ext [ 0 ] . substr ( 1 ) : fallback ; } ;