Comparing version 2.3.1 to 3.0.0
@@ -5,2 +5,16 @@ # Changelog | ||
## [3.0.0] (2021-06-29) | ||
### Added | ||
- `crumble.setCookie()` now accepts a `crumbs.sameSite` attribute, this defaults to `lax` when not provided. | ||
### Changed | ||
- `crumble.removeCookie()` no longer accepts a `crumbs.secure` flag as it is not required to remove a cookie. | ||
### Removed | ||
- Removed the `crumbs.firstPartyOnly` flag as it has been superseded by `crumbs.sameSite`. | ||
## [2.3.1] (2021-05-16) | ||
@@ -7,0 +21,0 @@ |
@@ -52,7 +52,7 @@ /** | ||
/** | ||
* Indicates whether the cookie should only be sent in a first-party context. | ||
* The context restrictions that the cookie should be subject to. | ||
* | ||
* This is subject to client support. | ||
* Defaults to lax. | ||
*/ | ||
firstPartyOnly? : boolean; | ||
sameSite? : 'none' | 'lax' | 'strict'; | ||
} | ||
@@ -142,4 +142,3 @@ | ||
* domain : "a.domain.com", | ||
* path : "/an/example/path", | ||
* secure : false | ||
* path : "/an/example/path" | ||
* }); | ||
@@ -146,0 +145,0 @@ * ``` |
@@ -1,1 +0,1 @@ | ||
var e=new Date("Fri, 31 Dec 9999 23:59:59 GMT");function n(e){return e.replace(/([.*+?^=!:${}()/|[\]\\])/g,"\\$1")}function r(e){return encodeURIComponent(e).replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent)}function t(e){return encodeURIComponent(e).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent)}function o(e,t){var o=n(r(t));return new RegExp("(?:^|.*;)\\s*"+o+"\\s*\\=").test(e)}function a(e,t){var o=n(r(t)),a=new RegExp("(?:(?:^|.*;)\\s*"+o+"\\s*\\=\\s*(.*?)(?:;|$))").exec(e);return null===a?null:decodeURIComponent(a[1])}function i(n){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.value,a=n.name,i=void 0===a?null:a,u=n.age,p=n.expires,c=n.path,l=n.domain,m=n.secure,s=void 0!==m&&m,d=n.firstPartyOnly,g=void 0!==d&&d;if(null===i)throw new TypeError("The cookie name must be provided.");var f=r(i)+"=";if(null!=o&&(f+=t(o)),c&&(f+=";path="+c),l&&(f+=";domain="+l),u){if("number"!=typeof u||isNaN(u))throw new TypeError("The cookie age must be a valid number.");u===1/0&&(u=e.getTime()-Date.now()),(p=new Date).setTime(p.getTime()+u),f+=";max-age="+u/1e3,f+=";expires="+p.toUTCString()}else if(p){if("Invalid Date"===(p=p===1/0?e:new Date(p)).toString())throw new TypeError("The cookie expiry must represent a valid date.");f+=";max-age="+(u=p.getTime()-Date.now())/1e3,f+=";expires="+p.toUTCString()}return s&&(f+=";secure"),g&&(f+=";first-party-only"),f}function u(e){return i({name:e.name,path:e.path,domain:e.domain,secure:e.secure,firstPartyOnly:e.firstPartyOnly,age:-36e5})}export{a as getCookie,o as hasCookie,u as removeCookie,i as setCookie}; | ||
var e=new Date("Fri, 31 Dec 9999 23:59:59 GMT");function n(e){return e.replace(/([.*+?^=!:${}()/|[\]\\])/g,"\\$1")}function t(e){return encodeURIComponent(e).replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent)}function o(e){return encodeURIComponent(e).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent)}function r(e,o){var r=n(t(o));return new RegExp("(?:^|.*;)\\s*"+r+"\\s*\\=").test(e)}function i(e,o){var r=n(t(o)),i=new RegExp("(?:(?:^|.*;)\\s*"+r+"\\s*\\=\\s*(.*?)(?:;|$))").exec(e);return null===i?null:decodeURIComponent(i[1])}function a(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.value,i=n.name,a=void 0===i?null:i,s=n.age,u=n.expires,m=n.path,c=n.domain,p=n.secure,l=void 0!==p&&p,d=n.sameSite,g=void 0===d?"lax":d;if(null===a)throw new TypeError("The cookie name must be provided.");var f=t(a)+"=";if(null!=r&&(f+=o(r)),m&&(f+=";path="+m),c&&(f+=";domain="+c),s){if("number"!=typeof s||isNaN(s))throw new TypeError("The cookie age setting must be a valid number.");s===1/0&&(s=e.getTime()-Date.now()),(u=new Date).setTime(u.getTime()+s),f+=";max-age="+s/1e3,f+=";expires="+u.toUTCString()}else if(u){if("Invalid Date"===(u=u===1/0?e:new Date(u)).toString())throw new TypeError("The cookie expiry setting must represent a valid date.");f+=";max-age="+(s=u.getTime()-Date.now())/1e3,f+=";expires="+u.toUTCString()}if("none"!==g&&"lax"!==g&&"strict"!==g)throw new TypeError("The cookie samesite setting must take the value of `none`, `lax` or `strict`.");if(f+=";samesite="+g,l)f+=";secure";else if("none"===g)throw new Error("The cookie must be secure inorder to set its samesite setting to `none`.");return f}function s(e){return a({name:e.name,path:e.path,domain:e.domain,age:-36e5})}export{i as getCookie,r as hasCookie,s as removeCookie,a as setCookie}; |
{ | ||
"name" : "crumble", | ||
"version" : "2.3.1", | ||
"version" : "3.0.0", | ||
@@ -30,15 +30,15 @@ "type" : "module", | ||
{ | ||
"rollup" : "2.48.0", | ||
"rollup" : "2.52.3", | ||
"rollup-plugin-terser" : "7.0.2", | ||
"@rollup/plugin-babel" : "5.3.0", | ||
"mocha" : "8.4.0", | ||
"mocha" : "9.0.1", | ||
"chai" : "4.3.4", | ||
"chai-string" : "1.5.0", | ||
"sinon" : "10.0.0", | ||
"eslint" : "7.26.0", | ||
"eslint-plugin-import" : "2.23.1", | ||
"sinon" : "11.1.1", | ||
"eslint" : "7.29.0", | ||
"eslint-plugin-import" : "2.23.4", | ||
"eslint-plugin-promise" : "5.1.0", | ||
"eslint-config-protect-me-from-my-stupidity" : "7.2.0", | ||
"@babel/core" : "7.14.2", | ||
"@babel/preset-env" : "7.14.2" | ||
"eslint-config-protect-me-from-my-stupidity" : "7.2.2", | ||
"@babel/core" : "7.14.6", | ||
"@babel/preset-env" : "7.14.7" | ||
}, | ||
@@ -45,0 +45,0 @@ |
@@ -59,3 +59,3 @@ # Crumble | ||
* `secure` (boolean, optional) - Indicates whether the cookie should only be passed over HTTPS connections. Defaults to `false`. | ||
* `firstPartyOnly` (boolean, optional) - Indicates whether the cookie should only be sent in a first-party context. This is subject to client support. Defaults to `false`. | ||
* `sameSite` (string, optional) - Indicates the context restrictions that the cookie should be subject to. This can take the value of `none`, `lax` or `secure`. Defaults to `lax`. | ||
@@ -65,9 +65,10 @@ Example usage: | ||
``` js | ||
document.cookie = setCookie( | ||
{ | ||
name : 'name', | ||
value : 'value', | ||
domain : 'a.domain.com', | ||
path : '/an/example/path', | ||
secure : false | ||
document.cookie = setCookie({ | ||
name : 'name', | ||
value : 'value', | ||
domain : 'a.domain.com', | ||
path : '/an/example/path', | ||
age : 3600, | ||
secure : false, | ||
sameSite : 'strict' | ||
}); | ||
@@ -79,10 +80,10 @@ ``` | ||
``` js | ||
document.cookie = setCookie( | ||
{ | ||
name : 'name', | ||
domain : 'a.domain.com', | ||
path : '/an/example/path', | ||
secure : false | ||
}, "value"); | ||
document.cookie = setCookie({ | ||
name : 'name', | ||
domain : 'a.domain.com', | ||
path : '/an/example/path', | ||
age : 3600, | ||
secure : false, | ||
sameSite : 'strict' | ||
}, 'value'); | ||
``` | ||
@@ -99,4 +100,2 @@ | ||
* `domain` (string, optional) - The (sub)domain of which the cookie will be removed from. Defaults to the current domain. | ||
* `secure` (boolean, optional) - Indicates whether the cookie should only be removed over HTTPS connections. Defaults to `false`. | ||
* `firstPartyOnly` (boolean, optional) - Indicates whether the cookie should only be sent in a first-party context. This is subject to client support. Defaults to `false`. | ||
@@ -106,11 +105,11 @@ Example usage: | ||
``` js | ||
document.cookie = removeCookie( | ||
{ | ||
name : 'name', | ||
domain : 'a.domain.com', | ||
path : '/an/example/path', | ||
secure : false | ||
document.cookie = removeCookie({ | ||
name : 'name', | ||
domain : 'a.domain.com', | ||
path : '/an/example/path' | ||
}); | ||
``` | ||
**Note:** When a cookie was set with a specific path and/or domain, then you must provide the same values during removal. | ||
## Getting started | ||
@@ -117,0 +116,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16907
152
141