{"id":19269118,"url":"https://github.com/instamenta/dotenv_configurator","last_synced_at":"2025-02-23T20:12:03.547Z","repository":{"id":188233646,"uuid":"678339873","full_name":"instamenta/dotenv_configurator","owner":"instamenta","description":"Simple Node.js TypeScript NPM package that converts process.env to Object, Array, Number, Boolean, String","archived":false,"fork":false,"pushed_at":"2023-08-16T13:59:47.000Z","size":5402,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-05T12:42:25.246Z","etag":null,"topics":["dotenv-parser","environment-variables","independent-project","javascript","js","jsdoc","nodependence","npm-package","ts","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/dot_configurator","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/instamenta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-14T10:22:56.000Z","updated_at":"2023-08-16T11:45:34.000Z","dependencies_parsed_at":"2025-01-05T12:41:50.989Z","dependency_job_id":"a2c84c06-a784-4fbb-a048-09a48a6e588a","html_url":"https://github.com/instamenta/dotenv_configurator","commit_stats":null,"previous_names":["instamenta/dotenv_configurator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instamenta%2Fdotenv_configurator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instamenta%2Fdotenv_configurator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instamenta%2Fdotenv_configurator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instamenta%2Fdotenv_configurator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/instamenta","download_url":"https://codeload.github.com/instamenta/dotenv_configurator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240371761,"owners_count":19790888,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotenv-parser","environment-variables","independent-project","javascript","js","jsdoc","nodependence","npm-package","ts","typescript"],"created_at":"2024-11-09T20:18:33.538Z","updated_at":"2025-02-23T20:12:03.508Z","avatar_url":"https://github.com/instamenta.png","language":"TypeScript","readme":"# Dot Configurator\n\nDot configurator is a lightweight utility package for Node.js that simplifies the process of converting `process.env`\nvariables into various JavaScript data types. Whether you're dealing with numbers, objects, arrays, or booleans,\nDotConfigurator can automatically transform your environment variables into the correct data types.\n\n## Features\n\n- 🚀 Effortlessly convert environment variables\n- 📦 Supports numbers, objects, arrays, and booleans\n- 🌈 Intuitive and easy-to-use API\n- ⚙️ Lightweight and dependency-free\n\n## Installation\n\n```bash\nnpm install dotenv_configurator\n```\n\n## How it works? It's quite simple\n\n### Booleans\nThe DotConfigurator class provides an intuitive mechanism to detect and convert environment variables to their respective JavaScript data types. In the case of boolean values, the class employs a comprehensive approach that covers various representations. Whether an environment variable's value is specified as \n* \"true\" \n* \"false\" \n* \"on\" \n* \"off\" \n* \"yes\"  \n* \"no\" \n\n### Logic for Detecting Array, Object, and Number\n\nIn the `DotConfigurator` class, the logic is implemented to automatically detect and convert different types of environment variables. Here's how it handles arrays, objects, and numbers:\n\n- **Array Detection:** If a variable value is enclosed within square brackets (`[...]`), the `DotConfigurator` class attempts to parse it using `JSON.parse()` to convert it into an array. If the parsing is successful and the result is indeed an array, the variable is stored as an array. If the parsing fails or the result is not an array, the variable is treated as a parsing error and assigned the value `'PARSING_ERROR'`.\n\n- **Object Detection:** For variables that contain curly braces (`{...}`), the `DotConfigurator` class applies `JSON.parse()` to convert the variable into an object. If the parsing is successful and the result is a valid object, the variable is stored as an object. If the parsing fails, the variable is treated as a parsing error and assigned the value `'PARSING_ERROR'`.\n\n- **Number Detection:** Numeric variables are detected using the `isNaN()` function. If the variable can be successfully converted to a number using `Number()`, it is stored as a number. Otherwise, it's left unchanged.\n\nThis logic ensures that environment variables are correctly converted to their intended data types, and any parsing errors are properly handled. The `DotConfigurator` class simplifies the process of working with various data types in the `process.env` variables while providing ease of use and reliability.\n\nthe DotConfigurator class intelligently detects these variations and accurately transforms them into the corresponding boolean value. This smart handling ensures that your boolean variables are consistently interpreted, regardless of the specific string representation used in your environment. This capability simplifies the process of managing and utilizing boolean configuration settings within your application.\n\n## Usage\n\n```.env\n  SERVER_PORT: '8080',\n  API_URL: 'https://api.example.com',\n  ENABLE_FEATURE: 'true',\n  DATABASE_CONFIG: '{\"host\":\"localhost\",\"port\":3306}'\n```\n\n```index.js\nconst DotConfigurator = require('dotenv_configurator');\n\nconst dot = new DotConfigurator(process.env);\n\nconst serverPort = dot.GET('SERVER_PORT'); // Returns a number: 8080\n\nconst apiUrl = dot.GET('API_URL'); // Returns a string: \"https://api.example.com\"\n\nconst enableFeature = dot.GET('ENABLE_FEATURE'); // Returns a boolean: true\n\nconst dbConfig = dot.GET('DATABASE_CONFIG'); // Returns an object: { host: localhost, port:3306 }\n```\n\n## Error Handling\nIf there's an error during conversion, the variable will not be cached, and \"PARSING_ERROR\" will be assigned instead. Be sure to check for this value when retrieving a converted variable.\n\nIn case of error's the dotConfigurator will only alert but wont break the app in case you want to still use it you can always access it with just process.env...\n\n## License\n\nThis project is licensed under the MIT License.\n\nHappy coding! 👨‍💻👩‍💻","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finstamenta%2Fdotenv_configurator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finstamenta%2Fdotenv_configurator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finstamenta%2Fdotenv_configurator/lists"}