🛠️ToolsShed

Analizador de .env

Analiza archivos .env y muestra las variables como tabla o las convierte a JSON.

Preguntas Frecuentes

Implementación de Código

def parse_env(text: str) -> dict:
    result = {}
    for line in text.splitlines():
        line = line.strip()
        if not line or line.startswith("#"):
            continue
        eq = line.find("=")
        if eq == -1:
            continue
        key = line[:eq].strip()
        value = line[eq+1:].strip()
        # Strip surrounding quotes
        if len(value) >= 2 and value[0] == value[-1] and value[0] in ('"', "'"):
            value = value[1:-1]
        result[key] = value
    return result

env_text = """
DB_HOST=localhost
DB_PORT=5432
API_KEY="s3cr3t"
"""
import json; print(json.dumps(parse_env(env_text), indent=2))

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.