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

angular-cookie

v4.1.0

Published

Lightweight Angular module for access to cookies

Downloads

19,176

Readme

angular-cookie Build Status

Lightweight Angular module for access to cookies

Installation

You can install angular-cookie via bower

bower install angular-cookie

Other way to install angular-cookie is to clone this repo into your project with this command

git clone [email protected]:ivpusic/angular-cookie.git

Then you need to include angular-cookie.js script into your project

<script src="/path/to/angular-cookie.min.js"></script>

or include beautified version with

<script src="/path/to/angular-cookie.js"></script>

To rebuild min.js version run

grunt build

Run example

To run example execute following commands

git clone [email protected]:ivpusic/angular-cookie.git
cd angular-cookie
npm -g install bower
npm -g install grunt
npm install
bower install
grunt

After this, go at 127.0.0.1:9001/example in your browser, and you will see running example of angular-cookie.

Usage

First you need to inject ipCookie into your angular module.

var myApp = angular.module('myApp', ['ipCookie']);

And now, for example if you want to use it from your controller

myApp.controller('cookieController', ['$scope', 'ipCookie', function($scope, ipCookie) {
  // your code here
}]);

General signature of main function is

ipCookie(key, value, options);

Set

To create a cookie use

ipCookie(key, value);

The value supports strings, numbers, booleans, arrays and objects and will be automatically serialized into the cookie.

You can also set some additional options, like number of day when a cookie expires

ipCookie(key, value, { expires: 21 });

If you want to specify a cookie path use

ipCookie(key, value, { path: '/some/path' });

If you want to set the encode or decode functions use

ipCookie(key, value, { encode: function (value) { return value; } });

Get

To get all cookies use

ipCookie();

If you want to get a cookie with a specific key use

ipCookie(key);

If any cookie was not found, function returns undefined.

The returned value will be automatically deserialized.

If you want to pass an options object, you will need to also pass 'undefined' as the second parameter:

ipCookie(key, undefined, {decode: function (value) { return value; }};

Remove

And if you want to remove a cookie use

ipCookie.remove(key);

To remove a cookie on a specific path use

ipCookie.remove(key, { path: '/some/path/' });

Options

Domain

domain: 'example.com'

The domain tells the browser to which domain the cookie should be sent. If you don't specify it, it becomes the domain of the page that sets the cookie.

Path

path: '/'

The path gives you the chance to specify a directory where the cookie is active.

Expires

expires: 21

Each cookie has an expiry date after which it is trashed. If you don't specify the expiry date the cookie is trashed when you close the browser.

Expiration Unit

expirationUnit: 'minutes'

Allows you to set the expiration time in hours, minutes, seconds, or ``milliseconds`. If this is not specified, any expiration time specified will default to days.

Secure

secure: true

The Secure attribute is meant to keep cookie communication limited to encrypted transmission, directing browsers to use cookies only via secure/encrypted connections.

Encode function

encode: function (value) { return value; }

The method that will be used to encode the cookie value (should be passed when using Set).

Default: encodeURIComponent.

Decode function

decode: function (value) { return value; }

The method that will be used to decode extracted cookie values (should be passed when using Get).

Default: decodeURIComponent.

Notes

TODO

  • Add tests