在这段生成的代码处理 API 账户前,对它进行审查。
接受省略的账户参数或缺失的 preferences,保留值为 0 的重试次数,只返回 id、displayName、theme 和 retries,并且绝不修改输入。
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));
生成代码仅作示例,不代表任何特定模型