Socket
Socket
Sign inDemoInstall

tiny-cookie

Package Overview
Dependencies
0
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.3 to 0.4.0

2

bower.json
{
"name": "tiny-cookie",
"version": "0.3.3",
"version": "0.4.0",
"homepage": "https://github.com/Alex1990/tiny-cookie",

@@ -5,0 +5,0 @@ "authors": [

{
"name": "tiny-cookie",
"description": "A tiny cookie manipulation plugin",
"version": "0.3.3",
"version": "0.4.0",
"author": {

@@ -6,0 +6,0 @@ "name": "Alex Chao",

@@ -25,4 +25,10 @@ # tiny-cookie

Get the cookie value by the given key.
Get the cookie value with decoding, using `decodeURIComponent`.
### Cookie.getRaw(key)
**Also: Cookie.get(key, true)**
Get the cookie value without decoding.
### Cookie.set(key, value, options)

@@ -32,3 +38,3 @@

Set a cookie. The `options` parameter is an object. And its property can be a valid cookie option, such as `path`, `domain`, `expires`/`max-age` or `secure`. For example, you can set the expiration:
Set a cookie with encoding the value, using `encodeURIComponent`. The `options` parameter is an object. And its property can be a valid cookie option, such as `path`, `domain`, `expires`/`max-age` or `secure`. For example, you can set the expiration:

@@ -42,2 +48,8 @@ ```js

### Cookie.setRaw(key, value, options)
**Also: Cookie.set(key, value, true, options)**
Set a cookie without encoding.
### Cookie.remove(key)

@@ -44,0 +56,0 @@

@@ -56,2 +56,9 @@ describe('Cookie()', function() {

it('should return the value without decoding if second parameter is true', function() {
var key = 'withoutDecoding';
var value = encodeURIComponent('https://github.com/Alex1990/tiny-cookie');
document.cookie = key + '=' + value;
expect(Cookie.get(key, true)).toBe(value);
});
it('should return right value if cookie key contains whitespace', function() {

@@ -86,2 +93,11 @@ var key = 'he llo';

describe('Cookie.getRaw()', function() {
it('should return the value without decoding', function() {
var key = 'withoutDecoding';
var value = encodeURIComponent('https://github.com/Alex1990/tiny-cookie');
document.cookie = key + '=' + value;
expect(Cookie.getRaw(key)).toBe(value);
});
});
describe('Cookie.set()', function() {

@@ -99,2 +115,9 @@ it('should return the set cookie value', function() {

it('should return the value without encoding if the third parameter is true', function() {
var key = 'withoutEncoding';
var value = 'https://github.com/Alex1990/tiny-cookie';
Cookie.setRaw(key, value);
expect(Cookie.getRaw(key)).toBe(value);
});
it('should return null when cookie path is restricted', function() {

@@ -106,2 +129,11 @@ Cookie.set('path_cookie', 'some_value', { path: '/the-other-path/' });

describe('Cookie.setRaw()', function() {
it('should return the value without encoding', function() {
var key = 'withoutEncoding';
var value = 'https://github.com/Alex1990/tiny-cookie';
Cookie.setRaw(key, value);
expect(Cookie.getRaw(key)).toBe(value);
});
});
describe('Cookie.remove()', function() {

@@ -108,0 +140,0 @@ it('should return null when remove "foo" cookie', function() {

@@ -51,3 +51,3 @@ /*!

// Get the cookie value by the key.
Cookie.get = function(key) {
Cookie.get = function(key, raw) {
if (typeof key !== 'string' || !key) return null;

@@ -60,12 +60,26 @@

return res !== null ? decodeURIComponent(res[1]) : null;
return res !== null ? (raw ? res[1] : decodeURIComponent(res[1])) : null;
};
// Get the cookie's value without decoding.
Cookie.getRaw = function(key) {
return Cookie.get(key, true);
};
// Set a cookie.
Cookie.set = function(key, value, opts) {
Cookie.set = function(key, value, raw, opts) {
if (raw !== true) {
opts = raw;
raw = false;
}
opts = opts ? convert(opts) : '';
var cookie = key + '=' + encodeURIComponent(value) + opts;
var cookie = key + '=' + (raw ? value : encodeURIComponent(value)) + opts;
document.cookie = cookie;
};
// Set a cookie without encoding the value.
Cookie.setRaw = function(key, value, opts) {
Cookie.set(key, value, true, opts);
};
// Remove a cookie by the specified key.

@@ -72,0 +86,0 @@ Cookie.remove = function(key) {

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

!function(e,n){"function"==typeof define&&define.amd?define(n):"object"==typeof exports?module.exports=n():e.Cookie=n()}(this,function(e){"use strict";function n(o,t,r){return t===e?n.get(o):void(null===t?n.remove(o):n.set(o,t,r))}function o(e){return e.replace(/[.*+?^$|[\](){}\\-]/g,"\\$&")}function t(e){var n="";for(var o in e)e.hasOwnProperty(o)&&(n=";"+o+"="+e[o]);return n}return n.enabled=function(){var e,o="__test_key";return document.cookie=o+"=1",e=!!document.cookie,e&&n.remove(o),e},n.get=function(e){if("string"!=typeof e||!e)return null;e="(?:^|; )"+o(e)+"(?:=([^;]*?))?(?:;|$)";var n=new RegExp(e),t=n.exec(document.cookie);return null!==t?decodeURIComponent(t[1]):null},n.set=function(e,n,o){o=o?t(o):"";var r=e+"="+encodeURIComponent(n)+o;document.cookie=r},n.remove=function(e){n.set(e,"a",{expires:(new Date).toGMTString()})},n});
!function(e,n){"function"==typeof define&&define.amd?define(n):"object"==typeof exports?module.exports=n():e.Cookie=n()}(this,function(e){"use strict";function n(t,o,r){return o===e?n.get(t):void(null===o?n.remove(t):n.set(t,o,r))}function t(e){return e.replace(/[.*+?^$|[\](){}\\-]/g,"\\$&")}function o(e){var n="";for(var t in e)e.hasOwnProperty(t)&&(n=";"+t+"="+e[t]);return n}return n.enabled=function(){var e,t="__test_key";return document.cookie=t+"=1",e=!!document.cookie,e&&n.remove(t),e},n.get=function(e,n){if("string"!=typeof e||!e)return null;e="(?:^|; )"+t(e)+"(?:=([^;]*?))?(?:;|$)";var o=new RegExp(e),r=o.exec(document.cookie);return null!==r?n?r[1]:decodeURIComponent(r[1]):null},n.getRaw=function(e){return n.get(e,!0)},n.set=function(e,n,t,r){t!==!0&&(r=t,t=!1),r=r?o(r):"";var u=e+"="+(t?n:encodeURIComponent(n))+r;document.cookie=u},n.setRaw=function(e,t,o){n.set(e,t,!0,o)},n.remove=function(e){n.set(e,"a",{expires:(new Date).toGMTString()})},n});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc