1function hashToUri(type, hash) { 2 const encodedBlurhash = encodeURI(hash).replace(/#/g, '%23').replace(/\?/g, '%3F'); 3 return `${type}:/${encodedBlurhash}`; 4} 5/** 6 * Converts a blurhash string (`blurhash:/<hash>/<width>/<height>` or <hash>/<width>/<height>) into an `ImageSource`. 7 * 8 * @return An ImageSource representing the provided blurhash. 9 * */ 10export function resolveBlurhashString(str) { 11 const [blurhash, width, height] = str.replace(/^blurhash:\//, '').split('/'); 12 return { 13 uri: hashToUri('blurhash', blurhash), 14 width: parseInt(width, 10) || 16, 15 height: parseInt(height, 10) || 16, 16 }; 17} 18/** 19 * Converts a thumbhash string (`thumbhash:/<hash>` or `<hash>`) into an `ImageSource`. 20 * 21 * @return An ImageSource representing the provided thumbhash. 22 * */ 23export function resolveThumbhashString(str) { 24 // ThumbHash may contain slashes that could break the url when the slash is at the beginning. 25 // We replace slashes with backslashes to make sure we don't break the url's path. 26 const thumbhash = str.replace(/^thumbhash:\//, '').replace(/\//g, '\\'); 27 return { 28 uri: hashToUri('thumbhash', thumbhash), 29 }; 30} 31//# sourceMappingURL=resolveHashString.js.map