CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
cookies.js54 linesDownload Raw Back to helpers
1import utils from '../utils.js';2import platform from '../platform/index.js';3 4export default platform.hasStandardBrowserEnv ?5 6  // Standard browser envs support document.cookie7  {8    write(name, value, expires, path, domain, secure, sameSite) {9      if (typeof document === 'undefined') return;10 11      const cookie = [`${name}=${encodeURIComponent(value)}`];12 13      if (utils.isNumber(expires)) {14        cookie.push(`expires=${new Date(expires).toUTCString()}`);15      }16      if (utils.isString(path)) {17        cookie.push(`path=${path}`);18      }19      if (utils.isString(domain)) {20        cookie.push(`domain=${domain}`);21      }22      if (secure === true) {23        cookie.push('secure');24      }25      if (utils.isString(sameSite)) {26        cookie.push(`SameSite=${sameSite}`);27      }28 29      document.cookie = cookie.join('; ');30    },31 32    read(name) {33      if (typeof document === 'undefined') return null;34      const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));35      return match ? decodeURIComponent(match[1]) : null;36    },37 38    remove(name) {39      this.write(name, '', Date.now() - 86400000, '/');40    }41  }42 43  :44 45  // Non-standard browser env (web workers, react-native) lack needed support.46  {47    write() {},48    read() {49      return null;50    },51    remove() {}52  };53 54