diff --git a/packages/preview/tenv/0.1.1/LICENSE b/packages/preview/tenv/0.1.1/LICENSE new file mode 100644 index 000000000..c78060947 --- /dev/null +++ b/packages/preview/tenv/0.1.1/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 chillcicada <2210227279@qq.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/preview/tenv/0.1.1/README.md b/packages/preview/tenv/0.1.1/README.md new file mode 100644 index 000000000..7897ea3a9 --- /dev/null +++ b/packages/preview/tenv/0.1.1/README.md @@ -0,0 +1,15 @@ +# tenv + +Parse a .env content. + +## Usage + +```typ +#import "@preview/tenv.typ:0.1.1": parse_dotenv + +#let env = parse_dotenv(read(".env")) +``` + +## Example + +![Example](./example.png) diff --git a/packages/preview/tenv/0.1.1/example.png b/packages/preview/tenv/0.1.1/example.png new file mode 100644 index 000000000..e22cfe8e9 Binary files /dev/null and b/packages/preview/tenv/0.1.1/example.png differ diff --git a/packages/preview/tenv/0.1.1/lib.typ b/packages/preview/tenv/0.1.1/lib.typ new file mode 100644 index 000000000..33217528a --- /dev/null +++ b/packages/preview/tenv/0.1.1/lib.typ @@ -0,0 +1,27 @@ +#let parse_dotenv(ctx) = { + if type(ctx) == "content" { + ctx = ctx.text + } else if type(ctx) != "string" { + return ctx + } + + let arr = ctx.split(regex("#.*\r?\n?|\r?\n")).filter(it => it.trim() != "").map(line => { + let parts = line.split("=") + let key = parts.at(0).trim() + if (key != "") { + if (parts.len() > 1) { + (key, parts.at(1).trim()) + } else { + (key, "") + } + } + }).dedup() + + let obj = (:) + + for item in arr { + obj.insert(item.at(0), item.at(1)) + } + + obj +} diff --git a/packages/preview/tenv/0.1.1/typst.toml b/packages/preview/tenv/0.1.1/typst.toml new file mode 100644 index 000000000..c7bb0e7d9 --- /dev/null +++ b/packages/preview/tenv/0.1.1/typst.toml @@ -0,0 +1,11 @@ +[package] +name = "tenv" +version = "0.1.1" +entrypoint = "lib.typ" +authors = ["chillcicada"] +license = "MIT" +description = "Parse a .env content." +homepage = "https://github.com/chillcicada/typst-dotenv#readme" +repository = "https://github.com/chillcicada/typst-dotenv" +keywords = ["dotenv", "environment", "utility"] +exclude = ["example/*", ".*", "example.png"]