Giter Site home page Giter Site logo

Comments (5)

WitteStier avatar WitteStier commented on June 10, 2024 2

The lazy loading as documented did not work for me, however the code below do

const loadOptions = async () => {
  const zxcvbnCommonPackage = await import(/* webpackChunkName: "zxcvbnCommonPackage" */ '@zxcvbn-ts/language-common');
  const zxcvbnEnPackage = await import(/* webpackChunkName: "zxcvbnEnPackage" */ '@zxcvbn-ts/language-en');

  return {
    translations: zxcvbnEnPackage.default.translations,
    dictionary: {
      ...zxcvbnCommonPackage.default.dictionary,
      ...zxcvbnEnPackage.default.dictionary,
    },
  };
};

from zxcvbn.

MrWook avatar MrWook commented on June 10, 2024

The dictionaries are not included in the core library anymore. You need to load them by yourself.

We could add an example in the documentation to show how its done.
For example with webpack you could make an async import for lazyloading:

import zxcvbn from '@zxcvbn-ts/core'

const loadOptions = async () => {
  const zxcvbnCommonPackage =  import(/* webpackChunkName: "zxcvbnCommonPackage" */ '@zxcvbn-ts/language-common')
  const zxcvbnEnPackage =  import(/* webpackChunkName: "zxcvbnEnPackage" */ '@zxcvbn-ts/language-en')

  return {
    dictionary: {
      ...zxcvbnCommonPackage.dictionary,
      ...zxcvbnEnPackage.dictionary,
    },
    translations: zxcvbnEnPackage.translations,
  }
}

const password = 'somePassword'
const options = await loadOptions()
zxcvbn(password, options)

I didn't test it but it should do the trick. With CDN's you would just need to change the imports with await fetch('somecdn/zxcvbn-ts/language-someLanguage').

from zxcvbn.

MrWook avatar MrWook commented on June 10, 2024

I looked into it and it seems like there need to be done some changes to the build script to make it work for the browser and CDN approaches.

from zxcvbn.

MrWook avatar MrWook commented on June 10, 2024

Thats true thanks for the report i adjusted it #27

from zxcvbn.

MrWook avatar MrWook commented on June 10, 2024

I will close the issue as it is documented how to lazy load dictionaries.

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.