New Functions
Add deburr function → PR #449
Normalize accented Latin text into plain ASCII-friendly strings. deburr strips combining marks and expands common extended Latin letters and ligatures, which is useful before slugging, searching, or comparing user-facing text.
- Removes Unicode combining marks after NFD normalization
- Handles common Latin characters that do not decompose cleanly, like
Æ,ø,ß, andŁ - Leaves other characters untouched, so it stays focused on transliterating Latin text
import * as _ from 'radashi'
_.deburr('Crème Brûlée') // => 'Creme Brulee'
_.deburr('Ærøskøbing') // => 'Aeroskobing'
_.deburr('Straße') // => 'Strasse'Add getErrorMessage function → PR #466
Turn unknown caught values into a readable message that is safe to display or log. getErrorMessage returns messages from Error instances and non-empty strings, then falls back to "Unknown error." for empty or unsupported values.
- Works with
Errorsubclasses such asTypeError - Accepts string throws without wrapping them first
- Keeps arbitrary objects from being treated as errors just because they have a
messageproperty
import * as _ from 'radashi'
try {
throw new Error('Request failed')
} catch (error) {
_.getErrorMessage(error) // => 'Request failed'
}
_.getErrorMessage('Request failed') // => 'Request failed'
_.getErrorMessage(null) // => 'Unknown error.'