LoaderUtils.js 857 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @author Don McCurdy / https://www.donmccurdy.com
  3. */
  4. var LoaderUtils = {
  5. decodeText: function ( array ) {
  6. if ( typeof TextDecoder !== 'undefined' ) {
  7. return new TextDecoder().decode( array );
  8. }
  9. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  10. // throws a "maximum call stack size exceeded" error for large arrays.
  11. var s = '';
  12. for ( var i = 0, il = array.length; i < il; i ++ ) {
  13. // Implicitly assumes little-endian.
  14. s += String.fromCharCode( array[ i ] );
  15. }
  16. try {
  17. // merges multi-byte utf-8 characters.
  18. return decodeURIComponent( escape( s ) );
  19. } catch ( e ) { // see #16358
  20. return s;
  21. }
  22. },
  23. extractUrlBase: function ( url ) {
  24. var index = url.lastIndexOf( '/' );
  25. if ( index === - 1 ) return './';
  26. return url.substr( 0, index + 1 );
  27. }
  28. };
  29. export { LoaderUtils };