Created
September 15, 2015 10:20
-
-
Save kfitfk/8d2025d1c25c024ead05 to your computer and use it in GitHub Desktop.
Converts a Unicode range to the actual characters.
This file contains hidden or 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
/** | |
* 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