@s-libs/js-core
    Preparing search index...

    Function encodeString

    • Transforms value to be represented using a different set of characters, in a way that can be decoded later with decodeString.

      // encode a UUID into a more compact form to include in a URL parameter
      const uuid = 'd5942ea9-6520-42ea-9ced-7013285e4085';
      const UUID_ALPHABET = `-${NUMERIC_ALPHABET}abcdef`;

      const encoded = encodeString(uuid, UUID_ALPHABET, UNRESERVED_ALPHABET);
      const decoded = decodeString(encoded, UUID_ALPHABET, UNRESERVED_ALPHABET);

      expect(encoded).toBe('5pNPwHKvWJeLh-wMQ6_ohqcAm');
      expect(decoded).toBe(uuid);

      Parameters

      • value: string
      • alphabet: string
      • encodeAlphabet: string

      Returns string