blade
Version:
React at the edge.
71 lines (67 loc) • 2.37 kB
JavaScript
import { r as decodeURIComponent_ } from "./context-CKkJKjoo.js";
//#region ../../node_modules/hono/dist/utils/cookie.js
var validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
var parse = (cookie, name) => {
if (name && cookie.indexOf(name) === -1) return {};
const pairs = cookie.trim().split(";");
const parsedCookie = {};
for (let pairStr of pairs) {
pairStr = pairStr.trim();
const valueStartPos = pairStr.indexOf("=");
if (valueStartPos === -1) continue;
const cookieName = pairStr.substring(0, valueStartPos).trim();
if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) continue;
let cookieValue = pairStr.substring(valueStartPos + 1).trim();
if (cookieValue.startsWith("\"") && cookieValue.endsWith("\"")) cookieValue = cookieValue.slice(1, -1);
if (validCookieValueRegEx.test(cookieValue)) {
parsedCookie[cookieName] = decodeURIComponent_(cookieValue);
if (name) break;
}
}
return parsedCookie;
};
//#endregion
//#region ../../node_modules/hono/dist/helper/cookie/index.js
var getCookie = (c, key, prefix) => {
const cookie = c.req.raw.headers.get("Cookie");
if (typeof key === "string") {
if (!cookie) return;
let finalKey = key;
if (prefix === "secure") finalKey = "__Secure-" + key;
else if (prefix === "host") finalKey = "__Host-" + key;
return parse(cookie, finalKey)[finalKey];
}
if (!cookie) return {};
return parse(cookie);
};
//#endregion
//#region ../../node_modules/hono/dist/utils/encode.js
var decodeBase64Url = (str) => {
return decodeBase64(str.replace(/_|-/g, (m) => ({
_: "/",
"-": "+"
})[m] ?? m));
};
var encodeBase64Url = (buf) => encodeBase64(buf).replace(/\/|\+/g, (m) => ({
"/": "_",
"+": "-"
})[m] ?? m);
var encodeBase64 = (buf) => {
let binary = "";
const bytes = new Uint8Array(buf);
for (let i = 0, len = bytes.length; i < len; i++) binary += String.fromCharCode(bytes[i]);
return btoa(binary);
};
var decodeBase64 = (str) => {
const binary = atob(str);
const bytes = new Uint8Array(new ArrayBuffer(binary.length));
const half = binary.length / 2;
for (let i = 0, j = binary.length - 1; i <= half; i++, j--) {
bytes[i] = binary.charCodeAt(i);
bytes[j] = binary.charCodeAt(j);
}
return bytes;
};
//#endregion
export { getCookie as i, decodeBase64Url as n, encodeBase64Url as r, decodeBase64 as t };