tiny-cookie
Advanced tools
Comparing version 0.3.2 to 0.3.3
{ | ||
"name": "tiny-cookie", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"homepage": "https://github.com/Alex1990/tiny-cookie", | ||
@@ -5,0 +5,0 @@ "authors": [ |
{ | ||
"name": "tiny-cookie", | ||
"description": "A tiny cookie manipulation plugin", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Alex Chao", |
@@ -22,9 +22,11 @@ # tiny-cookie | ||
### Cookie.get(key) | ||
### Cookie(key) | ||
**Alias: Cookie(key)** | ||
Get the cookie value by the given key. | ||
### Cookie.set(key, value, options) | ||
### Cookie(key, value, options) | ||
**Alias: Cookie(key, value, options)** | ||
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: | ||
@@ -40,4 +42,5 @@ | ||
### Cookie.remove(key) | ||
### Cookie(key, null) | ||
**Alias: Cookie(key, null)** | ||
Remove a cookie. | ||
@@ -44,0 +47,0 @@ |
@@ -56,2 +56,16 @@ describe('Cookie()', function() { | ||
it('should return right value if cookie key contains whitespace', function() { | ||
var key = 'he llo'; | ||
var value = 'world'; | ||
document.cookie = key + '=' + value; | ||
expect(Cookie.get(key)).toBe(value); | ||
}); | ||
it('should return right value if cookie value contains whitespace', function() { | ||
var key = 'whitespacevalue'; | ||
var value = 'va lue'; | ||
document.cookie = key + '=' + value; | ||
expect(Cookie.get(key)).toBe(value); | ||
}); | ||
it('should return null if empty string passed', function() { | ||
@@ -65,2 +79,3 @@ document.cookie = 'onlyvalue'; | ||
// At least, in IE 9, it is impossible that cookie value is an empty string. | ||
it('should return an empty string if only key is set', function() { | ||
@@ -67,0 +82,0 @@ document.cookie = 'onlykey='; |
@@ -54,6 +54,6 @@ /*! | ||
key = '(?:^|;)' + escapeRe(key) + '(?:=([^;]*?))?(?:;|$)'; | ||
key = '(?:^|; )' + escapeRe(key) + '(?:=([^;]*?))?(?:;|$)'; | ||
var reKey = new RegExp(key); | ||
var res = reKey.exec(document.cookie.replace(/\s+/g, '')); | ||
var res = reKey.exec(document.cookie); | ||
@@ -60,0 +60,0 @@ return res !== null ? decodeURIComponent(res[1]) : null; |
@@ -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.replace(/\s+/g,""));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(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}); |
110942
3081
49