Skip to content

xNoRain001/cookie-v

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Cookie utils.

Installation

npm i cookie-x

Start

const Cookie = require('cookie-v')

const privateKey = 'privateKey'

const server = http.createServer((req, res) => {
  if (req.url === '/foo') {
    const cookie = new Cookie('privateKey', req, res)

    // foo=foo;
    cookie.set({
      key: 'foo',
      value: 'foo',
    })
    
    // ['bar=bar; ', 'baz=baz.Qgcu+leCZ9dhDla9uUZXaAa1OI806hdBMQmCVC73whc=; ']
    cookie.set([
      {
        key: 'bar',
        value: 'bar',
      },
      {
        key: 'baz',
        value: 'baz',
        isSign: true
      }
    ])

    // foo=foo; max-age=3600;
    // This operation will override previous foo
    cookie.set({
      key: 'foo',
      value: 'foo',
      'max-age': '3600'
    })

    res.end()
  }

  if (req.url === '/bar') {
    const cookie = new Cookie('privateKey', req, res)

    cookie.get('foo') // foo
    cookie.get('nonexistentKey') // null

    // { foo: 'foo', bar: 'bar', nonexistentKey: null }
    cookie.get(['foo', 'bar', 'nonexistentKey'])

    res.end()
  }
})

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published