@convertdigital/gamma-cookie
Advanced tools
+36
| ## Getting started | ||
| gamma-cookie is a JavaScript utility that provides as a fast and efficient way to get and set browser cookies. | ||
| ### Usage | ||
| #### setCookie() | ||
| ```javascript | ||
| const COOKIE_NAME = "recently_viewed"; | ||
| const COOKIE_SKUS_NAME = "recently_viewed_skus"; | ||
| const EXPIRE_TIME = 60 * 60 * 24 * 7; // set cookie expire time to 7 days | ||
| const MAX_LIMIT = 10; | ||
| const setRecentlyProducts = (handle) => { | ||
| let recentlyViewed = getRecentlyProducts(); | ||
| // Remove current product if it exists | ||
| recentlyViewed = recentlyViewed.filter((i) => i !== handle); | ||
| // Push new product to start of list | ||
| recentlyViewed.unshift(handle); | ||
| const newCookieValue = recentlyViewed.slice(0, MAX_LIMIT).join("|"); | ||
| setCookie(COOKIE_NAME, newCookieValue, { expires: EXPIRE_TIME }); | ||
| }; | ||
| ``` | ||
| #### getCookie() | ||
| ```javascript | ||
| const getRecentlyProducts = () => { | ||
| const cookieValue = getCookie(COOKIE_NAME) || ""; | ||
| return cookieValue.length ? cookieValue.split("|") : []; | ||
| }; | ||
| ``` |
+2
-2
| { | ||
| "name": "@convertdigital/gamma-cookie", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "This package acts as a utility to provide functionality with getting, and setting cookies.", | ||
@@ -16,2 +16,2 @@ "main": "index.ts", | ||
| "homepage": "https://bitbucket.org/convert/gamma-cookie#readme" | ||
| } | ||
| } |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
2153
86.08%3
50%1
-50%37
Infinity%