Git Product home page Git Product logo

cookie's Introduction

Cookie


spm package Build Status Coverage Status

提供 Cookie 操作方法。


使用说明

get Cookie.get(name, [options])

获取 cookie 值。options 参数可选,取值如下:

  1. converter 转换函数。如果所获取的 cookie 有值,会在返回前传给 converter 函数进行转换。
  2. 选项对象。对象中可以有两个属性:converterraw. raw 是布尔值,为真时,不会对获取到的 cookie 值进行 URI 解码。

:如果要获取的 cookie 键值不存在,则返回 undefined.

例子:

define(function() {
    var Cookie = require('cookie');

    // setup
    document.cookie = 'foo=1';
    document.cookie = 'bar=2';

    Cookie.get('foo');
    // returns '1'

    Cookie.get('bar', function(s) { return parseInt(s); } );
    // returns 2
});

set Cookie.set(name, value, [options])

设置 cookie 值。参数 options 可选,可以有以下属性:path(字符串)、domain(字符串)、 expires(数值或日期对象)、raw(布尔值)。当 raw 为真值时,在设置 cookie 值时,不会进行 URI 编码。

例子:

define(function() {
    var Cookie = require('cookie');

    Cookie.set('foo', 3);

    Cookie.set('bar', 4, {
        domain: 'example.com',
        path: '/',
        expires: 30
    });
});

remove Cookie.remove(name, [options])

移除指定的 cookie.

例子:

define(function() {
    var Cookie = require('cookie');

    Cookie.remove('foo');

    Cookie.remove('bar', {
        domain: 'example.com',
        path: '/'
    });
});

Bitdeli Badge

cookie's People

Contributors

lifesinger avatar afc163 avatar popomore avatar sorrycc avatar lepture avatar bitdeli-chef avatar chuangbo avatar lizzie avatar winstoncse avatar

Watchers

James Cloos 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.