Skip to content

pedrazzi/esm-cookie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 

Repository files navigation

JavaScript Module Cookie

ES Module version of the cookie package

Example for how to load the ES module in a browser:

<script type="module" src="cookie.js"></script>

OR

<script type="module">
  import cookie from 'cookie.js'
</script>

Basic Usage

Create a cookie, valid across the entire site:

cookie.set('name', 'value')

Create a cookie that expires 7 days from now, valid across the entire site:

cookie.set('name', 'value', { expires: 7 })

Create an expiring cookie, valid to the path of the current page:

cookie.set('test', 'value_test', { expires: 7, path: '' })

Read cookie:

cookie.get('name') // => 'value'
cookie.get('nothing') // => undefined

Read all visible cookies:

cookie.getAll() // => { name: 'value', test: 'value_test' }

Check if cookie exist

cookie.check("name")  // => true