-
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
Not recognizing dictionary words when multiple dictionaries are used #241
Comments
Hey, thank you for the report. Never thought about it and i wrote the whole documentation about it 🤦 I think i will rename all dictionaries with a language suffix so this will not happen anymore. 🤔 As a workaround you could either merge the dictionaries by yourself or rename them. |
Thanks for #249 👍 Using multiple languages packages in dictionaries seems like a common use case. @MrWook would it be possible to get it published? The last published version of the English dictionary and language package is https://unpkg.com/browse/@zxcvbn-ts/[email protected]/dist/index.esm.js
I was looking for this in the docs actually - recommendations for how to safely merge dictionaries. Even after #249 is released, I would suggest the following 2 docs topics:
|
Hey @karlhorky, this feature is a breaking change so it will come with the next major release.
import * as zxcvbnDePackage from '@zxcvbn-ts/language-de'
import * as zxcvbnEnPackage from '@zxcvbn-ts/language-en'
const options = {
dictionary: {
commonWords: [
...zxcvbnDePackage.dictionary.commonWords,
...zxcvbnEnPackage.dictionary.commonWords,
]
},
} Or you could use a deep-merge library and just do this: import * as zxcvbnDePackage from '@zxcvbn-ts/language-de'
import * as zxcvbnEnPackage from '@zxcvbn-ts/language-en'
import deepMerge from 'deepmerge'
const options = {
dictionary: deepMerge(zxcvbnDePackage.dictionary, zxcvbnEnPackage.dictionary),
} Here is a simple function that iterates over all entries of a language dictionary. Its a little bit dirty but its from chatGPT and works just fine function combineObjects(...objects: { [key: string]: any[] }[]): {
[key: string]: any[]
} {
return objects.reduce(
(combined, current) => {
Object.keys(current).forEach((key) => {
if (!combined[key]) {
combined[key] = []
}
combined[key] = combined[key].concat(current[key])
})
return combined
},
{} as { [key: string]: any[] },
)
} You can use it like the deepmerge library: import * as zxcvbnDePackage from '@zxcvbn-ts/language-de'
import * as zxcvbnEnPackage from '@zxcvbn-ts/language-en'
import * as zxcvbnJaPackage from '@zxcvbn-ts/language-ja'
import deepMerge from 'deepmerge'
const options = {
dictionary: combineObjects(zxcvbnDePackage.dictionary, zxcvbnEnPackage.dictionary, , zxcvbnJaPackage.dictionary),
} Maybe i could add the combineObjects function as a helper function. Probably i need to add helper function for #254 anyway.
As to why i'm not doing anything. I'm pretty busy with my personal life at the moment and i'm maintaining this project by my self but i'm always happy for some helping hands. |
Of course! It's open source, you don't owe me or anyone else anything. Thanks for maintaining it ❤️ And hope things are ok with you.
Oh, wasn't aware, thanks for the tip! Would you be ok with reopening this issue until the major release is published to npm? I would suggest this so that it's visible to users that it's an open issue in the current published version. Currently it's hard to find this problem, and this topic is missing from the docs.
Yeah, after analyzing the data structures and looking at the content of But there are sharp edges with combining Records, as we see in this issue (combining multiple dictionaries with property name collisions). Another path of questioning that I would have as a user would be:
Ideally I would hope for / expect a bit simpler of an API for this library, but I think with some documentation (and maybe some error handling / throwing) the current API could also work.
Yeah either some kind of helper (and ideally also docs, front and center in "Getting Started") would be good, to avoid the problems that users are running into.
That sounds pretty nice, yes! But it seems semantically different (eg. dynamic user input vs fixed website information). The usage example of const options = {
dictionary: {
websiteAndBrandWords: ['mycoolsite', 'my cool site', 'my.cool.site'],
},
}
zxcvbnOptions.setOptions(options) But again, it is in a section titled "UserInput", so that is semantically a different use case. My docs suggestion in 2 above is this:
On an unrelated "docs improvements" note: the top-level menu sections could be optimized further for most users - the positions of "Migration" and "Examples" could be swapped, since examples are much more interesting for most users than Migration. I can open an umbrella issue for improving the docs experience for users, if this would be accepted. |
Unfortunately thats not how github works. I link the issues with the merge requests and if the MR is merged the issue is closed. I think other libraries are not keeping the issues around too. But i can pin it so that everybody can see this issue as it is a major flaw in the system.
Documentation isn't one of my best points :D But if its not too much work for you feel free to add it as the documentation is just a bunch of .md files here
Actually the new major version will have a new API as described in the current pinned issue.
This idea of yours is already working exactly as you typed it.
Like i wrote previously feel free to adjust the documentation. As the maintainer of this library it's a bit hard to see what a consumer of the library really needs as i have everything in my head and "think" thats already known so i don't really "think" about writing it down. |
Projects can choose how they want to use issues / PRs on GitHub. I've seen a number of projects that will keep issues open until the work has been released (or even some greater requirement, like if the work has been integrated and tested in some external system, after release). But I understand if you and the other maintainers of Thanks for pinning!
Ok nice, thanks for the tip. These types of best practices things would be good to have in docs (how to optimally work with dictionaries, add new entries, stay performant, etc).
Ah ok, "class based" sounds like potentially more complicated of an API (personally preferring more functional APIs as much as possible) - hope that usage stays simple for users!
Nice, that would be good! I think also runtime errors are also useful for TypeScript users (multiple channels of messaging that something is going wrong are good).
Yeah, I was expecting the code to work - it was more for demonstrating how it wasn't related to the current section "UserInput".
Nice, I'll try to find some time to open an issue describing the changes I would recommend to the docs to improve the flow and clarity. And maybe already add some of those "best practices" things from how to use and add to dictionaries. |
Like i said i use the normal github workflow i would like to keep the issues open too but there is no configuration for something like that and i don't want to go against the tools that i'm using.
Probably but otherwise i need to expose a bunch of heavy scripts to compute the correct dictionaries and other options. So a class that will handle this is a lot easier. You could say a factory function would work too but i think this would be personal preferences and the classes approach made the overall codebase a lot easier. I added your ideas to issues to track the progress on them #269 #268 Additionally i published a beta version of the next major release so that i have more time to implement more breaking changes but have the other breaking changes out there |
If you use the common, en and de dictionary in the options, words like "eigentlich" are not seen as a dictionary word and considered brute-force. If only the de dictionary is used in the options, it is recognized as a dictionary word.
The text was updated successfully, but these errors were encountered: