UNPKG

@polgubau/utils

Version:

A collection of utility functions for TypeScript

51 lines 1.89 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var cookies_exports = {}; __export(cookies_exports, { deleteCookie: () => deleteCookie, getCookie: () => getCookie, setCookie: () => setCookie }); module.exports = __toCommonJS(cookies_exports); const setCookie = (name, value, days) => { const expirationDate = /* @__PURE__ */ new Date(); expirationDate.setDate(expirationDate.getDate() + (days ?? 0)); const cookieValue = encodeURIComponent(value) + (days ? `; expires=${expirationDate.toUTCString()}` : ""); document.cookie = `${name}=${cookieValue}; path=/`; }; const getCookie = (name) => { const cookies = document.cookie.split("; "); for (const cookie of cookies) { const [cookieName, cookieValue] = cookie.split("="); if (cookieName === name) { return decodeURIComponent(cookieValue ?? ""); } } return void 0; }; const deleteCookie = (name) => { document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { deleteCookie, getCookie, setCookie }); //# sourceMappingURL=cookies.js.map