Cookie Reader
An ES6 super tiny read-only cookie reader.
Literally, it only reads the cookie
Install
npm i cookie-reader
Example
// by default the parse method will use `document.cookie`// parses the cookie into a {"key":"value"} Objectconst cookie = Cookie // get an item from the cookieconst JWT_Token = Cookie
Methods
parse
Accepts 1 argument as a String
. Defaults to document.cookie
const cookieString = "some_key=ABC1234; key_2=123456;key_3=asdfg"Cookie/* * { some_key: "ABC1234", key_2: "123456", key_3: "asdfg" }*/
getItem
Accepts 2 arguments
key
: required keyString
, representing the item name from the cookie.cookie
: Optional cookieString
you want to get the key from ( defaults todocument.cookie
)
documentcookie = "some_key=ABC1234; key_2=123456;key_3=asdfg"Cookie// 123456 // OR const anotherCookieString = "key_1=A;key_2=12341"Cookie// 12341