Encodes values into a randomly generated string.
Generates random identifiers for input strings, the same input string will be the same output string (cached, not hashing). Used in some Reverse Squared projects for generating Error Codes that we can decode but outsiders without access will not be able to.
npm install @reverse/encoder
Use the encode()
function to encode a value. It returns the code that you will have to decode.
import { encode } from '@reverse/encoder';
encode('Hello!');
// Example Output: "91887D"
If you encode the same value twice, the returned code will be the same as the first time you encoded that value.
To decode the value, use the decode()
function. It will return the original value that you encoded.
import { decode } from '@reverse/encoder';
// Assuming we use the same code in the above example.
decode('91887D');
// "Hello!"
This module also exposes two functions for using the ID generator.
import { setIDGenerator } from '@reverse/encoder';
generateID(); // -> "123456" Example ID from default generator.
setIDGenerator(() => 'Hello'); // All generated IDs will be "Hello",
// this will crash the application after
// encoding two separate values.
generateID(); // -> "Hello"