password-validator
password-validator copied to clipboard
refactor: improve return types of validate method
- 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[]
-
Defined proper interfaces (
IOptions
,IDetails
) for options and details. -
Other changes are just auto formatting by prettier plugin.