npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

logni-cookie.js

v0.1.5

Published

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

Downloads

9

Readme

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>
  • debugMode (boolean) - Debug ode
  • expires (string) - Specified it will expire at the end of session.
  • domain (string) - If not specified, this defaults to the host portion of the current document location. Contrary to earlier specifications, leading dots in domain names are ignored, but browsers may decline to set the cookie containing such dots. If a domain is specified, subdomains are always included. (example: 'example.com' or 'subdomain.example.com')
  • httponly (boolean) - cookie attribute can help to mitigate this attack by preventing access to cookie value through Javascript
  • secure (boolean) - Cookie to only be transmitted over secure protocol as https. Before Chrome 52, this flag could appear with cookies from http domains.
  • path (string) - If not specified, defaults to the current path of the current document location. The path must be absolute (see RFC 6265). For more information on how to use relative paths. (default is "/", example: /, /path)

Expired format (expires):

You can specify a time unit after a time value 'X', such as XY, Xm, Xw, Xd, XH, XM or XS to represent:

  • Y: years (alias: y)
  • m: months
  • W: weeks (alias: w)
  • d: days
  • H: hours (alias: h)
  • M: minutes
  • S: seconds (alias: s)

Methods

  • get() - read one cookie
  • set() - setting one cookie
  • del() - remove one cookie
  • gets() - read more cookies
  • sets() - setting more cookies
  • gets() - remove more cookies
  • getAll() - is a string containing a semicolon-separated list of all cookies (i.e. key=value pairs). Note that each key and value may be surrounded by whitespace (space and tab characters): in fact, RFC 6265 mandates a single space after each semicolon, but some user agents may not abide by this.

Variables

<script type="text/javascript">
  cookieName1 = 'TEST1str';
  cookieValue1 = 'aa11' + Math.random();

  cookieName2 = 'TEST2str';
  cookieValue2 = '22bb' + Math.random();

  cookieName3 = 'TEST3int';
  cookieValue3 = 111;

  const cookieName4 = 'TEST4float';
  const cookieValue4 = 123.456;

  const cookieNames = [cookieName1, cookieName2, cookieName3, cookieName4];
  let cookieNameSets = {}
  cookieNameSets[cookieName1] = cookieValue1;
  cookieNameSets[cookieName3] = cookieValue3;
  cookieNameSets[cookieName4] = cookieValue4;
</script>

Setting per one cookie

<script type="text/javascript">
  logniCookie.set(cookieName1, cookieValue1, '2H', 'differentdomain.com'); // 2hour
  logniCookie.set(cookieName1, cookieValue1, '3w'); // 3 week
  logniCookie.set(cookieName1, cookieValue1, '10S'); // 10 second
  logniCookie.set(cookieName1, cookieValue1, 10); // 10 second (alias for '10s')
</script>

or settings for more cookies

<script type="text/javascript">
  logniCookie.sets(cookieNameSets, 'differentdomain.com'); // 2hour
</script>

Read / remove cookie

<script type="text/javascript">
  logniCookie.get(cookieName); // one cookie
  logniCookie.gets(cookieNames); // more cookies
  
  logniCookie.del(cookieName); // one cookie
  logniCookie.dels(cookieNames); // more cookies
</script>

Test

test/cookie.html

Contribution

Pull Requests are very welcome.

Licence

GNU General Public License v3.0