mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-11-11 01:20:31 +00:00
experimentally add linuxx64 and mingwx64 as target platforms
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package dev.inmo.micro_utils.mime_types
|
||||
|
||||
val mimeTypesByExtensions: Map<String, Array<MimeType>> by lazy {
|
||||
val extensionsMap = mutableMapOf<String, MutableList<MimeType>>()
|
||||
|
||||
knownMimeTypes.forEach { mimeType ->
|
||||
mimeType.extensions.forEach {
|
||||
extensionsMap.getOrPut(it) { mutableListOf() }.add(mimeType)
|
||||
}
|
||||
}
|
||||
|
||||
extensionsMap.mapValues {
|
||||
it.value.toTypedArray()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun getMimeType(
|
||||
stringWithExtension: String,
|
||||
selector: (Array<MimeType>) -> MimeType? = { it.firstOrNull() }
|
||||
) = mimeTypesByExtensions[stringWithExtension.takeLastWhile { it != '.' }] ?.takeIf { it.isNotEmpty() } ?.let(selector)
|
||||
inline fun getMimeTypeOrAny(
|
||||
stringWithExtension: String,
|
||||
selector: (Array<MimeType>) -> MimeType? = { it.firstOrNull() }
|
||||
) = getMimeType(stringWithExtension, selector) ?: KnownMimeTypes.Any
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,4 +5,6 @@ import kotlinx.serialization.Serializable
|
||||
@Serializable(MimeTypeSerializer::class)
|
||||
interface MimeType {
|
||||
val raw: String
|
||||
val extensions: Array<String>
|
||||
get() = emptyArray()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user