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

client-cookies

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

client-cookies - npm Package Compare versions

Comparing version 0.2.0 to 0.4.1

3

lib/Cookies.js

@@ -24,3 +24,4 @@ "use strict";

var cookie = key + "=" + value;
cookie += (0, _parseExpiry2.default)(options.expires);
var expires = (0, _parseExpiry2.default)(options.expires);
cookie += expires ? ';expires=' + expires : '';
return document.cookie = cookie;

@@ -27,0 +28,0 @@ },

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -10,9 +10,9 @@ Object.defineProperty(exports, "__esModule", {

var parseExpiry = function parseExpiry(expires) {
switch (typeof expires === "undefined" ? "undefined" : _typeof(expires)) {
switch (typeof expires === 'undefined' ? 'undefined' : _typeof(expires)) {
//no expiry provided
case "undefined":
return "";
case 'undefined':
return '';
break;
//expiry provided as a number of days
case "number":
case 'number':
return new Date(new Date().getTime() + expires * 1000 * 60 * 60 * 24);

@@ -19,0 +19,0 @@ break;

{
"name": "client-cookies",
"version": "0.2.0",
"version": "0.4.1",
"description": "A modest package to easily set, get and delete cookies in Javacript.",

@@ -8,3 +8,6 @@ "scripts": {

"compile": "babel -d lib/ src/",
"prepublish": "npm run compile"
"prepublish": "npm run compile",
"preversion": "npm test",
"version": "npm run compile && git add -A lib && git add package.json",
"postversion": "git push && git push --tags"
},

@@ -21,3 +24,2 @@ "keywords": [

"babel-cli": "^6.2.0",
"babel-core": "^6.2.1",
"babel-preset-es2015": "^6.1.18",

@@ -24,0 +26,0 @@ "chai": "^3.4.1",

@@ -12,3 +12,3 @@ #Client Cookies

Cookies.set('language', 'javascript');
Cookies.set('language', 'javascript'); // Sets the 'language' cookie, expires at end of session

@@ -22,2 +22,17 @@ Cookies.get('language'); // Returns 'javascript'

#### Set Options
You may pass an Object as the third parameter of the set method.
The available tweakable options are:
| Name | Type | Default | Description
|------------|----------------------------|---------|--------
| `expires` | `Number`, `Date`, `String` | `''` | When the property is not passed along, the set cookie will expire at the end of the session. When it is passed along, then the value's type will be evaluated. If it's a number, the cookie will expire that number of days later. If it's a Date instance, the cookie's expiry will be set for that date. Lastly, if it's a string, the code will try to parse a Date instance from it, and set the expiry for then; if it's not parsable, it will be the same as if the expires property had not be set at all, so the cookie will expire at the end of the session.
### Examples
```javascript
Cookies.get('set expiry', 'two days later', {expires: 2}); // Will expire two days later
```
### Testing

@@ -24,0 +39,0 @@ Simply run:

@@ -38,7 +38,7 @@ import jsdom from 'mocha-jsdom';

Cookies.get('expiring-soon').should.equal('');
Cookies.set('expiring-soon', 'like, a day after', {expiry: 1});
Cookies.set('expiring-soon', 'like, a day after', {expires: 1});
Cookies.get('expiring-soon').should.equal('like, a day after');
Cookies.get('expiring later').should.equal('');
Cookies.set('expiring later', 'twenty days later even.', {expiry: 20});
Cookies.set('expiring later', 'twenty days later even.', {expires: 20});
Cookies.get('expiring later').should.equal('twenty days later even.');

@@ -45,0 +45,0 @@ });

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