(
source: ImageSourcePropType,
options: PaletteOptions & { target?: PaletteTarget }
)
| 8 | } from './types'; |
| 9 | |
| 10 | export function getCacheKey( |
| 11 | source: ImageSourcePropType, |
| 12 | options: PaletteOptions & { target?: PaletteTarget } |
| 13 | ): string { |
| 14 | const uri = Image.resolveAssetSource(source)?.uri ?? ''; |
| 15 | |
| 16 | function serialize(obj: any): string { |
| 17 | if (obj == null) { |
| 18 | return ''; |
| 19 | } |
| 20 | |
| 21 | if (typeof obj !== 'object') { |
| 22 | return String(obj); |
| 23 | } |
| 24 | |
| 25 | if (Array.isArray(obj)) { |
| 26 | return obj.map(serialize).join(','); |
| 27 | } |
| 28 | |
| 29 | return Object.entries(obj) |
| 30 | .sort(([a], [b]) => a.localeCompare(b)) |
| 31 | .map(([k, v]) => `${k}:${serialize(v)}`) |
| 32 | .join(','); |
| 33 | } |
| 34 | |
| 35 | const optionsStr = serialize(options); |
| 36 | |
| 37 | return [uri, optionsStr].filter(Boolean).join('|'); |
| 38 | } |
| 39 | |
| 40 | export const paletteCache = new Map<string, PaletteResult>(); |
| 41 | export const swatchCache = new Map<string, PaletteSwatch>(); |
no test coverage detected