• Stars
    star
    266
  • Rank 154,103 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight Angular module for access to cookies

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

More Repositories

1

react-native-image-crop-picker

iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping
Objective-C
5,916
star
2

grpool

Lightweight Goroutine pool
Go
734
star
3

neo

Go Web Framework
Go
419
star
4

rerun

Configurable recompiling and rerunning go apps when source changes
Go
167
star
5

httpcheck

supertest inspired library for testing HTTP servers
Go
151
star
6

golog

Simple but powerful go logging library
Go
92
star
7

migrate

Tool for managing and executing your database migrations
Ruby
60
star
8

react-native-image-preview

Display zoomed image in transparent modal window
JavaScript
33
star
9

koa-bunyan

Using node-bunyan as koa logging middleware
JavaScript
22
star
10

react-native-autogrow-input

Missing auto grow multiline input component
JavaScript
20
star
11

arch-orchestrator

Orchestrator architectural pattern for large node.js applications
JavaScript
18
star
12

co-foreach

Run generator function as forEach loop callback
JavaScript
17
star
13

koa-routing

Manage koa routes on right way
JavaScript
15
star
14

tic-tac-toe

Tic-tac-toe game with AI in Prolog and GUI in Python (kivy framework + pyswip)
Python
11
star
15

urlregex

express-like named url parameters extracting from url
Go
8
star
16

go-clicolor

Package provides ability to print colored text to stdout.
Go
6
star
17

rust-elo

Rust crate for calculating player rating based on elo ranking system
Rust
5
star
18

react-ts-boilerplate

Minimal boilerplate for React typescript projects
JavaScript
5
star
19

i18n-xlsx

Typesafe i18n
TypeScript
5
star
20

sequelize-import

Lib for importing sequelize models with ease
JavaScript
5
star
21

ts-boilerplate

Minimal boilerplate for typescript projects
TypeScript
4
star
22

socket.io-cookie

Cookie parser middleware for socket.io
JavaScript
4
star
23

BreakableSprite-Cocos2D

Make breakable sprite with texture and physics (Box2D), and cut sprite at two specified points
Objective-C
4
star
24

genify

Bringing power of javascript generators into normal javascript environment
JavaScript
4
star
25

jFS

File system simulator with basic UNIX commands. Built using composite + abstract factory + singleton
Java
3
star
26

jDrawing

Library for drawing 2D/3D bodies and scenes in java
Java
3
star
27

b2GLDraw

OpenGL debug draw for Box2D
C++
3
star
28

monkey

Programming language implemented for fun and educational purposes
Go
3
star
29

glLamp

Mini OpenGL lib in C++ with 3D lamp example
C++
3
star
30

BounceCat

iOS game
Objective-C
3
star
31

koa-ember-seed

Starter kit for new Koa projects with Ember on client
JavaScript
3
star
32

easy-postgresql-fixture

postgreSQL middleware for easy-fixture
JavaScript
3
star
33

mongo-spade-replicate

Multi-agent system for distributed mongodb replication
Python
3
star
34

neo-cors

Enable CORS in your Neo application
Go
3
star
35

koa-r

Requesting node modules from one central place
JavaScript
2
star
36

easy-fixture

Converting live data from multiple data sources into fixture, and importing into corresponding data destinations
JavaScript
2
star
37

grunt-easy-postgresql-fixture

Grunt task for easy-postgresql-fixture
JavaScript
2
star
38

vim-javascript-adapted

Vim adapted for javascript development
Vim Script
2
star
39

spade-samples

Smart Python multi-Agent Development Environment samples
Python
2
star
40

cmap

Map with convenient methods for getting and setting values
Go
2
star
41

easy-mongo-fixture

Mongo middleware for easy-fixture
JavaScript
2
star
42

observable_pattern

Simple implementation of observable patten in C
C
2
star
43

abplot

Concurrent execution of ab tests and visualizing results using gnuplot
Rust
2
star
44

ChatApplication

Server and client side (c# wpf app)
C#
2
star
45

emacs-config

My emacs config
2
star
46

latte

Django site for management of restaurants and their menus
Python
2
star
47

node-authorizator

Node module for user authorization
JavaScript
2
star
48

pyobjus-ball

Example of using accelerometer to move ball on screen, with pyobjus and kivy-ios on iOS
Python
2
star
49

risk_doctor

Django site for management of an emergency situations
Python
2
star
50

grunt-easy-mongo-fixture

Grunt task for easy-mongo-fixture plugin. It helps to your load and save your fixtures using mongo database
JavaScript
2
star
51

authorizator-example

Example of using node-authorizator
JavaScript
1
star
52

b2GL

Box2D integration with OpenGL
C++
1
star
53

node-ts-boilerplate

Minimal boilerplate for Node.js typescript projects
TypeScript
1
star
54

ExamsWS

SOAP web service for overview of student exams
Java
1
star
55

node-module-seed

Seed repo for new node modules
JavaScript
1
star
56

salt-java8-formula

SaltStack
1
star
57

bunyan-cassandra

Cassandra bunyan stream
JavaScript
1
star
58

ProFlightXNA

Example of game written with help of XNA Framework
C#
1
star
59

Threading-and-semaphores

Examples of Threading and semaphores in c
C
1
star
60

List-ADT-implementation

Implementation of list using pointers and array in c
C
1
star
61

server_configs

SIS konfiguracijski file-ovi
Shell
1
star
62

salt-nats-formula

SaltStack
1
star
63

click-and-screenshot

Python script for performing mouse click (from Python) followed by screenshot (from Python)
Python
1
star
64

Zend_sample

Example of application in zend framework
PHP
1
star
65

salt-redis-formula

SaltStack
1
star
66

njuskalo-crawler

TypeScript
1
star
67

redis-terraform-salt

Terraform configuration to create infrastructure for Redis 4 cluster which is going to be provisioned by salt
HCL
1
star
68

salt-elasticsearch-formula

Salt formula for running Elasticsearch cluster using zen of aws discovery
SaltStack
1
star
69

salt-golang-formula

SaltStack
1
star
70

Edward-company-cSharp-app

Application for Edward d.o.o. company. Application use ORM to acces data (LINQ)
C#
1
star
71

koa-err

Global error handling middleware for koa
JavaScript
1
star
72

PandPProject

Web application, with WCF web service, and Windows phone 7 client app
C#
1
star
73

xmpp_client

Django XMPP (chat client) app. It uses strophe.js library for accessing ejabberd server
JavaScript
1
star
74

examples-of-algorithms-

Different types of algorithms
C++
1
star
75

akka-merge-sort

Merge sort using akka
Shell
1
star