Skip to content

Latest commit

 

History

History
219 lines (137 loc) · 4.13 KB

README.md

File metadata and controls

219 lines (137 loc) · 4.13 KB

<polymer-cookie>

Cookie Web Component for Polymer 1.x

Bower Build Status

Cookie Web Component for Polymer 1.x

<polymer-cookie
  id="test_cookie"
  name="test_cookie"
  value="hello world"
  time="2"
  format="h">
</polymer-cookie>

<polymer-cookie
  id="test_cookie2"
  name="test_cookie2"
  value="hello world!"
  auto-set>
</polymer-cookie>

Note: The params attribute must be double quoted JSON.

Usage

Add the library using the Javascript package manager Bower:

$ bower install --save polymer-cookie

Or clone this repository inside your project folder using Git:

$ git clone https://github.com/andreasonny83/polymer-cookie.git

Properties

name

Type: String

Default value: 'polymer-cookie'

Set the cookie name

value

type: String

Default value: ''

The cookie value

path

type: String

Default value: ''

The cookie path.

The path must be absolute. If not specified, defaults to the current path of the current document location.

domain

type: String

Default value: ''

The cookie domain.

(e.g., 'example.com' or 'subdomain.example.com'). If not specified, defaults to the host portion of the current document location (but not including subdomains). Contrary to earlier specifications, leading dots in domain names are ignored. If a domain is specified, subdomains are always included.

time

type: Number

Default value: 1

The expiration time related to the 'format' value. Set to -1 to never expire the cookie

format

type: String

Default value: 'd'

The expiration format time

  • 's' : seconds
  • 'm' : minutes
  • 'h' : hours
  • 'd' : days

secure

type: Boolean

Default value: false

Cookie to only be transmitted over secure protocol as https

http-only

type: Boolean

Default value: false

The HTTPOnly cookie attribute can help to mitigate this attack by preventing access to cookie value through Javascript. Read more about Cookies and Security.

auto-set

type: Boolean

Default value: false

If set, creates the cookie as the element is rendered on the page without the need of manually invoking createCookie

Methods

createCookie

Write the cookie

var cookie = Polymer.dom(document).querySelector('#user_cookie');
cookie.createCookie();

readCookie

Read the cookie if any, and the returns its value

var cookie = Polymer.dom(document).querySelector('#user_cookie');
var cookie_value = cookie.readCookie();

eraseCookie

Destroy the cookie

var cookie = Polymer.dom(document).querySelector('#user_cookie');
cookie.eraseCookie();

Rendering in a demo page

Install Polymer CLI

Install the Polymer CLI to serve the demo locally with:

$ npm install -g polymer-cli

Run the demo

First install all the project dependencies with:

$ bower install

Then, run Polymer serve from the repo directory with:

$ polymer serve

Then open localhost:8080/components/polymer-cookie/demo/ in your browser.

For more information about Polymer CLI have a look at the official documentation

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Contributors

A special thanks to our contributors:

Changelog

Changelog available here

License

MIT License © Andrea SonnY