Spaces:
Running
Running
File size: 1,243 Bytes
2b7aae2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | class LoaderUtils {
static decodeText(array) {
if (typeof TextDecoder !== 'undefined') {
return new TextDecoder().decode(array);
}
// Avoid the String.fromCharCode.apply(null, array) shortcut, which
// throws a "maximum call stack size exceeded" error for large arrays.
let s = '';
for (let i = 0, il = array.length; i < il; i++) {
// Implicitly assumes little-endian.
s += String.fromCharCode(array[i]);
}
try {
// merges multi-byte utf-8 characters.
return decodeURIComponent(escape(s));
} catch (e) {
// see #16358
return s;
}
}
static extractUrlBase(url) {
const index = url.lastIndexOf('/');
if (index === -1) return './';
return url.substr(0, index + 1);
}
static resolveURL(url, path) {
// Invalid URL
if (typeof url !== 'string' || url === '') return '';
// Host Relative URL
if (/^https?:\/\//i.test(path) && /^\//.test(url)) {
path = path.replace(/(^https?:\/\/[^\/]+).*/i, '$1');
}
// Absolute URL http://,https://,//
if (/^(https?:)?\/\//i.test(url)) return url;
// Data URI
if (/^data:.*,.*$/i.test(url)) return url;
// Blob URL
if (/^blob:.*$/i.test(url)) return url;
// Relative URL
return path + url;
}
}
export { LoaderUtils };
|