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

Simplify initOptional function for clarity #204

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

darseen
Copy link
Contributor

@darseen darseen commented Dec 24, 2023

Pull Request: Refactor initOptional Function

Description:

This pull request simplifies the initOptional function for improved clarity and conciseness. Key changes include:

  • Simplified variable initialization using the logical OR operator.
  • Maintained the same functionality with reduced redundancy.

Before:

initOptional(key, options, fallback = null) {
    let value = options[key];
    //Env variables names expected to be in SNAKE_CASE and uppercase
    let envKey = `AMADEUS_${key.replace(/[A-Z]/g, c => `_${c.toLowerCase()}`).toUpperCase()}`;
    if (value == undefined) { value = options[key]; } // unnecessary if check
    if (value == undefined) { value = process.env[envKey]; }
    if (value == undefined) { value = fallback; }
    return value;
  }

After:

initOptional(key, options, fallback = null) {
    // Env variables names expected to be in SNAKE_CASE and uppercase
    let envKey = `AMADEUS_${key.replace(/[A-Z]/g, c => `_${c.toLowerCase()}`).toUpperCase()}`;
    let value = options[key] || process.env[envKey] || fallback;
    return value;
}

Testing:

  • Executed existing unit tests to ensure maintained functionality.

Impact

  • Non-breaking changes that simplify code without altering behavior.

Reviewer

  • Please review for readability and confirm no unintended side effects.

Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@minjikarin minjikarin merged commit a70fd98 into amadeus4dev:master Jan 3, 2024
4 checks passed
@minjikarin
Copy link
Contributor

@darseen, Thank you so much for your contribution :)

@darseen darseen deleted the initOptional-refactor branch January 15, 2024 17:17
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.

2 participants