├── README.md ├── LICENSE └── Cookies.js /README.md: -------------------------------------------------------------------------------- 1 |
2 |

JS Cookies Lib

3 | 4 |

About

5 | It is lightweight and easy Lib for manage Cookies in Java Script. 6 | 7 |

Usage

8 | 1. Download Cookies.js from Released Branch and add to your program.
9 | 2. Include Functions from Cookies.js to your javascript file. (your file need be type="module") 10 |
import { Cookies, CreateCookie, ChangeCookie, LoadCookies, ReLoadCookies, DeleteCookie } from "./Cookies.js"; 11 |
12 | 3. To Load Cookie use LoadCookies() or ReLoadCookies() functions.
13 | 4. For Read Data from cookie just Load Cookies and use Cookies[Name].
14 | 5. For Adding new Cookie or change cookie use CreateCookie(Name, Data, LifeTimeInMiliSeconds) or ChangeCookie(Name, Data, LifeTimeInMiliSeconds);
15 | 6. To delete Cookie use DeleteCookie(Name);
16 | 17 |

Features

18 | 19 | * Load Cookies 20 | * Reload Cookies 21 | * Get Data from Cookies 22 | * Create new Cookie 23 | * Change Cookie 24 | * Delete Cookies 25 | 26 |
27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Daynlight 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Cookies.js: -------------------------------------------------------------------------------- 1 | //Data 2 | var Cookies = []; 3 | 4 | //Functions 5 | function ReLoadCookies(){ 6 | Cookies = []; 7 | var Data = decodeURIComponent(document.cookie).split(";"); 8 | 9 | Data.forEach(element => { 10 | var Temp = element.split("="); 11 | Cookies[Temp[0].replaceAll(' ','')] = Temp[1]; 12 | }); 13 | } 14 | function LoadCookies(){ReLoadCookies()} 15 | 16 | function CreateCookie(Name, Data, LifeTimeInMiliSeconds){ 17 | var LifeDate = new Date(); 18 | LifeDate.setTime(LifeDate.getTime() + LifeTimeInMiliSeconds); 19 | var NewCookie = `${Name}=${Data}; expires=${LifeDate.toUTCString() }; path=/`; 20 | 21 | Cookies[Name] = Data; 22 | document.cookie = NewCookie; 23 | } 24 | function ChangeCookie(Name, Data, LifeTimeInMiliSeconds){ CreateCookie(Name, Data, LifeTimeInMiliSeconds) }; 25 | 26 | function DeleteCookie(Name){ 27 | var LifeDate = new Date(); 28 | LifeDate.setTime(LifeDate.getTime() * 0); 29 | var DeletedCookie = `${Name}=""; expires=${LifeDate.toUTCString()}; path=/`; 30 | 31 | Cookies[Name] = undefined; 32 | document.cookie = DeletedCookie 33 | console.log(Cookies); 34 | } 35 | 36 | //Export 37 | export {Cookies, CreateCookie, ChangeCookie, LoadCookies, ReLoadCookies, DeleteCookie}; --------------------------------------------------------------------------------