Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

isomorphic-cookie

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isomorphic-cookie - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

2

package.json
{
"name": "isomorphic-cookie",
"version": "1.2.1",
"version": "1.2.2",
"description": "Load and save cookies on the client and server",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

# isomorphic-cookie
Load, save and remove cookies within your isomorphic application
## Isomorphic cookies!
The initial idea for this package came from the popular react-cookie package, but we've made it a little harder to make serious mistakes using plugToRequest() with async server operations. Instead of providing that function, that allows you to only read/write to one request at a time (the current plugged request), we've allowed for passing the request to the load() function and the response to the save() and remove() functions. This way it's easier to reason about exactly which request/response you're interacting with.

@@ -10,5 +9,28 @@

## Download
`npm install @discodigital/isomorphic-cookie`
`npm install --save isomorphic-cookie`
## Usage
### `isomorphicCookie.load(name, [request], [doNotParse])`
### `isomorphicCookie.save(name, val, [options], [response])`
### `isomorphicCookie.remove(name, [options], [response])`
## options (object)
### path
> cookie path
### expires
> absolute expiration date for the cookie (Date object)
### domain
> domain for the cookie
### secure
> defaults to true
### httpOnly
# Examples

@@ -23,6 +45,32 @@

isomorphicCookie.save('clientCookie', 'clientCookie value here');
isomorphicCookie.save('clientCookie', 'Cookie value here');
```
### On the server (Express):
```js
const express = require('express');
const cookieParser = require('cookie-parser');
const path = require('path');
const isomorphicCookie = require('isomorphic-cookie');
const app = express();
app.use(express.static('dist'));
app.use(cookieParser());
app.get('/', (req, res) => {
console.log(`client cookie: ${isomorphicCookie.load('clientCookie', req)}`);
console.log(`server cookie: ${isomorphicCookie.load('serverCookie', req)}`);
isomorphicCookie.save('serverCookie', 'Cookie value here', {}, res);
res.sendFile(path.join(__dirname, 'index.html'));
});
app.listen(8000);
```
### On the server (Hapi):

@@ -59,3 +107,3 @@ ```js

isomorphicCookie.save('serverCookie', `serverCookie, call #: ${callIndex}`, {}, reply);
isomorphicCookie.save('serverCookie', 'Cookie value here', {}, reply);

@@ -76,53 +124,3 @@ reply.file(path.join(__dirname, 'index.html'));

### On the server (Express):
```js
const express = require('express');
const cookieParser = require('cookie-parser');
const path = require('path');
const isomorphicCookie = require('isomorphic-cookie');
const app = express();
app.use(express.static('dist'));
app.use(cookieParser());
app.get('/', (req, res) => {
console.log(`client cookie: ${isomorphicCookie.load('clientCookie', req)}`);
console.log(`server cookie: ${isomorphicCookie.load('serverCookie', req)}`);
isomorphicCookie.save('serverCookie', `serverCookie, call #: ${callIndex}`, {}, res);
res.sendFile(path.join(__dirname, 'index.html'));
});
app.listen(8000);
```
## Usage
### `isomorphicCookie.load(name, [request], [doNotParse])`
### `isomorphicCookie.save(name, val, [options], [response])`
### `isomorphicCookie.remove(name, [options], [response])`
## options (object)
### path
> cookie path
### expires
> absolute expiration date for the cookie (Date object)
### domain
> domain for the cookie
### secure
> defaults to true
### httpOnly
## License
This project is under the MIT license. You are free to do whatever you want with it.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc