cookie-v

1.0.1 • Public • Published

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()
  }
})

Readme

Keywords

Package Sidebar

Install

npm i cookie-v

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

3.92 kB

Total Files

6

Last publish

Collaborators

  • xnorain001