js-cookie.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import "./chunk-HM4MQYWN.js";
  2. // node_modules/js-cookie/dist/js.cookie.mjs
  3. function assign(target) {
  4. for (var i = 1; i < arguments.length; i++) {
  5. var source = arguments[i];
  6. for (var key in source) {
  7. target[key] = source[key];
  8. }
  9. }
  10. return target;
  11. }
  12. var defaultConverter = {
  13. read: function(value) {
  14. if (value[0] === '"') {
  15. value = value.slice(1, -1);
  16. }
  17. return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
  18. },
  19. write: function(value) {
  20. return encodeURIComponent(value).replace(
  21. /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
  22. decodeURIComponent
  23. );
  24. }
  25. };
  26. function init(converter, defaultAttributes) {
  27. function set(name, value, attributes) {
  28. if (typeof document === "undefined") {
  29. return;
  30. }
  31. attributes = assign({}, defaultAttributes, attributes);
  32. if (typeof attributes.expires === "number") {
  33. attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
  34. }
  35. if (attributes.expires) {
  36. attributes.expires = attributes.expires.toUTCString();
  37. }
  38. name = encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
  39. var stringifiedAttributes = "";
  40. for (var attributeName in attributes) {
  41. if (!attributes[attributeName]) {
  42. continue;
  43. }
  44. stringifiedAttributes += "; " + attributeName;
  45. if (attributes[attributeName] === true) {
  46. continue;
  47. }
  48. stringifiedAttributes += "=" + attributes[attributeName].split(";")[0];
  49. }
  50. return document.cookie = name + "=" + converter.write(value, name) + stringifiedAttributes;
  51. }
  52. function get(name) {
  53. if (typeof document === "undefined" || arguments.length && !name) {
  54. return;
  55. }
  56. var cookies = document.cookie ? document.cookie.split("; ") : [];
  57. var jar = {};
  58. for (var i = 0; i < cookies.length; i++) {
  59. var parts = cookies[i].split("=");
  60. var value = parts.slice(1).join("=");
  61. try {
  62. var found = decodeURIComponent(parts[0]);
  63. jar[found] = converter.read(value, found);
  64. if (name === found) {
  65. break;
  66. }
  67. } catch (e) {
  68. }
  69. }
  70. return name ? jar[name] : jar;
  71. }
  72. return Object.create(
  73. {
  74. set,
  75. get,
  76. remove: function(name, attributes) {
  77. set(
  78. name,
  79. "",
  80. assign({}, attributes, {
  81. expires: -1
  82. })
  83. );
  84. },
  85. withAttributes: function(attributes) {
  86. return init(this.converter, assign({}, this.attributes, attributes));
  87. },
  88. withConverter: function(converter2) {
  89. return init(assign({}, this.converter, converter2), this.attributes);
  90. }
  91. },
  92. {
  93. attributes: { value: Object.freeze(defaultAttributes) },
  94. converter: { value: Object.freeze(converter) }
  95. }
  96. );
  97. }
  98. var api = init(defaultConverter, { path: "/" });
  99. export {
  100. api as default
  101. };
  102. /*! Bundled license information:
  103. js-cookie/dist/js.cookie.mjs:
  104. (*! js-cookie v3.0.5 | MIT *)
  105. */
  106. //# sourceMappingURL=js-cookie.js.map