@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
2 lines (1 loc) • 1.23 kB
JavaScript
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class r{#t=Object.create(null);#e=Object.create(null);constructor(t=[]){if(Array.isArray(t))for(let e=0;e<t.length;e+=2)this.append(t[e],t[e+1]);else for(const e in t){const i=t[e];i!==void 0&&(Array.isArray(i)?i.forEach(o=>this.append(e,o)):this.append(e,i))}}get link(){return this.#t}get cookies(){return{...this.#e}}getCookie(t){return this.#e[t]}*entries(){for(const t in this.#t)for(const e of this.#t[t])yield[t,e]}json(){return Object.fromEntries(Object.entries(this.#t).map(([t,e])=>[t,e[0]]))}has(t){return t.toString().toLowerCase()in this.#t}get(t){return this.#t[t.toString().toLowerCase()]?.[0]??null}getAll(t){return this.#t[t.toString().toLowerCase()]??[]}set(t,e){const i=t.toString().toLowerCase();return this.#t[i]=[e],i==="cookie"&&this.#i(e),this}append(t,e){const i=t.toString().toLowerCase();return(this.#t[i]||=[]).push(e),i==="cookie"&&this.#i(e),this}delete(t){const e=t.toString().toLowerCase();return delete this.#t[e],e==="cookie"&&(this.#e={}),this}#i(t){t.split(";").forEach(e=>{const[i,...o]=e.trim().split("=");i&&(this.#e[i]=decodeURIComponent(o.join("=")||""))})}}exports.default=r;