Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat envToObject #47

Merged
merged 2 commits into from
Aug 3, 2024
Merged

Feat envToObject #47

merged 2 commits into from
Aug 3, 2024

Conversation

aegenet
Copy link
Owner

@aegenet aegenet commented Aug 3, 2024

Combine multiple environment variables into one JS object.

import { env } from 'node:process';
import { envToObject } from '@aegenet/belt-env-to-obj';

// { NAME: 'John', AGE: '25', IS_OK: 'true' }
const result = envToObject(env);
//=> { NAME: 'John', AGE: 25, IS_OK: true }
// Default delimiter is '__' (double underscore)
const config = envToObject(
  {
    BELT__CONTACT__NAME: 'John',
    BELT__CONTACT__AGE: '25',
    BELT__CONTACT__IS_OK: 'true',
  },
  {
    convertKey: key => key.toLowerCase(),
  }
);
// config => { belt: { contact: { name: 'John', age: 25, is_ok: true } } }

@aegenet aegenet self-assigned this Aug 3, 2024
@aegenet aegenet merged commit 247ec0e into master Aug 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant