1import resolveAssetSource from './resolveAssetSource'; 2import { resolveBlurhashString, resolveThumbhashString } from './resolveHashString'; 3export function isBlurhashString(str) { 4 return /^(blurhash:\/)?[\w#$%*+,\-.:;=?@[\]^_{}|~]+(\/[\d.]+)*$/.test(str); 5} 6// Base64 strings will be recognized as blurhash by default (to keep compatibility), 7// interpret as thumbhash only if correct uri scheme is provided 8export function isThumbhashString(str) { 9 return str.startsWith('thumbhash:/'); 10} 11function resolveSource(source) { 12 if (typeof source === 'string') { 13 if (isBlurhashString(source)) { 14 return resolveBlurhashString(source); 15 } 16 else if (isThumbhashString(source)) { 17 return resolveThumbhashString(source); 18 } 19 return { uri: source }; 20 } 21 if (typeof source === 'number') { 22 return resolveAssetSource(source); 23 } 24 if (typeof source === 'object' && (source?.blurhash || source?.thumbhash)) { 25 const { blurhash, thumbhash, ...restSource } = source; 26 const resolved = thumbhash 27 ? resolveThumbhashString(thumbhash) 28 : resolveBlurhashString(blurhash); 29 return { 30 ...resolved, 31 ...restSource, 32 }; 33 } 34 return source ?? null; 35} 36/** 37 * Resolves provided `source` prop to an array of objects expected by the native implementation. 38 */ 39export function resolveSources(sources) { 40 if (Array.isArray(sources)) { 41 return sources.map(resolveSource).filter(Boolean); 42 } 43 return [resolveSource(sources)].filter(Boolean); 44} 45//# sourceMappingURL=resolveSources.js.map