UNPKG

@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
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class o{getAny=this.getKnown;#t=Object.create(null);constructor(t){if(t){if(typeof t=="string"){const r=t.charAt(0)==="?"?t.slice(1):t;for(const e of r.split("&")){if(!e)continue;const[s,n=""]=e.split("=",2);this.append(decodeURIComponent(s),decodeURIComponent(n))}return}if(Array.isArray(t)){for(const[r,e]of t)this.append(r,e);return}if(t instanceof URLSearchParams){for(const[r,e]of t)this.append(r,e);return}for(const r in t)this.append(r,t[r])}}json(){return Object.fromEntries(Object.entries(this.#t).map(([t,r])=>[t,r[0]]))}getKnown(t){const r=this.#t[this.#r(String(t))];return(r&&r[0])??null}getAll(t){return this.#t[this.#r(String(t))]??[]}has(t){return this.#r(String(t))in this.#t}set(t,r){return this.#t[this.#r(String(t))]=[String(r)],this}append(t,r){const e=this.#r(String(t)),s=this.#t[e];return s?s.push(String(r)):this.#t[e]=[String(r)],this}delete(t){return delete this.#t[this.#r(String(t))],this}getObject(){const t={};for(const r in this.#t)t[r]=this.#t[r][0];return t}*[Symbol.iterator](){for(const t in this.#t)for(const r of this.#t[t])yield[t,r]}#r(t){return t.toString()}}exports.default=o;