-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change return value of feedback.warning when there is no warning given #148
Comments
I don't really understand this. |
While it does work, it relies on JavaScripts coercing, which is simply not clean, at least in my view. |
It was @U-4-E-A improved example with What is the use case where a typescript compile will throw an error? I will check with a few colleagues about "clean code" to get some more opinions on this matter. |
I found this library yesterday and added it to my code. I already have other stuff there which is why I merge the results (code simplified): type CheckPasswordResult = {
warnings: string[]
};
function examplePasswordCheck(password: string): CheckPasswordResult {
const zxcvbnResult = zxcvbn(password);
const someOtherResult = someOtherStuff(password);
const warnings: string[] = [...someOtherResult.warnings, zxcvbnResult.feedback.warning];
return { warnings };
}
function consumer(): void {
const passwordResult = examplePasswordCheck('password-from-request');
if (passwordResult.warnings.length > 0) {
throw new Error('Bad password.');
}
doSomethingWithThePassword();
} As I always work with Imagine it would return With just |
That use case seems more than reasonable 👍 Will change it to null, which would be a breaking change but good thing i'm currently developing against a new major version anyway |
Victory! Can I ask what changes we will see in the new major version? |
Apart from this change, it will be everything since the MR #174
Additionally i'm trying to work on a "unmunger" instead of the l33t speak to search for more complex l33t speak stuff. If i don't get this done i can at least fix #118 which is kind of breaking. Another thing that i'm working on is trying to fix the ReDOS vulnerability dropbox/zxcvbn#327 It would be nice if i could land the seperator MR too #115 |
@MrWook I have a new PR for implementing an "unmunger" if you want to look through it: GoSimpleLLC/nbvcxz#84 I haven't had a chance to look through it to merge yet, but wanted to bring it to your attention. |
Currently returns the following if no warning found: -
feedback: { warning: '', suggestions: [] }
Suggest changing type of warning to
string | null
orstring[]
Reason - empty string still indicates on a programmatic level that a warning "exists". Even though the warning is not currently an array (rather a single string), a return of
warning: []
orwarning: ["A warning message here"]
may be a logical option.If a string (rather than an array of strings) is to be returned, suggest
warning: null
orwarning: "A warning message here"
to establish non-existence of warning. This will allow forif(feedback.warning) {...}
rather thanif(feedback.warning.length) {...}
, which is somewhat hackish.The text was updated successfully, but these errors were encountered: