Git Product home page Git Product logo

Comments (8)

MrWook avatar MrWook commented on August 19, 2024 2

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

from zxcvbn.

MrWook avatar MrWook commented on August 19, 2024 1

I don't really understand this.
An empty string is a falsy value so if(feedback.warning) should work fine 🤔
Additional there will always be only one warning because this is something set by the highest matcher and are not combined same with the suggestions.

from zxcvbn.

bagbag avatar bagbag commented on August 19, 2024 1

An empty string is a falsy value so if(feedback.warning) should work fine

While it does work, it relies on JavaScripts coercing, which is simply not clean, at least in my view.
Image that you forget to check with an if, then it will just proceed with that empty string. If you have null instead, the TypeScript compiler will complain.

from zxcvbn.

bagbag avatar bagbag commented on August 19, 2024 1

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 null/undefined instead of an empty string, this was what I did intuitively (no check for an empty string). There will be no compiler error from TypeScript. So I run the code... and what I get is an unwanted runtime behavior, even though I check the length of the warnings array to see if there are warnings. Now I have to take some time and debug what happens.

Imagine it would return null instead of ''. TypeScript would complain that null is not allowed inside of that string[] and I could see instantly what the problem is.

With just string it is ambiguous, while string | null (or string | undefined) is unambiguous/explicit.
For your use-case nothing changes. You can still use if (feedback.warning) and TS will give you a string inside that if-block.
You can even get rid of that null if you really want by using strictNullChecks: false.

from zxcvbn.

MrWook avatar MrWook commented on August 19, 2024 1

Apart from this change, it will be everything since the MR #174
Which means:

  • language packages treeshakeable
  • removal of default exports
  • networkError handler options for the pwned matcher
  • diceware dictionary with separated scoring for the dictionary matcher
  • a compound splitter which is used by the generator of the dictionaries => smaller bundle size for the spanish package

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

from zxcvbn.

Tostino avatar Tostino commented on August 19, 2024 1

@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.

from zxcvbn.

MrWook avatar MrWook commented on August 19, 2024

It was @U-4-E-A improved example with if(feedback.warning), which is ignoring an empty warning just fine.

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.

from zxcvbn.

U-4-E-A avatar U-4-E-A commented on August 19, 2024

Victory!

Can I ask what changes we will see in the new major version?

from zxcvbn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.