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

crumble

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crumble - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

CHANGELOG.md

5

Crumble.d.ts

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

// Type definitions for Crumble
// --------------------------------------------------------
export interface Crumbs

@@ -30,3 +27,3 @@ {

export function setCookie(crumbs : Crumbs, cookieValue? : string | null | undefined) : void;
export function setCookie(crumbs : Crumbs, value? : string | null | undefined) : void;

@@ -33,0 +30,0 @@ // --------------------------------------------------------

2

LICENSE.txt
MIT License
Copyright (c) 2015 - 2017 Luke Phillips
Copyright (c) 2015 - 2018 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" : "1.0.0",
"version" : "1.1.0",

@@ -30,8 +30,10 @@ "description" : "A simple wrapper that makes reading the cookies of a given document easy and expressive.",

{
"jsdom" : "9.5.0",
"chai" : "3.5.0",
"sinon" : "1.15.4",
"grunt" : "0.4.5",
"grunt-eslint" : "19.0.0",
"grunt-mocha-cli" : "2.1.0"
"mocha" : "4.1.0",
"jsdom" : "11.5.1",
"chai" : "4.1.2",
"eslint" : "4.14.0",
"sinon" : "4.1.3",
"eslint-plugin-import" : "2.8.0",
"eslint-plugin-promise" : "3.6.0",
"eslint-config-protect-me-from-my-stupidity" : "~2.0.3"
},

@@ -51,3 +53,5 @@

{
"test" : "grunt test"
"lint" : "node_modules/.bin/eslint 'src/**/*.js' 'tests/**/*.js'",
"unit" : "node_modules/.bin/mocha 'tests/**/*.js'",
"test" : "npm run lint && npm run unit"
},

@@ -54,0 +58,0 @@

@@ -12,27 +12,25 @@ # Crumble

Determines whether cookies are enabled in the document.
Determines whether the client has cookies enabled.
### `Boolean Crumble#hasCookie(string name)`
### `String Crumble#getCookie(string name)`
Determines whether a cookie exists in the document.
Retrieves the value of a cookie. `null` will be returned if the cookie does not exist.
### `String Crumble#getCookie(string name)`
### `Boolean Crumble#hasCookie(string name)`
Retrieves the value of a cookie from the document. `null` will be returned if the cookie does not exist.
Determines whether a cookie exists.
### `void Crumble#setCookie(Object crumbs [, string cookieValue])`
### `void Crumble#setCookie(Object crumbs [, string value])`
Sets a cookie in the document.
Sets a cookie. The cookie crumbs you can provide are:
The cookie crumbs you can provide are:
* `name` (string, required) - The name of the cookie.
* `value` (string, optional) - The value of the cookie.
* `age` (number, optional) - The duration (in milliseconds) of which the cookie can live. When defined, any provided expiry date is ignored. When set to `Infinity` the cookie will be set to expire with date: `31 Dec 9999 23:59:59 GMT`.
* `expires` (Date|string|number, optional) - The expiry date of the cookie, if omitted, the cookie will expire at the end of the session. You can provide a date object, date string or a timestamp. When provided a timestamp equivalent to `Infinity` the cookie will be set to expire with date: `31 Dec 9999 23:59:59 GMT`.
* `path` (string, optional) - The path of which the cookie will be created. Defaults to the current path.
* `domain` (string, optional) - The (sub)domain of which the cookie will be created. When set to `.` the domain will be set to the current root domain. Defaults to the current domain.
* `secure` (boolean, optional) - Indicates whether the cookie should only be sent 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`.
* `name` (String, required) - The name of the cookie.
* `value` (String, optional) - The value of the cookie.
* `age` (Number, optional) - The duration (in milliseconds) of which the cookie can live. When defined, any provided expiry date is ignored. When set to `Infinity` the cookie will be set to expire with date: `31 Dec 9999 23:59:59 GMT`.
* `expires` (Date|String|Number, optional) - The expiry date of the cookie, if omitted, the cookie will expire at the end of the session. You can provide a date object, date string or a timestamp. When provided a timestamp equivalent to `Infinity` the cookie will be set to expire with date: `31 Dec 9999 23:59:59 GMT`.
* `path` (String, optional) - The path of which the cookie will be created. Defaults to the path of the document.
* `domain` (String, optional) - The (sub)domain of which the cookie will be created. The domain can only be a domain that the document is in, however cookies can cross subdomains. When set to `.` the domain will be set to the root domain of the document. Defaults to the domain of the document (i.e. the value of `document.domain`).
* `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`.
Example usage:

@@ -43,7 +41,11 @@

{
name : 'name', value : 'value', domain : 'a.domain.com', path : '/a/document/path', secure : false
name : "name",
value : "value",
domain : "a.domain.com",
path : "/an/example/path",
secure : false
});
```
Alternatively you can separate the value from the cookie crumbs:
Alternatively you can separate the value of the cookie from the cookie crumbs:

@@ -53,3 +55,6 @@ ``` js

{
name : 'name', domain : 'a.domain.com', path : '/a/document/path', secure : false
name : 'name',
domain : 'a.domain.com',
path : '/an/example/path',
secure : false

@@ -59,16 +64,14 @@ }, 'value');

This is useful as the value is usually the variable when setting a cookie whereas the other cookie crumbs are usually fixed.
This is useful as the value of the cookie is usually the variable whereas the other cookie crumbs are usually fixed.
### `void Crumble#removeCookie(Object crumbs)`
Removes a cookie from the document by forcing it to immediately expire.
Removes a cookie by forcing it to immediately expire. The cookie crumbs you can provide are:
The cookie crumbs you can provide are:
* `name` (string, required) - The name of the cookie.
* `path` (string, optional) - The path of which the cookie will be removed from. Defaults to the current path.
* `domain` (string, optional) - The (sub)domain of which the cookie will be removed from. When set to `.` the cookie will be removed from the current root domain. 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 removed in a first-party context. This is subject to client support. Defaults to `false`.
* `name` (String, required) - The name of the cookie.
* `path` (String, optional) - The path of which the cookie will be removed from. Defaults to the path of the document.
* `domain` (String, optional) - The (sub)domain of which the cookie will be removed from. The domain can only be a domain that the document is in, however cookies can cross subdomains. When set to `.` the cookie will be removed from the root domain of the document. Defaults to the domain of the document (i.e. the value of `document.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`.
Example usage:

@@ -85,3 +88,3 @@

It's available through the Node Package Manager (NPM), so you can install it like so:
This project is available through the Node Package Manager (NPM), so you can install it like so:

@@ -92,11 +95,13 @@ ``` sh

This is a `commonjs` module; so you will need to use a bundler.
## Development
This project doesn't have much of a build process. It does have tests though; which you can run with Grunt like so:
This project doesn't have much of a build process. It does have tests though; which you can run like so:
``` sh
grunt test
npm test
```
This also runs code quality checks using ESLint. Please refer to the `.eslintrc` file to familiar yourself with the rules.
This also runs code quality checks using ESLint. Please refer to the `.eslintrc` files to familiar yourself with the rules.

@@ -103,0 +108,0 @@ ## License

@@ -1,7 +0,3 @@

/* eslint-env browser */
'use strict';
// --------------------------------------------------------
/**

@@ -54,3 +50,3 @@ * The reserved name of the test cookies created by Crumble.

*/
const ROOT_DOMAIN = '.';
const ROOT_DOMAIN_SHORTHAND = '.';

@@ -60,3 +56,3 @@ // --------------------------------------------------------

/**
* Retrieves the domain of the current document.
* Retrieves the current domain.
*

@@ -67,3 +63,3 @@ * @private

*
* @returns {String} The current domain.
* @return {String} The current domain.
*

@@ -80,5 +76,5 @@ * @memberof Crumble

/**
* Retrieves the root domain of the current document.
* Retrieves the current root domain.
*
* For example if the document is on domain `a.b.c.com` the root domain will be `c.com`.
* For example if the current domain is `a.b.c.com` the root domain would be `c.com`.
*

@@ -89,3 +85,3 @@ * @private

*
* @returns {String} The current root domain.
* @return {String} The current root domain.
*

@@ -102,4 +98,3 @@ * @memberof Crumble

setCookie(
{
setCookie({
domain, name : TEST_COOKIE_NAME

@@ -114,4 +109,3 @@ });

removeCookie(
{
removeCookie({
domain, name : TEST_COOKIE_NAME

@@ -130,3 +124,3 @@ });

*
* @returns {Boolean} `true` if cookies are enabled, otherwise `false`.
* @return {Boolean} `true` if cookies are enabled, otherwise `false`.
*

@@ -147,3 +141,3 @@ * @memberof Crumble

*
* @returns {Boolean} `true` if the cookie exists, otherwise `false`.
* @return {Boolean} `true` if the cookie exists, otherwise `false`.
*

@@ -166,5 +160,5 @@ * @param {String} name The name of the cookie to test the presence of.

*
* @returns {String} The value of the cookie or `null` if the cookie doesn't exist.
* @return {String} The value of the cookie or `null` if the cookie doesn't exist.
*
* @param {String} name The name of the cookie to read..
* @param {String} name The name of the cookie to read.
*

@@ -182,3 +176,3 @@ * @memberof Crumble

return decodeURIComponent( cookie[1] );
return decodeURIComponent(cookie[1]);
}

@@ -196,3 +190,7 @@

* {
* name : "name", value : "value", domain : "a.domain.com", path : "/a/document/path", secure : false
* name : "name",
* value : "value",
* domain : "a.domain.com",
* path : "/an/example/path",
* secure : false
* });

@@ -206,3 +204,6 @@ * ```

* {
* name : "name", domain : "a.domain.com", path : "/a/document/path", secure : false
* name : "name",
* domain : "a.domain.com",
* path : "/an/example/path",
* secure : false
*

@@ -214,3 +215,3 @@ * }, 'value');

*
* @instance
* @static
*

@@ -222,7 +223,7 @@ * @param {Object} crumbs The crumbs that make the cookie.

* @param {Date|String|Number} [crumbs.expires] The expiry date of the cookie, if omitted, the cookie will expire at the end of the session. You can provide a date object, date string or a timestamp. When provided a timestamp equivalent to `Infinity` the cookie will be set to expire with date: `31 Dec 9999 23:59:59 GMT`.
* @param {String} [crumbs.path] The path of which the cookie will be created. Defaults to the path of the document.
* @param {String} [crumbs.domain] The (sub)domain of which the cookie will be created. The domain can only be a domain that the document is in, however cookies can cross subdomains. When set to `.` the domain will be set to the root domain of the document. Defaults to the domain of the document (i.e. the value of `document.domain`).
* @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. When set to `.` the domain will be set to the current root domain. 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} [cookieValue] The value of the cookie. When omitted `crumbs.value` will be used.
* @param {String} [value = crumbs.value] The value of the cookie.
*

