Skip to content

Instantly share code, notes, and snippets.

@kfitfk
Created September 15, 2015 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kfitfk/8d2025d1c25c024ead05 to your computer and use it in GitHub Desktop.
Save kfitfk/8d2025d1c25c024ead05 to your computer and use it in GitHub Desktop.
Converts a Unicode range to the actual characters.
/**
* Convert a Unicode range to the actual characters.
* The Unicode range is in this form - ['U+0020', 'U+0041-005A']
* @param {array} range - An array containing strings of Unicode range.
* @returns {array} - An array containing the actual characters.
*/
function charactersFromUnicodeRange(ranges) {
var output = [];
ranges.forEach(function(range) {
range = range.replace(/^U+/, '');
var parts = range.split('-');
if (parts.length === 1)
return output.push(String.fromCharCode(parseInt(parts[0], 16)));
var start = parseInt(parts[0], 16);
var end = parseInt(parts[1], 16);
for (var i = start; i <= end; i++) {
output.push(String.fromCharCode(i));
}
});
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment