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

Refactor use of util.format #35

Open
adam-cyclones opened this issue May 30, 2022 · 1 comment
Open

Refactor use of util.format #35

adam-cyclones opened this issue May 30, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@adam-cyclones
Copy link

adam-cyclones commented May 30, 2022

util.format

Supports %s C style replacement but JavaScript itself supports template literals which are clearer to see the expected output and don't need an import.
A function can be used for composure.

const journeyURLTemplate =
  '%s/json%s/realm-config/authentication/authenticationtrees/trees/%s';
const nodeURLTemplate =
  '%s/json%s/realm-config/authentication/authenticationtrees/nodes/%s/%s';
  
// five minutes later
const urlString = util.format(
  queryAllTreesURLTemplate,
  storage.session.getTenant(),
  getCurrentRealmPath()
);

const response = await generateAmApi(getTreeApiConfig())
    .get(urlString, {
      withCredentials: true,
    })

Becomes

const journeyURLTemplate = ({ host, treename }) => `${host}/json%s/realm-config/authentication/authenticationtrees/trees/${treename}`;
const nodeURLTemplate = ({host, something, somethingElse}) => `${host}/json%s/realm-config/authentication/authenticationtrees/nodes/${something}/${somethingElse}`;

const response = await generateAmApi(getTreeApiConfig())
    .get(journeyURLTemplate({ host, treename }), {
      withCredentials: true,
    })
@adam-cyclones adam-cyclones added the enhancement New feature or request label May 30, 2022
@adam-cyclones
Copy link
Author

To disucss

@vscheuber vscheuber transferred this issue from rockcarver/frodo Sep 1, 2022
vscheuber added a commit to vscheuber/frodo-lib that referenced this issue Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant