GithubHelp home page GithubHelp logo

ng2-cookies's Introduction

ng2-cookies

Simple library to deal with cookies in Angular2.

Compatibility Break v0 to v1

Replaced deprecated window.escape to encodeURIComponent

Installation

To install this library, run:

$ npm install ng2-cookies

Angular-CLI install notes

Edit the vendorNpmFiles array (path: ./angular-cli-build.js).

module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
      ...
      'ng2-cookies/**/*.+(js|js.map)'

Also add ng2-cookies to the map and packages object in the system-config.ts (path: ./src/system-config.ts).

const map: any = {
  'ng2-cookies': 'vendor/ng2-cookies'
};

/** User packages configuration. */
const packages: any = {
  'ng2-cookies': {main: 'ng2-cookies.js', defaultExtension: 'js'},
};

Usage:

import { Cookie } from 'ng2-cookies/ng2-cookies';

Cookie.set('cookieName', 'cookieValue');
Cookie.set('cookieName', 'cookieValue', 10 /*days from now*/);
Cookie.set('cookieName', 'cookieValue', 10, '/myapp/', 'mydomain.com', true /* https only */ );
let dt = new Date('October 13, 2017 11:13:45');
Cookie.set('cookieName', 'cookieValue', dt);
Cookie.set('cookieName', 'cookieValue', dt, '/myapp/', 'mydomain.com', true /* https only */ );

Cookie.check('cookieName');

let myCookie = Cookie.get('cookieName');

/*
* List of cookies as Object, like: { cookieName: "cookieValue", cookieName2: "cookieValue2" ... etc }
*/
let cookielist = Cookie.getAll();

Cookie.delete('cookieName');
Cookie.deleteAll();

Contributors

carcamano Bigous sasidhar iloveyo123u1 etwillbefine josx tyxz
Carcamano Bigous Sasidhar Iloveyo123u1 Etwillbefine Josx Tyx

License

MIT © Felipe Rebelo Lopes

ng2-cookies's People

Contributors

carcamano avatar bigous avatar sasidhar avatar tyxz avatar josx avatar etwillbefine avatar

Watchers

James Cloos avatar  avatar

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.