achievements package in vanilla JavaScript applications.
Installation
Define Your Achievements
UsedefineAchievements() to create a typed array of achievement definitions:
Achievement Properties
id(required): Unique identifier for the achievementlabel(required): Display namedescription(required): Description texthidden(optional): If true, id/label/description are hidden until unlockedhint(optional): If true, only the description is hidden until unlockedmaxProgress(optional): When provided, enables progress tracking and auto-unlocks at this value
Create the Engine
Initialize the achievement engine with your definitions:Configuration Options
definitions(required): Array of achievement definitionsstorage(optional): Storage adapter (defaults tolocalStorageAdapter())hash(optional): Hash adapter for tamper detection (defaults tofnv1aHashAdapter())onUnlock(optional): Callback fired when an achievement is unlockedonTamperDetected(optional): Callback fired when stored data fails integrity check
Unlock Achievements
Manual Unlock
Progress-Based Unlock
For achievements withmaxProgress, they auto-unlock when progress reaches the target:
Item Collection
UsecollectItem() to track unique items and automatically update progress:
Dynamic Progress Targets
UpdatemaxProgress at runtime using setMaxProgress():
Subscribe to Changes
React to achievement state changes:Toast Notifications
Manage achievement unlock notifications:Reset Progress
Wipe all state from memory and storage:Storage Adapters
The package includes three built-in adapters:LocalStorage (Default)
In-Memory Storage
Useful for testing or temporary sessions:Custom Storage
See the Custom Storage Guide for implementing your own adapter.Anti-Cheat Protection
The engine automatically protects stored data with integrity hashes:fnv1aHashAdapter() provides fast, synchronous tamper detection. For stronger hashing, see the Custom Hash Guide.
Complete Example
Next Steps
- React Integration Guide - Use with React hooks and context
- Custom Storage Guide - Implement custom storage backends
- Custom Hash Guide - Use custom hashing for tamper detection
