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

js-cookie

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-cookie - npm Package Compare versions

Comparing version 3.0.0-beta.0 to 3.0.0-beta.1

66

dist/js.cookie.js

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

/*! js-cookie v3.0.0-beta.0 | MIT */
/*! js-cookie v3.0.0-beta.1 | MIT */
;

@@ -13,2 +13,14 @@ (function (global, factory) {

var rfc6265Converter = {
read: function (value) {
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
},
write: function (value) {
return encodeURIComponent(value).replace(
/%(2[346BF]|3[ACDEF]|40|5[BDE]|60|7[BCD])/g,
decodeURIComponent
)
}
};
function extend () {

@@ -25,7 +37,3 @@ var result = {};

function decode (s) {
return s.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
}
function init (converter) {
function init (converter, defaultAttributes) {
function set (key, value, attributes) {

@@ -36,6 +44,6 @@ if (typeof document === 'undefined') {

attributes = extend(api.defaults, attributes);
attributes = extend(defaultAttributes, attributes);
if (typeof attributes.expires === 'number') {
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e5);
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
}

@@ -46,11 +54,6 @@ if (attributes.expires) {

value = converter.write
? converter.write(value, key)
: encodeURIComponent(String(value)).replace(
/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,
decodeURIComponent
);
value = converter.write(value, key);
key = encodeURIComponent(String(key))
.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
key = encodeURIComponent(key)
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
.replace(/[()]/g, escape);

@@ -63,3 +66,5 @@

}
stringifiedAttributes += '; ' + attributeName;
if (attributes[attributeName] === true) {

@@ -100,5 +105,4 @@ continue

try {
var name = decode(parts[0]);
jar[name] =
(converter.read || converter)(cookie, name) || decode(cookie);
var name = rfc6265Converter.read(parts[0]);
jar[name] = converter.read(cookie, name);

@@ -114,6 +118,5 @@ if (key === name) {

var api = {
defaults: {
path: '/'
},
// Create an instance of the api while ensuring it cannot be
// tampered with...
return Object.freeze({
set: set,

@@ -130,12 +133,17 @@ get: get,

},
withConverter: init
};
return api
withAttributes: function (attributes) {
return init(this.converter, extend(this.attributes, attributes))
},
withConverter: function (converter) {
return init(extend(this.converter, converter), this.attributes)
},
attributes: Object.freeze(defaultAttributes),
converter: Object.freeze(converter)
})
}
var js_cookie = init(function () {});
var api = init(rfc6265Converter, { path: '/' });
return js_cookie;
return api;
}));

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

/*! js-cookie v3.0.0-beta.0 | MIT */
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self,function(){var t=e.Cookies,o=e.Cookies=n();o.noConflict=function(){return e.Cookies=t,o}}())}(this,function(){"use strict";function e(){for(var e={},n=0;n<arguments.length;n++){var t=arguments[n];for(var o in t)e[o]=t[o]}return e}function n(e){return e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)}return function t(o){function r(n,t,r){if("undefined"!=typeof document){"number"==typeof(r=e(i.defaults,r)).expires&&(r.expires=new Date(1*new Date+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=o.write?o.write(t,n):encodeURIComponent(String(t)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),n=encodeURIComponent(String(n)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var f in r)r[f]&&(c+="; "+f,!0!==r[f]&&(c+="="+r[f].split(";")[0]));return document.cookie=n+"="+t+c}}var i={defaults:{path:"/"},set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],r={},i=0;i<t.length;i++){var c=t[i].split("="),f=c.slice(1).join("=");'"'===f.charAt(0)&&(f=f.slice(1,-1));try{var u=n(c[0]);if(r[u]=(o.read||o)(f,u)||n(f),e===u)break}catch(e){}}return e?r[e]:r}},remove:function(n,t){r(n,"",e(t,{expires:-1}))},withConverter:t};return i}(function(){})});
/*! js-cookie v3.0.0-beta.1 | MIT */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self,function(){var n=e.Cookies,r=e.Cookies=t();r.noConflict=function(){return e.Cookies=n,r}}())}(this,function(){"use strict";var e={read:function(e){return e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[ACDEF]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function t(){for(var e={},t=0;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}return function n(r,o){function i(e,n,i){if("undefined"!=typeof document){"number"==typeof(i=t(o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),n=r.write(n,e),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=e+"="+n+c}}return Object.freeze({set:i,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var c=n[i].split("="),u=c.slice(1).join("=");'"'===u.charAt(0)&&(u=u.slice(1,-1));try{var f=e.read(c[0]);if(o[f]=r.read(u,f),t===f)break}catch(e){}}return t?o[t]:o}},remove:function(e,n){i(e,"",t(n,{expires:-1}))},withAttributes:function(e){return n(this.converter,t(this.attributes,e))},withConverter:function(e){return n(t(this.converter,e),this.attributes)},attributes:Object.freeze(o),converter:Object.freeze(r)})}(e,{path:"/"})});
{
"name": "js-cookie",
"version": "3.0.0-beta.0",
"version": "3.0.0-beta.1",
"description": "A simple, lightweight JavaScript API for handling cookies",

@@ -36,3 +36,3 @@ "browser": "dist/js.cookie.js",

"devDependencies": {
"browserstack-runner": "0.9.0",
"browserstack-runner": "^0.9.0",
"eslint": "^6.5.1",

@@ -42,16 +42,16 @@ "eslint-config-standard": "^14.1.0",

"eslint-plugin-markdown": "^1.0.0",
"grunt": "1.0.4",
"grunt-compare-size": "0.4.2",
"grunt-contrib-connect": "2.1.0",
"grunt-contrib-nodeunit": "2.0.0",
"grunt-contrib-qunit": "3.1.0",
"grunt-contrib-watch": "1.1.0",
"grunt-exec": "3.0.0",
"gzip-js": "0.3.2",
"prettier": "1.18.2",
"qunit": "2.9.2",
"grunt": "^1.0.4",
"grunt-compare-size": "^0.4.2",
"grunt-contrib-connect": "^2.1.0",
"grunt-contrib-nodeunit": "^2.0.0",
"grunt-contrib-qunit": "^3.1.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-exec": "^3.0.0",
"gzip-js": "^0.3.2",
"prettier": "^1.18.2",
"qunit": "^2.9.3",
"release-it": "^12.3.6",
"rollup": "^1.20.3",
"rollup-plugin-filesize": "^6.2.0",
"rollup-plugin-license": "^0.12.1",
"rollup-plugin-license": "^0.13.0",
"rollup-plugin-terser": "^5.1.1",

@@ -58,0 +58,0 @@ "standard": "^14.1.0"

@@ -5,3 +5,3 @@ <p align="center">

# JavaScript Cookie [![Build Status](https://travis-ci.org/js-cookie/js-cookie.svg?branch=master)](https://travis-ci.org/js-cookie/js-cookie) [![BrowserStack Status](https://www.browserstack.com/automate/badge.svg?badge_key=b3VDaHAxVDg0NDdCRmtUOWg0SlQzK2NsRVhWTjlDQS9qdGJoak1GMzJiVT0tLVhwZHNvdGRoY284YVRrRnI3eU1JTnc9PQ==--5e88ffb3ca116001d7ef2cfb97a4128ac31174c2)](https://www.browserstack.com/automate/public-build/b3VDaHAxVDg0NDdCRmtUOWg0SlQzK2NsRVhWTjlDQS9qdGJoak1GMzJiVT0tLVhwZHNvdGRoY284YVRrRnI3eU1JTnc9PQ==--5e88ffb3ca116001d7ef2cfb97a4128ac31174c2) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![Code Climate](https://codeclimate.com/github/js-cookie/js-cookie.svg)](https://codeclimate.com/github/js-cookie/js-cookie) [![npm](https://img.shields.io/npm/v/js-cookie)](https://www.npmjs.com/package/js-cookie) [![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/js-cookie/badge?style=rounded)](https://www.jsdelivr.com/package/npm/js-cookie)
# JavaScript Cookie [![Build Status](https://travis-ci.org/js-cookie/js-cookie.svg?branch=master)](https://travis-ci.org/js-cookie/js-cookie) [![BrowserStack Status](https://www.browserstack.com/automate/badge.svg?badge_key=b3VDaHAxVDg0NDdCRmtUOWg0SlQzK2NsRVhWTjlDQS9qdGJoak1GMzJiVT0tLVhwZHNvdGRoY284YVRrRnI3eU1JTnc9PQ==--5e88ffb3ca116001d7ef2cfb97a4128ac31174c2)](https://www.browserstack.com/automate/public-build/b3VDaHAxVDg0NDdCRmtUOWg0SlQzK2NsRVhWTjlDQS9qdGJoak1GMzJiVT0tLVhwZHNvdGRoY284YVRrRnI3eU1JTnc9PQ==--5e88ffb3ca116001d7ef2cfb97a4128ac31174c2) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![Code Climate](https://codeclimate.com/github/js-cookie/js-cookie.svg)](https://codeclimate.com/github/js-cookie/js-cookie) [![npm](https://img.shields.io/github/package-json/v/js-cookie/js-cookie)](https://www.npmjs.com/package/js-cookie) [![size](https://img.shields.io/bundlephobia/minzip/js-cookie/beta)](https://www.npmjs.com/package/js-cookie) [![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/js-cookie/badge?style=rounded)](https://www.jsdelivr.com/package/npm/js-cookie)

@@ -19,3 +19,3 @@ A simple, lightweight JavaScript API for handling cookies

- Enable [custom encoding/decoding](#converters)
- **~900 bytes** gzipped!
- **< 800 bytes** gzipped!

@@ -32,6 +32,6 @@ **If you're viewing this at https://github.com/js-cookie/js-cookie, you're reading the documentation for the master branch.

```
$ npm install js-cookie --save
$ npm i js-cookie
```
The npm package has a `module` property that is pointing to an ES module, to provide support for ES module aware bundlers.
The npm package has a `module` field pointing to an ES module variant of the library, mainly to provide support for ES module aware bundlers, whereas its `browser` field points to an UMD module for full backward compatibility.

@@ -68,6 +68,17 @@ ### Direct download

UMD:
```html
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@beta/dist/js.cookie.min.js"></script>
```
ES module:
```html
<script
type="module"
src="https://cdn.jsdelivr.net/npm/js-cookie@beta/dist/js.cookie.min.mjs"
></script>
```
**Never include the source directly from GitHub (http://raw.github.com/...).** The file

@@ -150,3 +161,3 @@ is being served as text/plain and as such may be blocked because of the wrong MIME type.

_Note: Removing a nonexistent cookie does not raise any exception nor return any value._
_Note: Removing a nonexistent cookie neither raises any exception nor returns any value._

@@ -175,3 +186,3 @@ ## Namespace conflicts

Cookie attributes defaults can be set globally by setting properties of the `Cookies.defaults` object or individually for each call to `Cookies.set(...)` by passing a plain object in the last argument. Per-call attributes override the default attributes.
Cookie attribute defaults can be set globally by creating an instance of the api via `withAttributes()`, or individually for each call to `Cookies.set(...)` by passing a plain object as the last argument. Per-call attributes override the default attributes.

@@ -257,2 +268,22 @@ ### expires

### sameSite
A [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), with possible values `lax` or `strict`, prevents the browser from sending cookie along with cross-site requests.
Default: not set, i.e. include cookie in any request.
**Examples:**
```javascript
Cookies.set('name', 'value', { sameSite: 'lax' })
Cookies.get('name') // => 'value'
Cookies.remove('name')
```
### Setting up defaults
```javascript
const api = Cookies.withAttributes({ path: '/', domain: '.example.com' })
```
## Converters

@@ -262,5 +293,3 @@

Create a new instance of the api that overrides the default decoding implementation.
All get methods that rely in a proper decoding to work, such as `Cookies.get()` and `Cookies.get('name')`, will run the converter first for each cookie.
The returning String will be used as the cookie value.
Create a new instance of the api that overrides the default decoding implementation. All get methods that rely in a proper decoding to work, such as `Cookies.get()` and `Cookies.get('name')`, will run the given converter for each cookie. The returned value will be used as the cookie value.

@@ -272,5 +301,9 @@ Example from reading one of the cookies that can only be decoded using the `escape` function:

document.cookie = 'default=%E5%8C%97'
var cookies = Cookies.withConverter(function (value, name) {
if (name === 'escaped') {
return unescape(value)
var cookies = Cookies.withConverter({
read: function (value, name) {
if (name === 'escaped') {
return unescape(value)
}
// Fall back to default for all other cookies
return Cookies.converter.read(value, name)
}

@@ -289,7 +322,4 @@ })

Cookies.withConverter({
read: function (value, name) {
// Read converter
},
write: function (value, name) {
// Write converter
return value.toUpperCase()
}

@@ -299,2 +329,8 @@ })

## TypeScript declarations
```
$ npm i @types/js-cookie
```
## Server-side integration

@@ -301,0 +337,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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