2022-11-17 17:19:32 +02:00
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
2022-04-11 17:49:32 +02:00
|
|
|
import { customAlphabet } from 'nanoid/non-secure';
|
2020-10-09 19:35:46 +02:00
|
|
|
|
2020-12-28 13:48:47 +02:00
|
|
|
// https://zelark.github.io/nano-id-cc/
|
|
|
|
// https://security.stackexchange.com/a/41749/1873
|
|
|
|
// > On the other hand, 128 bits (between 21 and 22 characters
|
|
|
|
// > alphanumeric) is beyond the reach of brute-force attacks pretty much
|
|
|
|
// > indefinitely
|
2020-10-09 19:35:46 +02:00
|
|
|
const nanoid = customAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 22);
|
|
|
|
|
|
|
|
export default {
|
2021-06-22 20:57:04 +02:00
|
|
|
create: function(): string {
|
2022-11-17 17:19:32 +02:00
|
|
|
return uuidv4().replace(/-/g, '');
|
2020-10-09 19:35:46 +02:00
|
|
|
},
|
2021-06-22 20:57:04 +02:00
|
|
|
createNano: function(): string {
|
2020-10-09 19:35:46 +02:00
|
|
|
return nanoid();
|
|
|
|
},
|
2023-07-16 18:48:13 +02:00
|
|
|
createNanoForInboxEmail: (): string => {
|
|
|
|
return customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 8)();
|
|
|
|
},
|
2020-10-09 19:35:46 +02:00
|
|
|
};
|