Learn Ethical Hacking from DROP Organization

A simple, lightweight JavaScript API for handling cookies

 


A simple, lightweight JavaScript API for handling cookies


Works in all browsers

Accepts any character

Heavily tested

No dependency

Supports ES modules

Supports AMD/CommonJS

RFC 6265 compliant

Useful Wiki

Enable custom encoding/decoding

< 800 bytes gzipped!


πŸ„ΈπŸ„½πŸ…‚πŸ…ƒπŸ„°πŸ„»πŸ„»πŸ„ΈπŸ…‚πŸ„°πŸ…ƒπŸ„ΈπŸ„ΎπŸ„½ & πŸ…πŸ…„πŸ„½ :


1) git clone https://gplinks.co/ro9b


2) $ npm i js-cookie


3) to use 


Note the different extensions: .mjs denotes the ES module, whereas .js is the UMD one.


Example for how to load the ES module in a browser:


<script type="module" src="/path/to/js.cookie.mjs"></script>

<script type="module">

  import Cookies from '/path/to/js.cookie.mjs'


  Cookies.set('foo', 'bar')

</script>


5) Not all browsers support ES modules natively yet. For this reason the npm package/release provides both the ES and UMD module variant and you may want to include the ES module along with the UMD fallback to account for this:


<script type="module" src="/path/to/js.cookie.mjs"></script>

<script nomodule defer src="/path/to/js.cookie.js"></script>

Here we're loading the nomodule script in a deferred fashion, because ES modules are deferred by default. This may not be strictly necessary depending on how you're using the library.

About Roshan Burnwal

Roshan Burnwal
Recommended Posts × +

0 Comments: