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

chocolata

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chocolata

Cookies Management in the browser (document.cookie) which supports complex data structure (objects) not only Strings

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status

Chocolata JS LOGO

Overview :

An Javascript Client-side API that handles adding, getting & removing cookies to/from document.cookie.

It handles also complex data structure. Indeed, You can persist not only String but also Objects in document.cookie.

Install

npm install chocolata --save;

Example :

NPM environment :

import {getItem, setItem, removeItem} from 'chocolata';

setItem('token', '1234');
// document.cookie ==> "token=1234"

setItem('otherToken', '5678')
// document.cookie ==> "token=1234; otherToken=5678"

//--- Handle Objects ---

setItem('userInfo', {
  firstName: 'Ahmed',
  lastName: 'Toumi',  
});

// "token=1234; otherToken=5678; userInfo={"firstName":"Ahmed","lastName":"Toumi"}"

const {firstName, lastName} = getItem('userInfo');
console.log(`Welcome back ${firstName} ${lastName} !`)

Non-NPM environment:

In this case you need to import the script as CDN.

Also, examples above are still valid. However , instead of import .. , window.Chocolata is the namespace of this library:

<script src="https://cdn.rawgit.com/abdennour/chocolata/39513fa4/cdn/chocolata-latest.min.js"></script>

<script>

  Chocolata.setItem('userInfo', {
    firstName: 'Ahmed',
    lastName: 'Toumi',  
  });

  // "token=1234; otherToken=5678; userInfo={"firstName":"Ahmed","lastName":"Toumi"}"

  const {firstName, lastName} = Chocolata.getItem('userInfo');

  console.log(
    `Welcome back ${firstName} ${lastName} !`
  )
</script>

License:

MIT .

Keywords

FAQs

Package last updated on 19 Aug 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

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