Add checkLanguageCode util function

This commit is contained in:
Leilei332
2025-10-02 12:50:33 +08:00
parent d77539bf13
commit b9489576c4

View File

@@ -162,6 +162,18 @@ exports.toTitleCase = function(str) {
return (str || "").replace(/(^|\s)\S/g, function(c) {return c.toUpperCase();});
}
/*
Check whether a language code is supported by Intl
*/
exports.checkLanguageCode = lang => {
try {
"a".localeCompare("a", lang);
return true;
} catch(e) {
return false;
}
}
/*
Find the line break preceding a given position in a string
Returns position immediately after that line break, or the start of the string