Package Exports
- chocolata
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chocolata) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 .
