custom-alphabet.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import Hashids from '../lib/hashids';
  2. import { assert } from 'chai';
  3. describe('custom alphabet', () => {
  4. const testAlphabet = (alphabet) => {
  5. const hashids = new Hashids('', 0, alphabet);
  6. const numbers = [1, 2, 3];
  7. const id = hashids.encode(numbers);
  8. const decodedNumbers = hashids.decode(id);
  9. assert.deepEqual(decodedNumbers, numbers);
  10. };
  11. it(`should work with the worst alphabet`, () => {
  12. testAlphabet('cCsSfFhHuUiItT01');
  13. });
  14. it(`should work with half the alphabet being separators`, () => {
  15. testAlphabet('abdegjklCFHISTUc');
  16. });
  17. it(`should work with exactly 2 separators`, () => {
  18. testAlphabet('abdegjklmnopqrSF');
  19. });
  20. it(`should work with no separators`, () => {
  21. testAlphabet('abdegjklmnopqrvwxyzABDEGJKLMNOPQRVWXYZ1234567890');
  22. });
  23. it(`should work with super long alphabet`, () => {
  24. testAlphabet('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&*()-_=+\\|\'";:/?.>,<{[}]');
  25. });
  26. it(`should work with a weird alphabet`, () => {
  27. testAlphabet('`~!@#$%^&*()-_=+\\|\'";:/?.>,<{[}]');
  28. });
  29. });