prsm/packages/ids
nvms 2acba51367 refactor: convert ids to functional API with improved tests
- Replace class-based implementation with functional approach
- Switch from Manten to Vitest for testing
- Update README with clearer API documentation
- Fix alphabet randomization test
2025-03-26 19:03:31 -04:00
..
src refactor: convert ids to functional API with improved tests 2025-03-26 19:03:31 -04:00
tests refactor: convert ids to functional API with improved tests 2025-03-26 19:03:31 -04:00
.npmignore relocate these 2024-08-27 18:16:34 -04:00
bump.config.ts relocate these 2024-08-27 18:16:34 -04:00
bun.lockb refactor: convert ids to functional API with improved tests 2025-03-26 19:03:31 -04:00
package.json refactor: convert ids to functional API with improved tests 2025-03-26 19:03:31 -04:00
README.md refactor: convert ids to functional API with improved tests 2025-03-26 19:03:31 -04:00
tsconfig.json relocate these 2024-08-27 18:16:34 -04:00
tsup.config.ts relocate these 2024-08-27 18:16:34 -04:00
vitest.config.ts refactor: convert ids to functional API with improved tests 2025-03-26 19:03:31 -04:00

ids

NPM version

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