1import type { Cookies } from '@sveltejs/kit';
2import { hash } from 'node:crypto';
3
4export const scopeCookies = (cookies: Cookies, path: string) => {
5 return {
6 get: (key: string) => {
7 return cookies.get(key);
8 },
9 set: (key: string, value: string, props: Omit<Parameters<Cookies['set']>[2], 'path'> = {}) => {
10 cookies.set(key, value, { ...props, path });
11 },
12 delete: (key: string, props: Omit<Parameters<Cookies['delete']>[1], 'path'> = {}) => {
13 cookies.delete(key, { ...props, path });
14 }
15 };
16};
17
18const cipherChars = ['#', '%', '+', '=', '//'];
19export const fancyText = (input: string) => {
20 const hashed = hash('sha256', input, 'hex');
21 let result = '';
22 let idx = 0;
23 while (idx < hashed.length) {
24 result += cipherChars[hashed.charCodeAt(idx) % cipherChars.length];
25 idx += 1;
26 }
27 return result;
28};