Skip to content

a good case to use one "options" argument #21

@FarahZaqout

Description

@FarahZaqout

Here what you're doing is taking two arguments then put them into a single object, which is when it makes sense to take that object from the beginning as one parameter

const createCookie = (otps) => {
const token = sign(opts, process.env.SECRET);
  return token;
};

we can do validation here like

const createCookie = (otps) => {
if (!opts.userId) throw new Error('missing user id in cookie input') // or whatever error message you feel makes sense to you
const token = sign(opts, process.env.SECRET);
  return token;
};

validation is always good, in your original function, you could forget to enter a value and the function will not tell you anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions