cross-cookie

0.0.9 • Public • Published

cross-cookie Build Status NPM Version License: MIT

Universal cookie for browsers and React Native. The scenario that cross-cookie really shines is when the same javascript codebase needs to run on different platforms.

  • Platform agnostic: browsers or React Native
  • Simple interface: no instantiation, no configuration and no extra dependency

Table of Contents


Install

npm install --save cross-cookie
// Using ES6 modules
import cookie from 'cross-cookie';
 
// Using CommonJS modules
const cookie = require('cross-cookie');

The UMD build is also available on unpkg:

<script src="//unpkg.com/cross-cookie/dist/cross-cookie.js"></script>

This adds the "cookie" object to the window.


Usage

const cookie = require('cross-cookie');
 
// Store current user
cookie.set('user', { name: 'Marcus' })
  .then(() => console.log('cookie set!'));
 
// Store multiple users
cookie.set({
    user1: { name: 'Marcus' },
    user2: { name: 'John' }
  })
  .then(() => console.log('cookies set!'));
 
// Get current user
cookie.get('user')
  .then(value => console.log(value));
 
// Get multiple users
cookie.getAll()
  .then(cookies => {
    console.log(cookies.user);
    console.log(cookies.user1);
    console.log(cookies.user2);
  });
 
// Remove current user
cookie.remove('user')
  .then(() => console.log('cookie removed!'));
 
// Clear all keys
cookie.clearAll()
  .then(() => console.log('all cookies removed!'));

⚠️ Warning: If you're in an environment that doesn't support Promises such as Internet Explorer, you must install an ES6 Promise compatible polyfill. es6-promise is suggested.

Demo

Try it out on the JSFiddle playground ➡️.

Supported environments

  • React-Native
  • Browsers
    • Chrome
    • Firefox
    • Safari 6.1+
    • Internet Explorer 10+

License

cross-cookie is licenced under the MIT license © Leonardo Quixadá

Author

@lquixada
@lquixada

Package Sidebar

Install

npm i cross-cookie

Weekly Downloads

3

Version

0.0.9

License

MIT

Last publish

Collaborators

  • lquixada