Giter VIP home page Giter VIP logo

cookiejs.js's Introduction

cookiejs v1.0.1 Build Status Scrutinizer Code Quality Downloads over NPM per month

Set, get and remove cookies.

UMD and ES6 modules

We ship cookiejs.js primarly as a UMD module but there is also an ES6 module included.

using the ES6 module

import cookiejs from 'cookiejs.js'; //should import cookiejs.es.js
cookiejs.set('testcookie', 'testvalue');

Getting started

There is more than one way to use cookiejs.js inside your project. I prefer using npm for dependency management.

If you haven't used npm (Node Package manager) before, be sure to check out the Getting Started guide, as it explains how to install and use npm. Once you're familiar with that process, you may install the cookiejs.js module with this command inside your project:

npm install cookiejs.js --save-dev

Once the module has been installed, you may integrate that file into your build process (e.g concatenating and uglifying your JS with Grunt or whatever) since the --save-dev option is meant for development only.

Available functions inside cookiejs.js

cookiejs.set(sCookieName, sValue, oAttributes)

Sets a cookie.

// make sure cookiejs.js is already available when this code runs
cookiejs.set(
  // name of the cookie
  // default: undefined
  // required
  'captainObvious',
  // value of the cookie
  // default: ''
  'Thank you Captain Obvious, you just saved my life.',
  {
    // specifies allowed hosts to receive the cookie
    // default: the host of the current document location
    domain: '.eric-zieger.de',
    // indicates a URL path that must exist in the requested URL
    // default: '/',
    path: '/the-adventures-of-captain-obvious/',
    // cookie is deleted when the client shuts down (session-cookie) or when the expire date is reached
    // default: session-cookie
    expires: new Date('2040-01-01').toUTCString(),
    // cookie expires after a specific length of time in seconds
    // default: undefined
    'max-age': '3600',
    // cookie is only sent to the server with a encrypted request over the HTTPS protocol
    // default: false
    secure: true
  }
);

cookiejs.get(sCookieName)

Get the value of a cookie.

// make sure cookiejs.js is already available when this code runs

cookiejs.get('captainObvious');

// returns 'Thank you Captain Obvious, you just saved my life.'

cookiejs.remove(sCookieName, oAttributes)

Removes a cookie by overwriting the expires date. When a custom domain and/or path atrribute is used you have to hand them as object into this function. Else the cookie will not get removed.

// make sure cookiejs.js is already available when this code runs

cookiejs.remove('captainObvious', {
  domain: '.eric-zieger.de',
  path: '/the-adventures-of-captain-obvious/'
});

cookiejs.js's People

Contributors

thezieger avatar danopz avatar

Stargazers

Sven Bischoff avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

danopz

cookiejs.js's Issues

define function is not called properly

define(id?, dependencies?, factory); see: AMD API

Also requirejs says:

You can explicitly name modules yourself, but it makes the modules less portable -- if you move the file to another directory you will need to change the name. It is normally best to avoid coding in a name for the module and just let the optimization tool burn in the module names. (source)

Consider to not reassign parameter values

Scrutinizer considers to not reassign parameters since it often makes code less readable.
We should consider introducing a new variable instead.

On the other hand... the currently used reassignment of the parameter is a often used pattern to make undefined parameters, or paramters interpreted as false, fallback to a default value. So it makes the code less breakable and we may consider to mark this as false-positives inside scrutinizer.

Add test for default cookie options

A test for the default option should be added so we cover the correct behaviour. And we don't accidentally remove default features again see 0.6.1 release note.

add CONTRIBUTING.md

To fullfill Githubs recommended community standards we should add a CONTRIBUTING.md

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.