Last active
October 12, 2024 14:14
-
-
Save kashmiry/ba35115ba23e8b6f034c2562dbd4042c to your computer and use it in GitHub Desktop.
DataTables Arabic Search Normalization. this extends the diacritics function provided in DataTables >= 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ready | |
$(function() { | |
//extend diacritics to support arabic characters | |
if(typeof DataTable !== 'undefined') { | |
DataTable.util.diacritics(function(str, both) { | |
if(typeof str !== 'string') { | |
return str; | |
} | |
var normalized = str | |
.normalize("NFD") | |
.replace(/[أآإ]/g, 'ا') //alef | |
.replace("ؤ", "و") //waw | |
.replace(/ة/g, "ه") //taa marbota | |
.replace(/[\u064B-\u065F]/g, ''); //tashkeel | |
return normalized.length !== str.length ? | |
(both === true ? str + ' ' : '') + normalized.replace(/[\u0300-\u036f]/g, "") : | |
normalized; | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment