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.0 to 2.5.1

2

lib/cookie/index.js

@@ -58,3 +58,3 @@ /**

return store[name] || null;
return null;
}

@@ -61,0 +61,0 @@ /**

@@ -13,3 +13,3 @@ # cookie

The following methods are provided:
## The following methods are provided:

@@ -23,1 +23,9 @@ - `read(name)`: Read the cookie with the given name.

- `remove(name)`: Delete the cookie with the given name.
## Usage with `cookieConsent`:
- Call `cookieConsent.initConsent` before calling `cookie.create`.
- Cookies will get created only if the consent for that cookie is true.
- Each cookie will automatically subscribe to `enable` and `disable` consent events for that cookie.
- Cookie will get set when consent is `true`.
- Cookie will get removed when consent is `false`.
var cookieConsent = (function () {
var init = false;
var consentDisabled = true;
var store = {};
var subscribers = {};
var events = ['add', 'enable', 'disable'];
var events = ['add', 'enable', 'disable', 'change'];
/**

@@ -39,6 +40,11 @@ * _publish: Calls subscriber callbacks

_publish(consentKey, 'disable', consentValue);
_publish(consentKey, 'change', consentValue);
}
else {
else if (oldValue === false) {
_publish(consentKey, 'enable', consentValue);
_publish(consentKey, 'change', consentValue);
}
else {
_publish(consentKey, 'change', consentValue);
}
}

@@ -55,8 +61,23 @@ }

/**
* Get consent disabled
* @returns Boolean
*/
function getConsentDisabled () {
return consentDisabled
}
/**
* initConsent: Initialize the consent store
* @param {Object} consent Consent object
* @param {Boolean} disable Disable consent
* @returns Boolean
*/
function initConsent (consent) {
function initConsent (consent, disable) {
if (!init) {
consentDisabled = !!disable;
if (consentDisabled) {
init = true;
return true;
}
if (!(consent && !Array.isArray(consent) && typeof consent === 'object')) {

@@ -87,2 +108,6 @@ throw new TypeError('cookieConsent (init): consent should be an object.');

function getConsent (consentKey) {
if (consentDisabled) {
return true;
}
return store[consentKey];

@@ -96,3 +121,3 @@ }

function setConsent (consent) {
if (init) {
if (init && !consentDisabled) {
if (!(consent && !Array.isArray(consent) && typeof consent === 'object')) {

@@ -157,2 +182,3 @@ throw new TypeError('cookieConsent (setConsent): consent should be an object.')

getConsent: getConsent,
getConsentDisabled: getConsentDisabled,
setConsent: setConsent,

@@ -159,0 +185,0 @@ subscribe: subscribe

@@ -8,6 +8,10 @@ # cookieConsent

// Initialize
/**
* 2nd parameter is to disable/enable consent mechanism.
* Passing true will disable the consent mechanism.
*/
cookieConsent.initConsent({
cookie1: false,
cookie2: true
});
}, false);

@@ -26,2 +30,3 @@ // Set cookie consent

// Valid events that can be subscribed to are 'add', 'enable', 'disable', and 'change'
// Subscribe to consent 'disable' event. Triggers when a cookie consent is set to false

@@ -32,2 +37,5 @@ var event = cookieConsent.subscribe('cookie3', 'disable', function (data) {});

event.unsubscribe();
// Get cookie consent disabled/enabled value.
cookieConsent.getConsentDisabled();
```
{
"name": "bv-ui-core",
"version": "2.5.0",
"version": "2.5.1",
"license": "Apache 2.0",

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

@@ -43,2 +43,3 @@ ![](https://travis-ci.org/bazaarvoice/bv-ui-core.svg)

- [cookie](./lib/cookie)
- [cookieConsent](./lib/cookieConsent)
- [cssLoadChecker](./lib/cssLoadChecker)

@@ -45,0 +46,0 @@ - [date.now](./lib/date.now)

@@ -75,3 +75,3 @@ /**

var events = ['add', 'enable', 'disable'];
var events = ['add', 'enable', 'disable', 'change'];
expect(test3).to.throw(TypeError, 'cookieConsent (subscribe): event name should be one of ' + events.join(', ') + '.');

@@ -78,0 +78,0 @@

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