import { dataBuilder } from "@helpers/datas/dataBuilder"; import { lorem } from "@helpers/ui/lipsum"; import { type Image, RDFTYPE_IMAGE } from "@src/rdf"; export const image: Image = { "@id": "store://local.sample-object/images/1/", "@type": RDFTYPE_IMAGE, creation_date: "2024-11-11T12:54:52.359000Z", update_date: "2024-11-14T08:04:47.631017Z", name: "Sample Image", url: "https://placehold.co/420x500", iframe: false, }; export const get_random_image = ( imageAsIframe = false, allowRemovables = false ): Image => { const removables: string[] = []; const replacements: Image = { "@id": `store://local.sample-object/${Math.floor(Math.random() * 1000)}/`, creation_date: new Date( Date.now() - Math.random() * 365 * 24 * 60 * 60 * 1000 ).toISOString(), update_date: new Date( Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000 ).toISOString(), name: lorem.generateSentences(1), url: "", iframe: typeof imageAsIframe === "boolean" ? imageAsIframe : Math.random() < 0.3, }; replacements.url = `https://placehold.co/420x500?text=${encodeURIComponent( replacements.name || "" )}`; if (allowRemovables) { const removableGenerator = (key: string) => { // Between 0 and 25% chance if (Math.random() < Math.random() * 0.25) { removables.push(key); } }; removableGenerator("name"); removableGenerator("url"); removableGenerator("iframe"); } return dataBuilder(image, removables, replacements, true) as Image; };