format-cookie.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.formatCookie = void 0;
  6. var getSameSiteValue = function getSameSiteValue(o) {
  7. var sameSite = o.sameSite;
  8. if (typeof sameSite === "undefined") return null;
  9. if (["none", "lax", "strict"].indexOf(sameSite.toLowerCase()) >= 0) return sameSite;
  10. return null;
  11. };
  12. var formatOptions = function formatOptions(o) {
  13. var path = o.path,
  14. domain = o.domain,
  15. expires = o.expires,
  16. secure = o.secure;
  17. var sameSiteValue = getSameSiteValue(o);
  18. return [typeof path === "undefined" || path === null ? "" : ";path=" + path, typeof domain === "undefined" || domain === null ? "" : ";domain=" + domain, typeof expires === "undefined" || expires === null ? "" : ";expires=" + expires.toUTCString(), typeof secure === "undefined" || secure === false ? "" : ";secure", sameSiteValue === null ? "" : ";SameSite=" + sameSiteValue].join("");
  19. };
  20. var formatCookie = function formatCookie(k, d, o) {
  21. return [encodeURIComponent(k), "=", encodeURIComponent(d), formatOptions(o)].join("");
  22. };
  23. exports.formatCookie = formatCookie;