oxjs/min/Unicode/Unicode.js
Sanjay Bhangar a8a7dc9445 Add core Ox modules as ES modules with tests
This commit adds ES module versions of fundamental Ox utilities:
- Array utilities (api, compact, unique, zip, etc.)
- String utilities (capitalize, clean, truncate, wordwrap, etc.)
- Math utilities (trig functions, geographic calculations, etc.)
- Object utilities (clone, serialize, keys/values, etc.)
- Function utilities (cache, debounce, throttle, memoize, etc.)
- Constants (math, time, colors, HTTP status codes)
- Polyfills for older browser compatibility

All modules include proper imports/exports and maintain the same API
as the original implementations. Added comprehensive test coverage with
31 tests passing.

Next steps: Convert remaining core modules, set up build pipeline,
and test backward compatibility with existing examples.

🤖 Generated with AI assistance
2026-02-09 17:32:06 +05:30

104 lines
3.2 KiB
JavaScript

'use strict';
Ox.load.Unicode = function(options, callback) {
Ox.getJSON(Ox.PATH + 'Unicode/json/Unicode.json?' + Ox.VERSION, function(chars) {
//@ Constants
//@ Ox.UNICODE_CHARACTERS <o> Unicode characters
Ox.UNICODE_CHARACTERS = chars;
var byASCII = {}, byName = {}, bySection = [], byType = {};
Ox.forEach(chars, function(data, char) {
if (data.ascii) {
byASCII[data.ascii] = byASCII[data.ascii] || [];
byASCII[data.ascii].push(char);
}
data.names.forEach(function(name) {
byName[name] = char;
});
bySection[data.section] = bySection[data.section] || [];
bySection[data.section].push(char);
byType[data.type] = byType[data.type] || [];
byType[data.type].push(char);
});
//@ Functions
/*@
Ox.getCharactersByASCII <f> Returns all unicode equivalents of a given ASCII character
(ascii) -> <[s]> Unicode Characters
ascii <s> ASCII string
> Ox.getCharactersByASCII('A').length
36
@*/
Ox.getCharactersByASCII = function(ascii) {
return byASCII[ascii] || '';
};
/*@
Ox.getCharacterByName <f> Returns a character for a given unicode name
(name) -> <s> Character
> Ox.getCharacterByName('Skull and Crossbones')
'\u2620'
@*/
Ox.getCharacterByName = function(name) {
return byName[name.toUpperCase()] || '';
};
/*@
Ox.getCharactersBySection <f> Returns all characters in a given section
(section) -> <[s]> Characters
section <s> Unicode section name
> Ox.getCharactersBySection('Arabic').length
252
@*/
Ox.getCharactersBySection = function(section) {
return bySection[section.toUpperCase()] || '';
};
/*@
Ox.getCharactersByType <f> Returns all characters of a given type
(type) -> <[s]> Characters
type <s> Unicode character type
> Ox.getCharactersByType('Uppercase Latin Alphabet').join('')
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@*/
Ox.getCharactersByType = function(type) {
return byType[type.toUpperCase()] || '';
};
/*@
Ox.sortASCII <f> Sorts an array of unicode strings
(arr) -> <[s]> Sorted array
> Ox.sortASCII(['å', 'b', 'ç', 'd', 'é'])
['å', 'b', 'ç', 'd', 'é']
@*/
// FIXME: should be Ox.sortUnicode
Ox.sortASCII = function(arr) {
return Ox.sort(arr, function(str) {
return Ox.toASCII(str);
});
};
/*@
Ox.toASCII <f> Replaces a unicode string with its ASCII equivalent
(unicode) -> <s> ASCII string
> Ox.toASCII('Åbçdé')
'Abcde'
> Ox.toASCII('\u2162 \u33a6')
'3 km3'
@*/
Ox.toASCII = function(str) {
return Ox.map(str, function(chr) {
return chars[chr].ascii || chr;
});
};
callback(true);
});
}