@@ -233,5 +234,5 @@ * @throws {TypeError} When `crumbs.name` is `null` or `undefined`.

*/
function setCookie (crumbs, cookieValue)
function setCookie (crumbs, value = crumbs.value)
{
let { name = null, value = null, age, expires, path, domain, secure = false, firstPartyOnly = false } = crumbs;
let { name = null, age, expires, path, domain, secure = false, firstPartyOnly = false } = crumbs;

@@ -245,14 +246,4 @@ if (name === null)

// When `cookieValue` is only `undefined`, then use the
// `value` crumb.
if (cookieValue !== undefined)
{
value = cookieValue;
}
// Value.
//
// To keep things tidy, ensure the value is omitted if it
// results in `null`.
if (value !== null)
if (typeof value !== 'undefined' && value !== null)
{

@@ -269,13 +260,5 @@ cookie += encodeURIComponent(value);

// Domain.
//
// If the provided domain matches the document domain, do
// not bother adding the attribute.
//
// This is to support domains like `localhost`, which when
// explicitly set causes the cookie not to be written.
let domainOfTheDocument = getDomain();
if (domain && domain !== domainOfTheDocument)
if (domain && domain !== getDomain())
{
if (domain === ROOT_DOMAIN)
if (domain === ROOT_DOMAIN_SHORTHAND)
{

@@ -298,4 +281,2 @@ domain = getRootDomain();

{
// Determine the number of seconds between now and the
// maximum allowed expiry date.
age = MAXIMUM_EXPIRY_DATE.getTime() - Date.now();

@@ -322,4 +303,8 @@ }

if (expires.toString() !== 'Invalid Date')
if (expires.toString() === 'Invalid Date')
{
throw new TypeError('The cookie expiry must represent a valid date.');
}
else
{
age = expires.getTime() - Date.now();

@@ -333,6 +318,2 @@

}
else
{
throw new TypeError('The cookie expiry must represent a valid date.');
}
}

@@ -369,8 +350,8 @@

*
* @instance
* @static
*
* @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 path of the current document.
* @param {String} [crumbs.domain] The (sub)domain of which the cookie will be removed from. The domain can only be a domain that the document is in, however cookies can cross subdomains. When set to `.` the cookie will be removed from the root domain of the document. Defaults to the domain of the document (i.e. the value of `document.domain`).
* @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. When set to `.` the cookie will be removed from the current root domain. Defaults to the current domain.
* @param {Boolean} [crumbs.secure = false] Indicates whether the cookie should only be removed over HTTPS connections.

@@ -381,8 +362,5 @@ * @param {Boolean} [crumbs.firstPartyOnly = false] Indicates whether the cookie should only be sent in a first-party context. This is subject to client support.

*/
function removeCookie (crumbs)
function removeCookie ({ name, path, domain, secure, firstPartyOnly })
{
let { name, path, domain, secure, firstPartyOnly } = crumbs;
setCookie(
{
setCookie({
name, path, domain, secure, firstPartyOnly, age : -3600000

@@ -389,0 +367,0 @@ });

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