import Hashids from '../lib/hashids' describe('custom alphabet', () => { const testAlphabet = (alphabet: string) => { const hashids = new Hashids('', 0, alphabet) const numbers = [1, 2, 3] const id = hashids.encode(numbers) const decodedNumbers = hashids.decode(id) expect(decodedNumbers).toEqual(numbers) } test(`should work with the worst alphabet`, () => { testAlphabet('cCsSfFhHuUiItT01') }) test(`should work with an alphabet containing spaces`, () => { testAlphabet('cCsSfFhH uUiItT01') }) test(`should work with half the alphabet being separators`, () => { testAlphabet('abdegjklCFHISTUc') }) test(`should work with exactly 2 separators`, () => { testAlphabet('abdegjklmnopqrSF') }) test(`should work with no separators`, () => { testAlphabet('abdegjklmnopqrvwxyzABDEGJKLMNOPQRVWXYZ1234567890') }) test(`should work with super long alphabet`, () => { testAlphabet( 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&*()-_=+\\|\'";:/?.>,<{[}]', ) }) test(`should work with a weird alphabet`, () => { testAlphabet('`~!@#$%^&*()-_=+\\|\'";:/?.>,<{[}]') }) test(`should work with an alphabet with unicode chars`, () => { testAlphabet('πŸ˜€πŸ˜πŸ˜‚πŸ€£πŸ˜ƒπŸ˜„πŸ˜…πŸ˜†πŸ˜‰πŸ˜ŠπŸ˜‹πŸ˜ŽπŸ˜πŸ˜˜πŸ₯°πŸ˜—πŸ˜™πŸ˜š') }) test(`should work with an alphabet with complex unicode chars`, () => { testAlphabet('πŸ€ΊπŸ‘©πŸΏβ€πŸ¦³πŸ›πŸ‘©πŸ»πŸ¦·πŸ€¦β€β™‚οΈπŸβ˜πŸΌβœπŸΎπŸ‘‰πŸ½πŸ‡ΈπŸ‡°β€οΈπŸ­') }) test(`should work with alphabet that contains emojis that are subsets of each other`, () => { testAlphabet('πŸ˜πŸ§‘πŸ½β€πŸ¦³πŸ§‘πŸ·πŸ‘©πŸΏβ€πŸ¦°πŸ‘©πŸΎβ€πŸ¦°πŸ‘©πŸ½β€πŸ¦°πŸ‘©πŸ»β€πŸ¦°βœπŸΎπŸ‘‰πŸ½πŸ‘©πŸ»πŸ¦·πŸ€¦β€β™‚οΈ') testAlphabet('πŸ˜πŸ§‘πŸ§‘πŸ½β€πŸ¦³πŸ·πŸ‘©πŸ»β€πŸ¦°πŸ‘©πŸΏβ€πŸ¦°πŸ‘©πŸ½β€πŸ¦°πŸ‘©πŸΎβ€πŸ¦°βœπŸΎπŸ‘‰πŸ½πŸ‘©πŸ»πŸ¦·πŸ€¦β€β™‚οΈ') }) })