UNPKG

@sigiljs/sigil

Version:

TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating

49 lines (48 loc) 1.74 kB
class o { _precompiled; constructor(i, t, e = {}) { this._name = i, this._value = t, this._options = e, this.compile(); } _name; get name() { return this._name; } _value; get value() { return this._value; } _options; get options() { return { ...this._options }; } compile() { if (this._precompiled) return this._precompiled; const i = []; if (i.push(`${this._name}=${this._value === null ? "" : this.encodeCookieValue(this._value)}`), this._options.expires && i.push(`Expires=${this._options.expires.toUTCString()}`), typeof this._options.maxAge == "number") { if (!Number.isFinite(this._options.maxAge) || !Number.isInteger(this._options.maxAge)) throw new TypeError("maxAge must be a finite integer (seconds)."); i.push(`Max-Age=${this._options.maxAge}`); } this._options.domain && i.push(`Domain=${this._options.domain}`), this._options.path && i.push(`Path=${this._options.path}`), this._options.secure && i.push("Secure"), this._options.httpOnly && i.push("HttpOnly"), this._options.sameSite && i.push(`SameSite=${this.capitalize(this._options.sameSite)}`), this._options.priority && i.push(`Priority=${this.capitalize(this._options.priority)}`), this._options.partitioned && i.push("Partitioned"); const t = i.join("; "); return this._precompiled = t, t; } setOptions(i) { this._options = { ...this._options, ...i }, this.compile(); } setValue(i) { this._value = i, this.compile(); } setName(i) { this._name = i, this.compile(); } encodeCookieValue(i) { return encodeURIComponent(i).replace(/%20/g, "+"); } capitalize(i) { return i.charAt(0).toUpperCase() + i.slice(1); } } export { o as default };