Review a generated account normalizer

from Destructuring assignment
Node 24 intermediate 8 min 3 issues to find

Review this generated code before it handles API accounts.

Accept an omitted account or missing preferences, preserve a retry count of zero, return only id, displayName, theme, and retries, and never mutate the input.

JavaScript
function prepareAccount(input = {}) {
  const {
    id,
    name: displayName,
    preferences: { theme = 'light', retries = 3 },
    password,
    ...remaining
  } = input;

  return {
    ...remaining,
    id,
    displayName,
    theme,
    retries: retries || 3,
  };
}

const account = {
  id: 'U-3',
  name: 'Mira',
  token: 'secret',
  preferences: { theme: 'dark', retries: 0 },
};
console.log(prepareAccount(account));

generated code is illustrative, not from any one model

Open in playground
Report an error