0.1.1 • Published 5 years ago

lognijs-cookie v0.1.1

Weekly downloads
1
License
GPL3 <https://git...
Repository
github
Last release
5 years ago

npm version Codacy Badge Github Releases Build Status License: GPL v3

logni-cookie.js

Cookie javascript library for work with cookies (supporting LogNI logger)

How to install?

  • git (github)
  • node package manager

Install from Github

$ git clone https://github.com/erikni/logni-cookie.js.git
$ cd logni-cookie.js
$ npm install
$ npm run build

Install from Node package manager

$ npm i logni-cookie.js

Usage:

Add the local javascript file to head of HTML page:

<head>
  <script src="build/js/logni-cookie.min.js" type="text/javascript"></script>
</head>

ES5 support:

<head>
  <script src="build/js/logni-cookie-es5.min.js" type="text/javascript"></script>
</head>

or from Cloudflare CDN:

<head>
  <script src="https://live-jslib.logni.net/js/logni-cookie.min.js" type="text/javascript"></script>
</head>

Initialization

<script type="text/javascript">
  logniCookie.path = '/'; // set cookie path (optimal)
  logniCookie.domain = '.yourdomain.com'; // set cookie (sub)domain (optimal)
  logniCookie.expires = '10m'; // 10min expired (optimal)
</script>

Expired values:

You can specify a time unit after a time value 'X', such as Xy, Xmo, Xw, Xd, Xh or Xm, to represent:

  • y: years
  • mo: months
  • w: weeks
  • d: days
  • h: hours
  • m/mi: minutes
  • s: seconds

Set cookie

<script type="text/javascript">
  cookieName = 'TEST1';
  cookieValue = 'AbC' + Math.random();

  logniCookie.set(cookieName, cookieValue, '2h', 'differentdomain.com');
  logniCookie.set(cookieName, cookieValue, '3w');
</script>

Read / remove cookie

<script type="text/javascript">
  logniCookie.get(cookieName);
  
  logniCookie.del(cookieName);
</script>

Test

test/cookie.html

Contribution

Pull Requests are very welcome.

Licence

GNU General Public License v3.0