Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eggjs/egg-cookies
cookies module for egg, base on pillarjs/cookies
https://github.com/eggjs/egg-cookies
cookie egg-plugin
Last synced: about 1 month ago
JSON representation
cookies module for egg, base on pillarjs/cookies
- Host: GitHub
- URL: https://github.com/eggjs/egg-cookies
- Owner: eggjs
- License: mit
- Created: 2016-07-15T02:54:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-07-06T09:23:55.000Z (5 months ago)
- Last Synced: 2024-10-29T21:05:51.800Z (about 1 month ago)
- Topics: cookie, egg-plugin
- Language: TypeScript
- Homepage:
- Size: 150 KB
- Stars: 29
- Watchers: 27
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-egg - egg-cookies - Cookie模块。 ![](https://img.shields.io/github/stars/eggjs/egg-cookies.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/egg-cookies.svg?style=flat-square) (仓库 / [内置插件](https://eggjs.org/zh-cn/basics/plugin.html#%E6%8F%92%E4%BB%B6%E5%88%97%E8%A1%A8))
README
# @eggjs/cookies
[![NPM version][npm-image]][npm-url]
[![build status][ci-image]][ci-url]
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url][npm-image]: https://img.shields.io/npm/v/@eggjs/cookies.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/cookies
[ci-image]: https://github.com/eggjs/egg-cookies/actions/workflows/nodejs.yml/badge.svg
[ci-url]: https://github.com/eggjs/egg-cookies/actions/workflows/nodejs.yml
[codecov-image]: https://codecov.io/gh/eggjs/egg-cookies/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/eggjs/egg-cookies
[download-image]: https://img.shields.io/npm/dm/@eggjs/cookies.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/cookiesExtends [pillarjs/cookies](https://github.com/pillarjs/cookies) to adapt koa and egg with some additional features.
## Encrypt
`@eggjs/cookies` provide an alternative `encrypt` mode like `signed`. An encrypt cookie's value will be encrypted base on keys. Anyone who don't have the keys are unable to know the original cookie's value.
```ts
import { Cookies } from '@eggjs/cookies';const cookies = new Cookies(ctx, keys[, defaultCookieOptions]);
cookies.set('foo', 'bar', { encrypt: true });
cookies.get('foo', { encrypt: true });
```**Note: you should both indicating in get and set in pairs.**
## Cookie Length Check
[Browsers all had some limitation in cookie's length](http://browsercookielimits.squawky.net/), so if set a cookie with an extremely long value(> 4093), `@eggjs/cookies` will emit an `cookieLimitExceed` event. You can listen to this event and record.
```ts
import { Cookies } from '@eggjs/cookies';const cookies = new Cookies(ctx, keys);
cookies.on('cookieLimitExceed', ({ name, value }) => {
// log
});cookies.set('foo', longText);
```## License
[MIT](LICENSE)
## Contributors
[![Contributors](https://contrib.rocks/image?repo=eggjs/egg-cookies)](https://github.com/eggjs/egg-cookies/graphs/contributors)
Made with [contributors-img](https://contrib.rocks).