Sha256: 1e99cc8c75770269d2483eb965bf1ea6ac101ed09a3cc5ea89fe76a951f1e5b1

Contents?: true

Size: 664 Bytes

Versions: 12

Compression:

Stored size: 664 Bytes

Contents

export function getCookie(name) {
  const cookies = document.cookie ? document.cookie.split("; ") : []
  const prefix = `${encodeURIComponent(name)}=`
  const cookie = cookies.find(cookie => cookie.startsWith(prefix))

  if (cookie) {
    const value = cookie.split("=").slice(1).join("=")
    return value ? decodeURIComponent(value) : undefined
  }
}

export function setCookie(name, value) {
  const twentyYears = 20 * 365 * 24 * 60 * 60 * 1000
  const body = [ name, value ].map(encodeURIComponent).join("=")
  const expires = new Date(Date.now() + twentyYears).toUTCString()
  const cookie = `${body}; path=/; expires=${expires}`
  document.cookie = cookie
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
css-zero-0.0.50 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.49 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.48 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.47 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.46 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.45 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.44 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.43 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.42 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.41 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.40 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js
css-zero-0.0.39 lib/generators/css_zero/install/templates/app/javascript/helpers/cookie_helpers.js