Comparing version 2.0.0 to 2.1.0
@@ -5,2 +5,8 @@ # Changelog | ||
## [2.1.0] (2019-04-27) | ||
### Added | ||
- Introduced documentation to the Typescript type definitons. | ||
## [2.0.0] (2018-02-13) | ||
@@ -7,0 +13,0 @@ |
151
Crumble.d.ts
@@ -0,27 +1,150 @@ | ||
/** | ||
* The crumbs that define a cookie. | ||
*/ | ||
export interface Crumbs | ||
{ | ||
name : string; | ||
value? : string | null; | ||
age? : number; | ||
expires? : string | number | Date; | ||
path? : string; | ||
domain? : string; | ||
secure? : boolean; | ||
/** | ||
* The name of the cookie. | ||
*/ | ||
name : string; | ||
/** | ||
* The value of the cookie. | ||
*/ | ||
value? : string | null; | ||
/** | ||
* The duration (in milliseconds) of which the cookie can live. | ||
* | ||
* When omitted and no `expires` crumb is provided, the cookie will expire at the end of the session. | ||
* | ||
* This takes precedence over the `expires` crumb. | ||
*/ | ||
age? : number; | ||
/** | ||
* The expiry date of the cookie. | ||
* | ||
* When omitted and no `age` crumb is provided, the cookie will expire at the end of the session. | ||
*/ | ||
expires? : string | number | Date; | ||
/** | ||
* The path of which the cookie will be created. | ||
* | ||
* Defaults to the current path. | ||
*/ | ||
path? : string; | ||
/** | ||
* The (sub)domain of which the cookie will be created. | ||
* | ||
* Defaults to the current domain. | ||
*/ | ||
domain? : string; | ||
/** | ||
* Indicates whether the cookie should only be passed over HTTPS connections. | ||
*/ | ||
secure? : boolean; | ||
/** | ||
* Indicates whether the cookie should only be sent in a first-party context. | ||
* | ||
* This is subject to client support. | ||
*/ | ||
firstPartyOnly? : boolean; | ||
} | ||
// -------------------------------------------------------- | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
/** | ||
* Determines whether a cookie exists in a plate of cookies like `document.cookie`. | ||
* | ||
* Example usage: | ||
* | ||
* ``` js | ||
* Crumble.hasCookie(document.cookie, 'cookie'); | ||
* ``` | ||
* | ||
* @returns `true` if the cookie exists, otherwise `false`. | ||
* | ||
* @param plate The plate of cookies to search. Will usually be the value of `document.cookie`. | ||
* @param name The name of the cookie to search the plate for. | ||
*/ | ||
export function hasCookie(plate : string, name : string) : boolean; | ||
// -------------------------------------------------------- | ||
/** | ||
* Reads the value of a cookie from a plate of cookies like `document.cookie`. | ||
* | ||
* Example usage: | ||
* | ||
* ``` js | ||
* Crumble.getCookie(document.cookie, 'cookie'); | ||
* ``` | ||
* | ||
* @returns The decoded value of the cookie or `null` if the cookie doesn't exist. | ||
* | ||
* @param plate The plate of cookies to search. Will usually be the value of `document.cookie`. | ||
* @param name The name of the cookie to read from the plate. | ||
*/ | ||
export function getCookie(plate : string, name : string) : string | null; | ||
// -------------------------------------------------------- | ||
/** | ||
* Creates a string that will set a cookie when assigned to a plate like `document.cookie`. | ||
* | ||
* Example usage: | ||
* | ||
* ``` js | ||
* document.cookie = Crumble.setCookie( | ||
* { | ||
* name : "name", | ||
* value : "value", | ||
* domain : "a.domain.com", | ||
* path : "/an/example/path", | ||
* secure : false | ||
* }); | ||
* ``` | ||
* | ||
* Alternatively you can separate the value from the rest of the crumbs, like so: | ||
* | ||
* ``` js | ||
* document.cookie = Crumble.setCookie( | ||
* { | ||
* name : "name", | ||
* domain : "a.domain.com", | ||
* path : "/an/example/path", | ||
* secure : false | ||
* | ||
* }, "value"); | ||
* ``` | ||
* | ||
* This can be useful when the cookie value is the variable and the other crumbs are fixed. | ||
* | ||
* @returns A string that will create or update a cookie. | ||
* | ||
* @param crumbs The crumbs defining the cookie to create or update. | ||
* @param value The value of the cookie. This takes precedence over the `value` crumb. | ||
*/ | ||
export function setCookie(crumbs : Crumbs, value? : string | null) : string; | ||
// -------------------------------------------------------- | ||
/** | ||
* Creates a string that will remove a cookie when assigned to a plate like `document.cookie`. | ||
* | ||
* Example usage: | ||
* | ||
* ``` js | ||
* document.cookie = Crumble.removeCookie( | ||
* { | ||
* name : "name", | ||
* domain : "a.domain.com", | ||
* path : "/an/example/path", | ||
* secure : false | ||
* }); | ||
* ``` | ||
* | ||
* @returns A string that will remove a cookie. | ||
* | ||
* @param crumbs The crumbs defining the cookie to remove. | ||
*/ | ||
export function removeCookie(crumbs : Crumbs) : string; |
MIT License | ||
Copyright (c) 2015 - 2018 Luke Phillips | ||
Copyright (c) 2015 - 2019 Luke Phillips | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
{ | ||
"name" : "crumble", | ||
"version" : "2.0.0", | ||
"version" : "2.1.0", | ||
@@ -16,4 +16,2 @@ "description" : "A RFC-6265 compliant library that makes reading and writing cookies easy.", | ||
[ | ||
"cookie", | ||
"document", | ||
"cookies" | ||
@@ -31,10 +29,10 @@ ], | ||
{ | ||
"mocha" : "5.0.0", | ||
"chai" : "4.1.2", | ||
"chai-string" : "1.4.0", | ||
"sinon" : "4.3.0", | ||
"eslint" : "4.17.0", | ||
"eslint-plugin-import" : "2.8.0", | ||
"eslint-plugin-promise" : "3.6.0", | ||
"eslint-config-protect-me-from-my-stupidity" : "~2.0.4" | ||
"mocha" : "6.1.4", | ||
"chai" : "4.2.0", | ||
"chai-string" : "1.5.0", | ||
"sinon" : "7.3.2", | ||
"eslint" : "5.16.0", | ||
"eslint-plugin-import" : "2.17.2", | ||
"eslint-plugin-promise" : "4.1.1", | ||
"eslint-config-protect-me-from-my-stupidity" : "~3.1.3" | ||
}, | ||
@@ -54,4 +52,4 @@ | ||
{ | ||
"lint" : "eslint 'src/**/*.js' 'tests/**/*.js'", | ||
"unit" : "mocha 'tests/**/*.js'", | ||
"lint" : "eslint \"src/**/*.js\" \"tests/**/*.js\"", | ||
"unit" : "mocha \"tests/**/*.js\"", | ||
"test" : "npm run lint && npm run unit" | ||
@@ -58,0 +56,0 @@ }, |
'use strict'; | ||
/** | ||
* The maximum expiry date a cookie can have. | ||
* | ||
* @private | ||
* | ||
* @static | ||
* | ||
* @final | ||
* | ||
* @type {Date} | ||
* | ||
* @memberof Crumble | ||
*/ | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
const MAXIMUM_EXPIRY_DATE = new Date('Fri, 31 Dec 9999 23:59:59 GMT'); | ||
// -------------------------------------------------------- | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
/** | ||
* Escapes a string so it can be placed in a regular expression. | ||
* | ||
* @static | ||
* | ||
* @private | ||
* | ||
* @return {String} The escaped string. | ||
* | ||
* @param {String} string The string to escape. | ||
* | ||
* @memberof Crumble | ||
*/ | ||
function escapeForRegularExpression (string) | ||
@@ -38,17 +14,4 @@ { | ||
// -------------------------------------------------------- | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
/** | ||
* Encodes a string; treating it as a RFC 6265 compliant cookie name. | ||
* | ||
* @static | ||
* | ||
* @private | ||
* | ||
* @return {String} The encoded string. | ||
* | ||
* @param {String} string The string to encode as a cookie name. | ||
* | ||
* @memberof Crumble | ||
*/ | ||
function encodeAsCookieName (string) | ||
@@ -62,17 +25,4 @@ { | ||
// -------------------------------------------------------- | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
/** | ||
* Encodes a string; treating it as a RFC 6265 compliant cookie value. | ||
* | ||
* @static | ||
* | ||
* @private | ||
* | ||
* @return {String} The encoded string. | ||
* | ||
* @param {String} string The string to encode as a cookie value. | ||
* | ||
* @memberof Crumble | ||
*/ | ||
function encodeAsCookieValue (string) | ||
@@ -84,22 +34,4 @@ { | ||
// -------------------------------------------------------- | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
/** | ||
* Determines whether a cookie exists in a plate of cookies like `document.cookie`. | ||
* | ||
* Example usage: | ||
* | ||
* ``` | ||
* Crumble.hasCookie(document.cookie, 'cookie'); | ||
* ``` | ||
* | ||
* @static | ||
* | ||
* @return {Boolean} `true` if the cookie exists, otherwise `false`. | ||
* | ||
* @param {String} plate The plate of cookies to search. Will usually be the value of `document.cookie`. | ||
* @param {String} name The name of the cookie to search the plate for. | ||
* | ||
* @memberof Crumble | ||
*/ | ||
function hasCookie (plate, name) | ||
@@ -114,22 +46,4 @@ { | ||
// -------------------------------------------------------- | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
/** | ||
* Reads the value of a cookie from a plate of cookies like `document.cookie`. | ||
* | ||
* Example usage: | ||
* | ||
* ``` | ||
* Crumble.getCookie(document.cookie, 'cookie'); | ||
* ``` | ||
* | ||
* @static | ||
* | ||
* @return {String} The decoded value of the cookie or `null` if the cookie doesn't exist. | ||
* | ||
* @param {String} plate The plate of cookies to search. Will usually be the value of `document.cookie`. | ||
* @param {String} name The name of the cookie to read from the plate. | ||
* | ||
* @memberof Crumble | ||
*/ | ||
function getCookie (plate, name) | ||
@@ -151,54 +65,4 @@ { | ||
// -------------------------------------------------------- | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
/** | ||
* Creates a string that will set a cookie when assigned to a plate like `document.cookie`. | ||
* | ||
* Example usage: | ||
* | ||
* ``` | ||
* document.cookie = Crumble.setCookie( | ||
* { | ||
* name : "name", | ||
* value : "value", | ||
* domain : "a.domain.com", | ||
* path : "/an/example/path", | ||
* secure : false | ||
* }); | ||
* ``` | ||
* | ||
* Alternatively you can separate the value from the rest of the crumbs, like so: | ||
* | ||
* ``` | ||
* document.cookie = Crumble.setCookie( | ||
* { | ||
* name : "name", | ||
* domain : "a.domain.com", | ||
* path : "/an/example/path", | ||
* secure : false | ||
* | ||
* }, "value"); | ||
* ``` | ||
* | ||
* This can be useful when the cookie value is the variable and the other crumbs are fixed. | ||
* | ||
* @static | ||
* | ||
* @return {String} A string that will set a cookie. | ||
* | ||
* @param {Object} crumbs The crumbs that make the cookie. | ||
* @param {String} crumbs.name The name of the cookie. | ||
* @param {String} [crumbs.value] The value of the cookie. | ||
* @param {Number} [crumbs.age] The duration (in milliseconds) of which the cookie can live. When omitted and no `expires` crumb is provided, the cookie will expire at the end of the session. This takes precedence over the `expires` crumb. | ||
* @param {Date|String|Number} [crumbs.expires] The expiry date of the cookie. When omitted and no `age` crumb is provided, the cookie will expire at the end of the session. | ||
* @param {String} [crumbs.path] The path of which the cookie will be created. Defaults to the current path. | ||
* @param {String} [crumbs.domain] The (sub)domain of which the cookie will be created. Defaults to the current domain. | ||
* @param {Boolean} [crumbs.secure = false] Indicates whether the cookie should only be passed over HTTPS connections. | ||
* @param {Boolean} [crumbs.firstPartyOnly = false] Indicates whether the cookie should only be sent in a first-party context. This is subject to client support. | ||
* @param {String} [value] The value of the cookie. This takes precedence over the `value` crumb. | ||
* | ||
* @throws {TypeError} When the `name` crumb is `null` or not provided. | ||
* @throws {TypeError} When the `age` crumb is not a valid number. | ||
* @throws {TypeError} When the `expires` crumb does not represent a valid date. | ||
*/ | ||
function setCookie (crumbs, value = crumbs.value) | ||
@@ -295,32 +159,4 @@ { | ||
// -------------------------------------------------------- | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
/** | ||
* Creates a string that will remove a cookie when assigned to a plate like `document.cookie`. | ||
* | ||
* Example usage: | ||
* | ||
* ``` | ||
* document.cookie = Crumble.removeCookie( | ||
* { | ||
* name : "name", | ||
* domain : "a.domain.com", | ||
* path : "/an/example/path", | ||
* secure : false | ||
* }); | ||
* ``` | ||
* | ||
* @static | ||
* | ||
* @return {String} A string that will remove a cookie. | ||
* | ||
* @param {Object} crumbs The crumbs of the cookie to remove. | ||
* @param {String} crumbs.name The name of the cookie. | ||
* @param {String} [crumbs.path] The path of which the cookie will be removed from. Defaults to the current path. | ||
* @param {String} [crumbs.domain] The (sub)domain of which the cookie will be removed from. Defaults to the current domain. | ||
* @param {Boolean} [crumbs.secure = false] Indicates whether the cookie should only be removed over HTTPS connections. | ||
* @param {Boolean} [crumbs.firstPartyOnly = false] Indicates whether the cookie should only be sent in a first-party context. This is subject to client support. | ||
* | ||
* @throws {Error} When the `name` crumb is `null` or not provided. | ||
*/ | ||
function removeCookie ({ name, path, domain, secure, firstPartyOnly }) | ||
@@ -333,4 +169,4 @@ { | ||
// -------------------------------------------------------- | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
module.exports = { hasCookie, getCookie, setCookie, removeCookie }; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
14438
263
1