replace(str, map)
Replaces occurrences of keys in a string based on a mapping object.
Example:
1compressor.replace("hello world", { hello: '$a', world: '$b' });2// "$a $b"
Edge Cases & Notes:
- Supports Unicode words via
\p{L}regex. - Generates short keys using patterns like
a, b, ..., z, aa, ab. - Words shorter than
minLengthor below frequency threshold are ignored. - Safe to use on strings without dictionary; returns original string unchanged if mapping is empty.