unorm
unorm copied to clipboard
Make it a true shim
If the JavaScript environment supports the String.prototype.normalize
function, this library should use that and export is as the unorm
functions (as fallback for code that expects it).
I'm not sure how to do this. It would be nice to still be able to use unorm implementation even browser has it's own.
I thought something like this:
if (!String.prototype.normalize) {
String.prototype.normalize = function() {
// ... unorm implementation here ...
return function(form) {
// ...
};
};
}
var unorm = {
nfc: function(str) { return ('' + str).normalize('NFC'); },
// ...
};
// export unorm object to browser, CommonJS, AMD, etc.
But you're right: What if I want to use unorm implementation instead of the one supplied by the browser. I don't have a nice solution yet for this use case.
What if I want to use unorm implementation instead of the one supplied by the browser.
It should work like this:
// this uses String.prototype.normalize if it's available
// but replaces it for any browser which has a partial implementation
import 'unorm';
// this uses unorm implementation
// granted you actually use the default export
import 'unorm' from 'unorm';