New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cross-cookie

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cross-cookie

Universal cookie API for Browsers and React Native.

0.0.9
latest
Source
npm
Version published
Weekly downloads
1
-75%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

cookie

FAQs

Package last updated on 03 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts