CyberAP/nanoid-dictionary

Add unistakable alphabet

ai opened this issue · 11 comments

ai commented

23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz this alphabet can no be misread in URL (no chance to errors like 1 instead of l or o instead of 0)

Maybe providing a helper function excludeMisreadings would be better?

excludeMisreadings('0123aloc') => '23ac'

ai commented

Any name, that you want

Fixed with a helper function preventMisreadings and a character set lookalikes.

ai commented

Users often need consistence ID length. This is why preventMisreadings can’t be used.

Let’s reopen it and add not-looks-alike alphabet.

ai commented

BTW, check the origin issue: ai/nanoid#99

The user needs one import, one function. This is the second reason why preventMisreadings didn’t fix the problem here.

This is why preventMisreadings can’t be used.

Why?

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

const safeStr = generate(preventMisreadings(url), 10);

The user needs one import, one function. This is the second reason why preventMisreadings didn’t fix the problem here.

This has to be done in project, not in repo. I would like to provide only generic exports that can be combined in any manner.

Let's imagine we don't want upper case or lower case there, what are we going to do then? We'll have to make a separate variant for all of these options, which I don't think is optimal right now.

For this very case it would be much better to extract it to a separate file and require it.

The user needs one import, one function.

Can't agree here, I think he needs a completely different thing: he wants to change nanoid behaviour globally, using some configuration. And after configuring it globally in one place use it everywhere else just as usual, but with his custom config already applied on each require.

Nanoid doesn't have that, so he has to store that configuration somewhere and require it in every place he uses nanoid. I can't see how providing a prepared string would fix this issue. He would still have to require that config everywhere, even as a wrapper function.

This I think is the best thing he could do right now:

// createSafeUrl.js
const generate= require('nanoid/generate');
const url = require('nanoid/url');
const preventMisreadings = require('nanoid-dictionary/preventMisreadings');

export default function(length = 10) {
  return generate(preventMisreadings(str), length);
}
import createSafeUrl from './createSafeUrl';

const safeUrl = createSafeUrl();

Or just write down the alphabet manually, as in his example. That works even better as there's no processing required in that case.

ai commented

It requires 3 imports, instead of 1. Not an option.

In that issue, the user explicitly what to have 1 import without extra helper file. And it is a good desire. Fewer imports (with the same functionality) is always better DX.

he wants to change nanoid behaviour globally, using some configuration.

Yes, it is what he asked. But he want a different thing:

  1. He has Meteor Random
  2. He wants to replace it to Nano ID.
  3. Meteor Random is only one import in every file.
  4. If he will replace one import to multiple imports or to one extra file it will downgrade DX for he.
  5. This is why after conversation he agreed that import nonLookAlike from 'nanoid-dictionary' will be good for he. One import. No extra helper JS file to support
jafri commented

@ai I think 5 and S can look quite similar depending on the renderer, perhaps worth removing 5

ai commented

Agree

@ai I think 5 and S can look quite similar depending on the renderer, perhaps worth removing 5

I can bump the version to 3.0.0 and update noLookalikes alphabet. But that will be after the 8th of January.

Updated nolookalikes to exclude 5, S and s. Available in the version v3.0.0.