1.0.3 • Published 6 years ago
@en.ahmed.mk/cookie-man v1.0.3
CookieMan
Control cookies like a pro.
Table of Contents :pushpin:
Simple code :pushpin:
// the simple way.
cookieman.setSimple('myName', 'Ahmed');
// the advanced way
cookieman
.fromName('myName')
.fromContent('Ahmed')
.fromPath('/')
.saveChanges();
Installation :pushpin:
npm install @en.ahmed.mk/cookie-man
Features :pushpin:
- save simple cookie with name and value
- save string, number, boolean or object as base64 encode (since v1.0.3)
- get decoded string from base64 encoded content (since v1.0.3)
- get decoded object from base64 encoded content (since v1.0.3)
- save advanced cookie with the following options
- name
- value ( object friendly )
- time span from minutes, hours, days, weeks
- specific path
- specific domain
- get cookie as string
- get cookie as object
- check cookie existence by name
- check if cookie have specific value
- call function for one time based on saved cookie
- delete cookie by name
- clear all cookies
- compatible with es5 and es6
Examples :pushpin:
es5
var CookieMan = require("@en.ahmed.mk/cookie-man").CookieMan,
_cookieman = new CookieMan();
// set simple cookie
_cookieman.setSimple("name","value");
// set simple cookie from object
var myObject = {
a: 1,
b: 2
};
_cookieman.setSimple("name", myObject);
// get it as string
_cookieman.get("name");
// get it as object
_cookieman.getObject("name");
// set advanced cookie
_cookieman
.fromName("name")
.fromContent("myContent") // accept any type
.formMinutes(5) // expires after 5 minutes
.fromPath("/")
.fromDomain("example.io")
.saveChanges();
es6
import { CookieMan } from '@en.ahmed.mk/cookie-man';
const _cookieman = new CookieMan();
// set simple cookie
_cookieman.setSimple('name','value');
// set simple cookie from object
const myObject = {
a: 1,
b: 2
};
_cookieman.setSimple('name', myObject);
// get it as string
_cookieman.get('name');
// get it as object
_cookieman.getObject('name');
// set advanced cookie
_cookieman
.fromName('name')
.fromContent('myContent') // accept any type
.formMinutes(5) // expires after 5 minutes
.fromPath('/')
.fromDomain('example.io')
.saveChanges();
Updates :rocket:
since v1.0.3
// get it as string
CookieMan.getFromBase64("name");
// get it as object
CookieMan.getObjectFromBase64("name");
// set it as Base64
CookieMan
.fromName("name")
.fromContent("myContent") // accept objects
.toBase64Content()
.saveChanges();
For list of available code see the Wiki
Testing :pushpin:
To test this module just do these simple steps
git clone https://github.com/AhmedMKamal/cookie-man.git
make sure you have http-server
installed, if not run
npm install -g http-server
In the directory of the repo run
npm install && npm run test
You'll end up with a page like this
files structure
.
├── \_\_test__
│ ├── scripts
│ │ ├── bundle.js
│ │ └── test.js
│ └── index.html
├── src
│ ├── base64.ts
│ ├── cookie.model.ts
│ └── index.ts
├── package.json
├── tsconfig.json
├── tslint.json
└── ...
Contributing :pushpin:
To contribute this repo
you can Fork this repo!
or run
git clone https://github.com/AhmedMKamal/cookie-man.git
open your IDE
start coding
One last thing this module built for everyone and anyone, if you see something will make it better just do it.