/* c8 ignore start */ /** * @deprecated Use datasets functionality instead. * @internal */ export interface AssetMatch extends Record { matches: string[] name?: string sourceImage: string } /** * Creates a helper function to ease the fact that assets have different URIs depending on the environment, and the (historical) absence of datasets functionality. It allows an array of URIs to be associated with one cannonical sourceImage, and returns it along with any other data added with it. * * @remarks * Creates a helper function that can be given a src string "needle" to find in the "haystack" {@link AssetMatch.matches} and returns its associated {@link AssetMatch.sourceImage}. If no match found, the helper function returns the sourceImage of the first item, just to ensure a valid image is returned. This is "fail silently" behaviour that can be used to avoid errors when the image is not found. * * @deprecated Use datasets functionality instead. * @internal * * @param haystack - an array of {@link AssetMatch} objects * @returns a function that takes a url to find in the haystack's matches arrays * */ export const createFinder = (haystack: AssetMatch[]) => (needle: string) => { const foundMatch = haystack.find(({matches}) => matches.includes(needle)) if (typeof foundMatch === `undefined`) { console.error(`A template error occurred: no matching data found.`) } return foundMatch || haystack[0] } /** * Checks that the given string is not empty. * @deprecated Use a simple check instead. An empty string is falsy. Not sure why this function was needed, really. * @internal * * @param text - the text to checked * @returns true or false */ export const hasCharacters = (text: string): boolean => Boolean(text) /* c8 ignore stop */