CyberAP/nanoid-dictionary

Add shortcuts

Closed this issue · 16 comments

ai commented

Now you need to imports to use nanoid-dictionary. Let’s make it smaller.

const unmistakable = require('nanoid-dictionary/unmistakable');

unmistakable(10) //=> ID with 10 symbols used `nanoid/generate` inside

Of course, we can keep old API

I've redone the structure. That will do?

ai commented

Can you show example of new structure?

ai commented

I saw the same example there 😄

Readme is updated now as well.

Possible now.

ai commented

@CyberAP I can’t see compact syntax in the docs. Can you give me a direct link to one function example?

ai commented

Here is the examples what I see:

const generate = require('nanoid/generate');
const dictionary = require('nanoid-dictionary');

const englishLowercase = generate(dictionary.lowercase, 10);

Still 2 imports, not a shortcut.

const englishLowercase = generate('nanoid-dictionary/lowercase', 10);

What is generate? NanoID’s generate doesn’t support passing file names.

What is generate? NanoID’s generate doesn’t support passing file names.

That's a typo, sorry. Should be:

const englishLowercase = require('nanoid-dictionary/lowercase');
ai commented

What is englishLowercase? Is it an alphabet’s string or a function? (if I don’t understand it, other user will no understand as well)

I know, that's all been fixed.

ai commented

Seems like it is just alphabet string https://github.com/CyberAP/nanoid-dictionary/blob/master/lowercase.js#L1

So to generate ID with this alphabet you need to make 2 imports and use long generate(englishLowercase, 10) call. It is not a shortcut, still too long for small utility library (user will ignore this solution and will go back to npm to look one-import solutions).

I see. I need to think about this. This change would practically convert this repo from pure utility to a mediator.

OK, I think I have a better idea. I can create a separate repo nanoid-generate which would be a mediator between the dictionary and nanoid generate method. This would be the place where you have all the predefined generators already set up for you. That would provide an exact functionality you want and also preserve dictionary as purely an utility repo. What do you think?

ai commented

Sounds good

Took a while, but here it is: https://github.com/CyberAP/nanoid-generate