password-validator icon indicating copy to clipboard operation
password-validator copied to clipboard

refactor: improve return types of validate method

Open rocktimsaikia opened this issue 6 months ago • 0 comments

  1. Added function overloads to improve the return type of the verify class method specifically.

Before:

Used to return the same union type. Which required hacks like as string[] in TS.

validate("password") # Boolean | string[]
validate("password", { list: true }) # Boolean | string[]
validate("password", { details: true }) # Boolean | string[]

After:

Now returns single specific type depending on the options provieded. Better DX.

validate("password") # Boolean
validate("password", { list: true }) # string[]
validate("password", { details: true }) # IDetails[]
  1. Defined proper interfaces (IOptions, IDetails) for options and details.

  2. Other changes are just auto formatting by prettier plugin.

rocktimsaikia avatar Aug 14 '24 15:08 rocktimsaikia