@kentrino/dotenvx-lite
v0.2.0
Published
Parse .env files and decrypt dotenvx encrypted: values.
Maintainers
Readme
@kentrino/dotenvx-lite
Parse .env files and decrypt dotenvx encrypted: values.
Installation
pnpm add @kentrino/dotenvx-lite
# or
npm install @kentrino/dotenvx-liteUsage
import {
DecryptError,
decrypt,
decryptEnv,
isDotenvPublicKey,
isEncrypted,
parseEnv,
} from "@kentrino/dotenvx-lite";
const parsed = parseEnv(source);
const env = decryptEnv(parsed, privateKey);
if (isDotenvPublicKey(key)) {
// DOTENV_PUBLIC_KEY or DOTENV_PUBLIC_KEY_*
}
if (isEncrypted(value)) {
const plain = decrypt(value, privateKey);
}
try {
decrypt(value, privateKey);
} catch (error) {
if (error instanceof DecryptError) {
console.error(error.code);
}
}parseEnv(src)parses.envtext into aRecord<string, string>while keepingencrypted:ciphertexts intact.decrypt(value, privateKey)decryptsencrypted:values (supporting comma-separated private keys) and returns plaintext values unchanged.decryptEnv(parsed, privateKey, options?)decrypts all entries and omitsDOTENV_PUBLIC_KEY/DOTENV_PUBLIC_KEY_*keys by default (pass{ omitPublicKeys: false }to retain them).isEncrypted(value)checks whether a string starts withencrypted:.isDotenvPublicKey(key)checks whether a key isDOTENV_PUBLIC_KEYorDOTENV_PUBLIC_KEY_*.
Browser usage
The default entrypoint uses Node.js built-in node:crypto with zero runtime dependencies. For browser environments, install the optional peer dependency eciesjs and import from @kentrino/dotenvx-lite/browser:
pnpm add @kentrino/dotenvx-lite eciesjsimport { decrypt, decryptEnv, parseEnv } from "@kentrino/dotenvx-lite/browser";Development
Requires Node.js >= 22.18.0 and pnpm 11.20.0.
pnpm install
vp run readyready runs check, test, and build in sequence.
License
MIT. Portions are adapted from motdotla/dotenv (BSD-2-Clause) and dotenvx/dotenvx (BSD-3-Clause); see THIRD_PARTY_NOTICES.md.
