unorm icon indicating copy to clipboard operation
unorm copied to clipboard

Make it a true shim

Open walling opened this issue 11 years ago • 3 comments

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).

walling avatar Nov 18 '13 10:11 walling

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.

phadej avatar Nov 21 '13 13:11 phadej

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.

walling avatar Jan 07 '14 13:01 walling

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';

Mouvedia avatar Nov 25 '17 15:11 Mouvedia