0.1.2 • Published 3 years ago

@m4rch/cookie v0.1.2

Weekly downloads
43
License
Unlicense
Repository
github
Last release
3 years ago

@m4rch/cookie

even though way overdone i wanted to make my own package to manage cookies in html

Installation

use npm

$ npm i @m4rch/cookie

or my own cdn

<script src="https://cdn.m4rch.xyz/cookie.js"></script>

if you want to include it into jquery you can either use a cdn for both

<script src="https://cdn.m4rch.xyz/jquery.js"></script>

or

<script src="https://cdn.m4rch.xyz/cookie-jq.js"></script>

if you want to include jquery via another cdn

documentation

if you are using one of the jquery variants then you are going to have to use $.cookie instead of cookie

.set(name, value, options?)

cookie.set("name", "value")

values automatically get encoded and decoded using encodeURIComponent and decodeURIComponent, respectively

JSON objects and arrays are automatically stringified with JSON.stringify() if they are passed as a value, null and undefined do not get assigned

options that can be passed are path and/or expires (in days)

cookie.set("name", "value", { path: "/", expires: 365 })

the default for path is / and for expires is "", resulting in a session cookie

.get(name?, options?)

for the value of a specific cookie use

cookie.get("name")

values get automatically decoded using decodeURIComponent

JSON objects and arrays are automatically parsed by JSON.parse(), if you don't want that use

cookie.get("name", { nojson: true })

for an array of every key-value pair use

cookie.get()

or if you want an object of every cookie use

cookie.get({ json: true })

.remove(name, options?)

cookie.remove("name")

if you want to specify a specific path use

cookie.remove("name", { path: "" })

the default for path is /

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago