UNPKG

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