LoaderUtils.js 793 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // Merges multi-byte utf-8 characters.
  17. return decodeURIComponent( escape( s ) );
  18. },
  19. extractUrlBase: function ( url ) {
  20. var index = url.lastIndexOf( '/' );
  21. if ( index === - 1 ) return './';
  22. return url.substr( 0, index + 1 );
  23. }
  24. };
  25. export { LoaderUtils };
粤ICP备19079148号