lodash.deburr provides a utility function that removes diacritics (accent marks) from latin-1 supplementary letters, converting them to their basic latin equivalents. This is useful for text normalization, search functionality, URL slug generation, and internationalization scenarios where accent-insensitive processing is required.
npm install lodash.deburr or use from full lodash libraryFor standalone lodash.deburr package:
const deburr = require('lodash.deburr');From full lodash library:
const _ = require('lodash');
// Use as _.deburr()ES6 modules (if available):
import deburr from 'lodash.deburr';const deburr = require('lodash.deburr');
// Remove accents from common phrases
const result1 = deburr('déjà vu');
// => 'deja vu'
const result2 = deburr('naïve café');
// => 'naive cafe'
const result3 = deburr('Zürich résumé');
// => 'Zurich resume'
// Handle empty or null values gracefully
const result4 = deburr('');
// => ''
const result5 = deburr(null);
// => ''
const result6 = deburr(undefined);
// => ''Converts latin-1 supplementary letters (accented characters) to their basic latin equivalents while preserving other characters.
/**
* Deburrs string by converting latin-1 supplementary letters to basic latin letters.
*
* @param {string} [string=''] - The string to deburr
* @returns {string} Returns the deburred string
*/
function deburr(string)Behavior:
Usage Examples:
// Basic accent removal
deburr('Crème brûlée'); // => 'Creme brulee'
deburr('piña colada'); // => 'pina colada'
// URL slug generation
function createSlug(text) {
return deburr(text)
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '');
}
createSlug('Café París'); // => 'cafe-paris'
// Search normalization
function normalizeForSearch(query) {
return deburr(query).toLowerCase();
}
const searchTerms = ['café', 'cafe'];
const normalizedTerms = searchTerms.map(normalizeForSearch);
// => ['cafe', 'cafe'] - now identical for matching
// Form data cleaning
const userInput = 'José María González';
const cleanedName = deburr(userInput);
// => 'Jose Maria Gonzalez'Character Mappings:
The function handles these latin-1 supplementary letter ranges:
Edge Cases: