UNPKG

@estarlincito/utils

Version:

A collection of utility functions designed to simplify and speed up development tasks in JavaScript and TypeScript projects.

2 lines (1 loc) 1.69 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("zod"),c=require("./num.cjs"),g=t.z.object({alt:t.z.string(),height:t.z.number().optional(),url:t.z.string(),width:t.z.number().optional()}),a=t.z.object({description:t.z.string(),images:t.z.tuple([g]).rest(g),locale:t.z.string().default("en-US"),siteName:t.z.string(),title:t.z.string(),url:t.z.string()}),l=t.z.object({authors:t.z.tuple([t.z.string()]).rest(t.z.string()),isbn:t.z.string(),releaseDate:t.z.string(),tags:t.z.tuple([t.z.string()]).rest(t.z.string())}).merge(a),m=t.z.object({audio:t.z.string().url().optional(),authors:t.z.tuple([t.z.string()]).rest(t.z.string()),modifiedTime:t.z.string(),publishedTime:t.z.string(),section:t.z.string(),tags:t.z.tuple([t.z.string()]).rest(t.z.string())}).merge(a),z=t.z.object({article:m,book:l,website:a}),h=s=>t.z.object({description:t.z.string(),icons:t.z.object({icon:t.z.string(),shortcut:t.z.string()}),metadataBase:t.z.instanceof(URL),openGraph:z.shape[s].transform(e=>({...e,images:e.images,type:s})),title:t.z.string()});class d{constructor(){}static generate(e,i){const u=e.images.map((r,o)=>{const n={...r};return o===0&&r.height!==void 0&&(n.height=c.num("600")),o===0&&r.width!==void 0&&(n.width=c.num("800")),n});return h(i).parse({description:e.description,icons:{icon:"/assets/favicons/favicon.ico",shortcut:"/assets/favicons/shortcut-icon.png"},metadataBase:new URL(e.url),openGraph:{...z.shape[i].parse({...e,images:u}),type:i},title:e.title})}static article(e){return this.generate(e,"article")}static website(e){return this.generate(e,"website")}static book(e){return this.generate(e,"book")}}exports.GenerateMetadata=d;