Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Add definitions for dotenv package #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added externals/dotenv/README.md
Empty file.
41 changes: 41 additions & 0 deletions externals/dotenv/_testShared/test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import js.externals.dotenv.Dotenv
import org.khronos.webgl.ArrayBuffer

fun configHasDefaultOptions() {
Dotenv.config()
}

fun configAcceptsCustomPath() {
Dotenv.config(object : Dotenv.DotenvOptions {
override val path = ".vne"
})
}

fun configAcceptsCustomEncoding() {
Dotenv.config(object : Dotenv.DotenvOptions {
override val encoding = "UTF-8"
})
}

fun loadCanForceReadingOfEnvFile() {
val env = Dotenv.config()

env.load()
}

fun variableCanBeRetrievedUsingGetOperation() {
val env = Dotenv.config()

check(env["KOTLIN_VERSION"] == "1.2")
}

fun parseCanExtractVariablesFromString() {
val env = Dotenv.parse("ONE=1\nTWO=2")

check(env["ONE"] == "1")
check(env["TWO"] == "2")
}

fun parseCanExtractVariablesFromBuffer() {
Dotenv.parse(ArrayBuffer(2))
}
3 changes: 3 additions & 0 deletions externals/dotenv/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"description": "dotenv"
}
3 changes: 3 additions & 0 deletions externals/dotenv/v5/konfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "5.0.1"
}
27 changes: 27 additions & 0 deletions externals/dotenv/v5/src/index.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package js.externals.dotenv

import org.khronos.webgl.BufferDataSource

external object Dotenv {

interface DotenvOptions {
val path: String?
get() = definedExternally

val encoding: String?
get() = definedExternally
}

interface DotenvResult {
operator fun get(name: String): String?

fun load()

}

fun config(options: DotenvOptions? = definedExternally): DotenvResult

fun parse(text: String): DotenvResult

fun parse(buffer: BufferDataSource): DotenvResult
}