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

bv-ui-core

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bv-ui-core - npm Package Compare versions

Comparing version 2.5.2 to 2.6.0

8

lib/cookie/index.js

@@ -82,2 +82,10 @@ /**

}
cookieConsent.subscribe(name,'add',function (consent) {
if (consent) {
createCookie(name,value,days,domain,secure);
}
else {
removeCookie(name,domain)
}
})

@@ -84,0 +92,0 @@ cookieConsent.subscribe(name, 'enable', function () {

2

lib/cookie/README.md

@@ -8,3 +8,3 @@ # cookie

cookie.write('RememberMe', '1', 365);
cookie.create('RememberMe', '1', 365);
console.log(cookie.read('RememberMe')); // '1'

@@ -11,0 +11,0 @@ cookie.remove('RememberMe');

@@ -7,2 +7,5 @@ var cookieConsent = (function () {

var events = ['add', 'enable', 'disable', 'change'];
var storeCallbacks = {};
/**

@@ -21,3 +24,15 @@ * _publish: Calls subscriber callbacks

}
/**
* _publishStore: calls Callbacks with the store object passed
*/
function _publishStore () {
if (Object.values(storeCallbacks).length > 0) {
Object.values(storeCallbacks).forEach(function (callback) {
callback(Object.assign({}, store));
})
}
}
/**
* _set: Set store data

@@ -61,3 +76,12 @@ * @param {String} consentKey Consent key

}
/**
* _unsubscribeStore: Unsubscribes subscribers from the consent store
*/
function _unsubscribeStore () {
if (storeCallbacks[this.key]) {
delete storeCallbacks[this.key];
}
}
/**
* Get consent disabled

@@ -125,2 +149,3 @@ * @returns Boolean

}
var store
var keys = Object.keys(consent);

@@ -130,2 +155,6 @@ for (var i = 0; i < keys.length; i++) {

}
var storeCopy=Object.assign({},store)
if (JSON.stringify(storeCopy)!==JSON.stringify(store)) {
_publishStore()
}
return true;

@@ -180,2 +209,15 @@ }

function subscribeToConsentStore (callback) {
if (typeof callback !== 'function') {
throw new TypeError('cookieConsent (subscribeToConsentStore): callback should be a function.');
}
var key = Math.random().toString(36).substr(2, 5);
storeCallbacks[key] = callback;
return {
unsubscribe: _unsubscribeStore.bind({ key: key })
}
}
return {

@@ -186,3 +228,4 @@ initConsent: initConsent,

setConsent: setConsent,
subscribe: subscribe
subscribe: subscribe,
subscribeToConsentStore: subscribeToConsentStore
};

@@ -189,0 +232,0 @@ })();

@@ -33,2 +33,5 @@ # cookieConsent

// Subscribe to the store change event. The latest consent store object is passed as parameter to the callback function
var event = subscribeToConsentStore(function (store){});
// Unsubscribe events

@@ -35,0 +38,0 @@ event.unsubscribe();

{
"name": "bv-ui-core",
"version": "2.5.2",
"version": "2.6.0",
"license": "Apache 2.0",

@@ -5,0 +5,0 @@ "description": "Bazaarvoice UI-related JavaScript",

@@ -87,5 +87,34 @@ /**

}
expect(test5()).to.be.an('object');
});
it('cookieConsent.subscribeToConsentStore', function () {
// Error checks - Correct errors are thrown
function test6 () {
cookieConsent.subscribeToConsentStore('Callback')
}
expect(test6).to.throw(TypeError,'cookieConsent (subscribeToConsentStore): callback should be a function.');
// Subscriber creation test - The subscription gets created correctly
function test7 () {
return cookieConsent.subscribeToConsentStore(function () {});
}
expect(test7()).to.be.an('object');
// Event listener test - The subscriber callback fires on store change
var fn = sinon.spy()
function test8 () {
cookieConsent.subscribeToConsentStore(fn)
cookieConsent.setConsent({ cookie4: true })
}
test8 ()
sinon.assert.calledOnce(fn)
// Unsubscribe test - Should be able to unsubscribe successfully (Should not fire the callback after unsubscription)
var fn2 = sinon.spy()
function test9 () {
var event = cookieConsent.subscribeToConsentStore(fn2)
event.unsubscribe()
cookieConsent.setConsent({ cookie5: true })
}
test9()
sinon.assert.notCalled(fn2)
});
});
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