How to use js-cookie - 10 common examples

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 flow-typed / flow-typed / definitions / npm / js-cookie_v2.x.x / flow_v0.38.x- / test_js-cookie-v2.x.x.js View on Github external
const otherCookie = Cookie.noConflict();

otherCookie.set('name', 'OtherCookie');


const cookieWithConverter = otherCookie.withConverter((value: string, name: string): string => {
    return value;
});

cookieWithConverter.defaults = {
    secure: true
};


// $ExpectError
Cookie.defaults = {
    secure: 1
};
github flow-typed / flow-typed / definitions / npm / js-cookie_v2.x.x / flow_v0.38.x- / test_js-cookie-v2.x.x.js View on Github external
Cookie.remove('version', {
    path: '/'
});

// $ExpectError
Cookie.removeCookie()

Cookie.set('data', {
    a: 1,
    b: 3
}, { secure: true });


// $ExpectError
Cookie.getJson();

const data: Object = Cookie.getJSON('data');


const otherCookie = Cookie.noConflict();

otherCookie.set('name', 'OtherCookie');


const cookieWithConverter = otherCookie.withConverter((value: string, name: string): string => {
    return value;
});

cookieWithConverter.defaults = {
    secure: true
};
github flow-typed / flow-typed / definitions / npm / js-cookie_v2.x.x / flow_v0.38.x- / test_js-cookie-v2.x.x.js View on Github external
// $ExpectError
Cookie.removeCookie()

Cookie.set('data', {
    a: 1,
    b: 3
}, { secure: true });


// $ExpectError
Cookie.getJson();

const data: Object = Cookie.getJSON('data');


const otherCookie = Cookie.noConflict();

otherCookie.set('name', 'OtherCookie');


const cookieWithConverter = otherCookie.withConverter((value: string, name: string): string => {
    return value;
});

cookieWithConverter.defaults = {
    secure: true
};


// $ExpectError
Cookie.defaults = {
    secure: 1
github flow-typed / flow-typed / definitions / npm / js-cookie_v2.x.x / flow_v0.38.x- / test_js-cookie-v2.x.x.js View on Github external
});

// $ExpectError
const v: string = Cookie.get('version');

const all: Object = Cookie.get();

// $ExpectError
Cookie.set(12, 'should fail');

Cookie.remove('version', {
    path: '/'
});

// $ExpectError
Cookie.removeCookie()

Cookie.set('data', {
    a: 1,
    b: 3
}, { secure: true });


// $ExpectError
Cookie.getJson();

const data: Object = Cookie.getJSON('data');


const otherCookie = Cookie.noConflict();

otherCookie.set('name', 'OtherCookie');
github strapi / strapi-sdk-javascript / src / lib / sdk.spec.ts View on Github external
test('Create an instance with existing token on cookies', t => {
  browserEnv(['window', 'document']);
  const Cookies = require('js-cookie');
  const globalAny: any = global;
  Cookies.set('jwt', 'XXX');
  // const CookieGet = sinon.spy(Cookies)

  const strapi = new Strapi('http://strapi-host', {
    localStorage: false
  });

  t.is(strapi.axios.defaults.headers.common.Authorization, 'Bearer XXX');
  // TODO: Mock Cookies
  // t.true(CookieGet.calledWith('jwt'));
  delete strapi.axios.defaults.headers.common.Authorization;
  delete globalAny.window;
});
github datenanfragen / website / src / error-handler.js View on Github external
function logError(event) {
    console.log('%cAn unexpected error occurred:', 'color: red; font-weight: bold;', event, 'Please submit reports via GitHub (https://github.com/datenanfragen/website/issues) or email (dev@datenanfragen.de).');
}

let debugging_enabled = false;
try {
    let cookie = require('js-cookie/src/js.cookie');
    debugging_enabled = !!cookie.get('debugging_enabled');
}
catch(e) {}

try {
    let preact = require('preact');
    let Modal = require('Components/Modal').default;
    let t  = require('Utility/i18n').default;

    window.addEventListener('error', event => {
        logError(event);

        // This is horrendous. It is however the easiest (and worryingly cleanest) way I see to achieve the intended result here as the (interesting) properties of the `Error` object are not enumerable and JSON.stringify() only encodes enumerable properties.
        let debug_info = JSON.parse(JSON.stringify(event, [ 'code', 'message', 'description', 'arguments', 'type', 'name', 'colno', 'filename', 'lineno', 'error', 'stack', 'enduser_message' ]));

        // It gets worse. Errors in Chrome have basically no information at all, not even a code or error type.
        // TODO: Since the Chrome debug info contains practically no information at all, we should probably include a note that users would need to manually copy the stack trace from the console in order for us to be able to do anything.
github yjx-passion / vue-element-admin / src / store / modules / app.js View on Github external
import Cookies from 'js-cookie'

const app = {
  state: {
    // 中英文
    language: Cookies.get('language') || 'zh',
    sidebar: {
      opened: !+Cookies.get('sidebarStatus')
    }
  },
  mutations: {
    TOGGLE_SIDEBAR: state => {
      if (state.sidebar.opened) {
        Cookies.set('sidebarStatus', 1)
      } else {
        Cookies.set('sidebarStatus', 0)
      }
      state.sidebar.opened = !state.sidebar.opened
    },
    // 中英文
    SET_LANGUAGE: (state, language) => {
      state.language = language
github owid / owid-grapher / site / client / runCookieNotice.tsx View on Github external
@action.bound onAccept() {
        // Set a cookie for 3 years
        Cookies.set(COOKIE_NAME, VERSION, { expires: 365 * 3 })
        this.accepted = true
    }
github FlowzPlatform / website-builder / src / views / UserDashboard.vue View on Github external
}).then(() => {
				localStorage.removeItem('current_sub_id')
				this.$session.remove('username')
				let location = psl.parse(window.location.hostname)
				location = location.domain === null ? location.input : location.domain
				Cookies.remove('auth_token', {domain: location})
				Cookies.remove('email', {domain: location})
				Cookies.remove('userDetailId', {domain: location})
				Cookies.remove('subscriptionId', {domain: location})

				this.isLoggedIn = false
				// this.$router.push('/login');
				window.location = '/login'
			}).catch(() => {
				// this.$message({
github bbc / simorgh / src / app / lib / analyticsUtils / index.js View on Github external
export const getAtUserId = () => {
  if (!onClient()) return null;

  const cookieName = 'atuserid';
  const cookie = Cookie.getJSON(cookieName);
  let val = pathOr(null, ['val'], cookie);
  const expires = 397; // expires in 13 months

  if (!cookie || !val) {
    val = uuid();
  }

  Cookie.set(cookieName, { val }, { expires, path: '/' });

  return val;
};