Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
angular-cookie
Advanced tools
Lightweight Angular module for access to cookies
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 git@github.com: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
To run example execute following commands
git clone git@github.com: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
.
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);
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; } });
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; }};
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/' });
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: '/'
The path gives you the chance to specify a directory where the cookie is active.
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.
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: 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 (value) { return value; }
The method that will be used to encode the cookie value (should be passed when using Set).
Default: encodeURIComponent.
decode: function (value) { return value; }
The method that will be used to decode extracted cookie values (should be passed when using Get).
Default: decodeURIComponent.
FAQs
Lightweight Angular module for access to cookies
The npm package angular-cookie receives a total of 4,948 weekly downloads. As such, angular-cookie popularity was classified as popular.
We found that angular-cookie demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.