All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.serpro69.kfaker.provider.Internet.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0-rc.7
Show newest version
package io.github.serpro69.kfaker.provider

import io.github.serpro69.kfaker.*
import io.github.serpro69.kfaker.dictionary.*
import io.github.serpro69.kfaker.provider.unique.LocalUniqueDataProvider
import io.github.serpro69.kfaker.provider.unique.UniqueProviderDelegate

/**
 * [FakeDataProvider] implementation for [YamlCategory.INTERNET] category.
 */
@Suppress("unused")
class Internet internal constructor(fakerService: FakerService) : YamlFakeDataProvider(fakerService) {
    override val yamlCategory = YamlCategory.INTERNET
    override val localUniqueDataProvider = LocalUniqueDataProvider()
    override val unique by UniqueProviderDelegate(localUniqueDataProvider)

    init {
        fakerService.load(yamlCategory)
    }

    fun domain() = resolve("free_email")

    @JvmOverloads
    fun email(name: String = ""): String {
        val localName = if (name.trim() == "") {
            fakerService.faker.name.name()
                .replace(".", "")
                .replace(" ", ".")
                .lowercase()
        } else name.replace(" ", "")

        return "$localName@${domain()}"
    }

    @JvmOverloads
    fun safeEmail(name: String = "") = "${email(name).substringBeforeLast(".")}.test"

    fun slug(): String = resolve("slug")

    fun domainSuffix(): String = resolve("domain_suffix")
    fun userAgent(browserType: String): String = resolve("user_agent", browserType.lowercase())
    fun botUserAgent(type: String): String = resolve("bot_user_agent", type.lowercase())
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy