Socket
Socket
Sign inDemoInstall

@envato/cookie-consent

Package Overview
Dependencies
1
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.1.0

1

dist/index.d.ts

@@ -8,2 +8,3 @@ export declare enum Consent {

export declare const deferRun: (job: () => any, consent: Consent) => void;
export declare const checkCookieConsent: (CookieString: string | undefined, consent: Consent) => boolean;
export declare const consented: (consent: Consent) => boolean;

29

dist/index.js

@@ -42,21 +42,12 @@ "use strict";

}
exports.consented = function (consent) {
if (!(typeof window !== 'undefined')) {
exports.checkCookieConsent = function (CookieString, consent) {
if (!CookieString) {
return false;
}
// when cookiebot is avaiable use it
if (!!(window && window.Cookiebot && window.Cookiebot.consent)) {
return !!window.Cookiebot.consent[consent];
}
// manually parse cookie if Cookiebot is not avaiable
var CookieConsent = Cookies.get('CookieConsent');
if (!CookieConsent) {
return false;
}
// For user outside of targeted area
if (CookieConsent === '-1') {
if (CookieString === '-1') {
return true;
}
try {
var parsedCookieConsent = JSON.parse(CookieConsent.replace(/%2c/g, ',')
var parsedCookieConsent = JSON.parse(CookieString.replace(/%2c/g, ',')
.replace(/'/g, '"')

@@ -70,2 +61,14 @@ .replace(/([{\[,])\s*([a-zA-Z0-9_]+?):/g, '$1"$2":'));

};
exports.consented = function (consent) {
if (!(typeof window !== 'undefined')) {
return false;
}
// when cookiebot is avaiable use it
if (!!(window && window.Cookiebot && window.Cookiebot.consent)) {
return !!window.Cookiebot.consent[consent];
}
// manually parse cookie if Cookiebot is not avaiable
var CookieConsent = Cookies.get('CookieConsent');
return exports.checkCookieConsent(CookieConsent, consent);
};
//# sourceMappingURL=index.js.map

@@ -41,2 +41,33 @@ "use strict";

});
describe('parseCookieConsent()', function () {
var CookieString;
describe('when CookieConsent is undefined', function () {
it('returns false', function () {
expect(index_1.checkCookieConsent(CookieString, index_1.Consent.statistics)).toBe(false);
});
});
describe('when CookieConsent is found', function () {
beforeEach(function () {
CookieString = undefined;
});
it('returns true for user outside of targeted area', function () {
CookieString = '-1';
expect(index_1.checkCookieConsent(CookieString, index_1.Consent.statistics)).toBe(true);
});
it('returns false if issue parsing cookie', function () {
CookieString = '{bad: "json}';
expect(index_1.checkCookieConsent(CookieString, index_1.Consent.statistics)).toBe(false);
});
it('returns true if user has consented', function () {
CookieString =
"{stamp:'X',necessary:true,preferences:false,statistics:true,marketing:true,ver:1}";
expect(index_1.checkCookieConsent(CookieString, index_1.Consent.statistics)).toBe(true);
});
it('returns false if user has not consented', function () {
CookieString =
"{stamp:'X',necessary:true,preferences:false,statistics:false,marketing:true,ver:1}";
expect(index_1.checkCookieConsent(CookieString, index_1.Consent.statistics)).toBe(false);
});
});
});
describe('deferRun()', function () {

@@ -43,0 +74,0 @@ describe('cookiebot has no response', function () {

{
"name": "@envato/cookie-consent",
"version": "1.0.1",
"version": "1.1.0",
"description": "Some helper functions to deal with cookie-consent",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -27,2 +27,5 @@ # cookie-consent

// Manually parse and check the consent type in the CookieConsent cookie
checkCookieConsent(Cookies.get('CookieConsent'), Consent.statistics)
// Run function after consent

@@ -29,0 +32,0 @@ deferRun(() => {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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