UNPKG

gentelella

Version:

Gentelella v4 — free admin template. 60 pages, 20 chart variants, fully interactive inbox & kanban, live theme generator, component playground, PWA-ready. Vite 8, vanilla JS, no Bootstrap, no jQuery.

1 lines 1.46 kB
function t(){return"undefined"!=typeof window&&(!!window.__GENTELELLA_API__||new URLSearchParams(window.location.search).has("api"))}function n(t,n){let e=t.slice(),a=Math.max(0,...e.map(t=>Number(t.id)||0))+1;return{list:async(t={})=>n?e.filter(e=>n(e,t)):e.slice(),get:async t=>e.find(n=>String(n.id)===String(t))||null,async create(t){const n={id:a++,...t};return e.unshift(n),n},async update(t,n){const a=e.findIndex(n=>String(n.id)===String(t));return 0>a?null:(e[a]={...e[a],...n},e[a])},async remove(t){const n=e.length;return e=e.filter(n=>String(n.id)!==String(t)),n>e.length},reset(){e=t.slice()}}}function e(t,n={}){const e=n.fetch||((...t)=>globalThis.fetch(...t)),r=n.listKey,s=async t=>{if(!t.ok){const n=await t.text().catch(()=>"");throw new a(t.status,n||t.statusText)}return t.json()};return{async list(n={}){const a=new URLSearchParams(n).toString(),i=a?`${t}?${a}`:t,o=await s(await e(i));return r?o[r]??[]:o},get:async n=>s(await e(`${t}/${encodeURIComponent(n)}`)),create:async n=>s(await e(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})),update:async(n,a)=>s(await e(`${t}/${encodeURIComponent(n)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})),remove:async n=>s(await e(`${t}/${encodeURIComponent(n)}`,{method:"DELETE"}))}}var a=class extends Error{constructor(t,n){super(`HTTP ${t}: ${n}`),this.name="HttpError",this.status=t}};export{n,t as r,e as t};