mirror of
https://github.com/nvms/prsm.git
synced 2025-12-15 15:50:53 +00:00
- Replace class-based implementation with functional approach - Switch from Manten to Vitest for testing - Update README with clearer API documentation - Fix alphabet randomization test |
||
|---|---|---|
| .. | ||
| src | ||
| tests | ||
| .npmignore | ||
| bump.config.ts | ||
| bun.lockb | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| tsup.config.ts | ||
| vitest.config.ts | ||
ids
Short, obfuscated, collision-proof, reversible identifiers.
Usage
import id from "@prsm/ids";
id.encode(12389125); // "7rYTs_"
id.decode("7rYTs_"); // 12389125
Configuration
Set custom alphabet:
id.setAlphabet("GZwBHpfWybgQ5d_2mM-jh84K69tqYknx7LN3zvDrcSJVRPXsCFT");
Randomize alphabet:
id.randomizeAlphabet();
API
| Function | Description |
|---|---|
encode(num) |
Converts number to obfuscated string |
decode(str) |
Converts obfuscated string back to number |
setAlphabet(str) |
Sets custom alphabet for encoding |
getAlphabet() |
Returns current alphabet |
randomizeAlphabet() |
Shuffles alphabet characters randomly |
Notes
- Maximum encodable value: 2,147,483,647 (MAX_INT32)
- Changing alphabet changes encoded values
- Encoded values must be decoded with same alphabet