How to use the js-cookie.withConverter function in js-cookie

To help you get started, we’ve selected a few js-cookie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github meetup / meetup-web-platform / packages / mwp-tracking-plugin / src / util / clickState.js View on Github external
import JSCookie from 'js-cookie';

/*
 * This module provides utilities for managing click tracking data in a cookie
 */

export const COOKIE_NAME = 'click-track'; // must remain in sync with Meetup Classic implementation

const BrowserCookies = JSCookie.withConverter({
	read: value => value,
	write: value =>
		encodeURIComponent(value).replace(
			/[!'()*]/g,
			c => `%${c.charCodeAt(0).toString(16)}`
		),
});

export const setClickCookie = clickTracking => {
	const domain = window.location.host.replace(/[^.]+/, ''); // strip leading subdomain, e.g. www or beta2
	const cookieVal = JSON.stringify(clickTracking);
	BrowserCookies.set(COOKIE_NAME, cookieVal, { domain });
};
export const getClickCookie = () => BrowserCookies.get(COOKIE_NAME);

export const appendClick = clickData =>
github meetup / meetup-web-platform / packages / mwp-tracking-plugin / src / util / clickState.js View on Github external
import JSCookie from 'js-cookie';

/*
 * This module provides utilities for managing click tracking data in Redux
 * state an saving that data to a browser cookie
 */

export const COOKIE_NAME = 'click-track'; // must remain in sync with Meetup Classic implementation

const BrowserCookies = JSCookie.withConverter({
	read: value => value,
	write: value =>
		encodeURIComponent(value).replace(
			/[!'()*]/g,
			c => `%${c.charCodeAt(0).toString(16)}`
		),
});

export const setClickCookie = clickTracking => {
	const domain = window.location.host.replace(/[^.]+/, ''); // strip leading subdomain, e.g. www or beta2
	const cookieVal = JSON.stringify(clickTracking);
	BrowserCookies.set(COOKIE_NAME, cookieVal, { domain });
};

export const CLICK_TRACK_ACTION = 'CLICK_TRACK';
export const CLICK_TRACK_CLEAR_ACTION = 'CLICK_TRACK_CLEAR';