4.0.3 • Published 6 months ago

koa-cookies v4.0.3

Weekly downloads
44,122
License
MIT
Repository
github
Last release
6 months ago

koa-cookies

Set, clear, and parse cookies in your Koa application.

Donate


Installation

npm i koa-cookies

Usage

// set up your koa server, koa-router, etc.
import { clearCookie, setCookie, parseCookie } from 'koa-cookies'

// Use in routes
app.get('/foo', async (ctx, next) => {
  await setCookie('bar', 'baz')(ctx) // => void
})
app.get('/things', async (ctx) => {
  await clearCookie('foo')(ctx) // => void
})
app.get('/stuff', async (ctx) => {
  await parseCookie('bar')(ctx) // => string value for this cookie key
})

// Use as middlewares
app.use(setCookie('foo', 'bar', config)) // set on every request
app.use(clearCookie('baz', config)) // clear on every request
app.use(parseCookie()) // always add all cookies to ctx.cookies

The config argument is optional. Defaults:

setCookieConfig = {
  domain: ctx.host,
  maxAge: one week,
  expires: one week from now
}

clearCookieConfig = {
  domain: ctx.host,
  maxAge: 1 second,
  expires: 1970-01-01T00:00:00.001Z
}

LICENSE

4.0.3

6 months ago

4.0.1

1 year ago

4.0.0

1 year ago

4.0.2

1 year ago

3.2.0

1 year ago

3.1.4

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.1

6 years ago