Coder Social home page Coder Social logo

json-cookie's Introduction

json-cookie

json-cookie is client module for easy cookie handling, support JSON data format without manual parsing and serializing.

Installation

Super quick install with npm. (Thanks npm!)

$ npm install --save json-cookie

Usage

If you are using web bundler like Browserify or Webpack, you can easily import them:

import cookie from 'json-cookie';
// or
var cookie = require('json-cookie');

Else, you should load manually with proper web server settings.

<script src="/node_modules/json-cookie/index.js"></script>

Or just copy /node_modules/json-cookie/index.js into your project directory and include it. I'm heavily recommend that using bundler. If you are not familiar with, you should try it. It isn't hard!

void cookie.set(string key, var value[, object options])

Set cookie with specified key and value with options. value can be a object. Available options are:

  • expires: Days of expiration.
  • days: Alias of expires.
  • path: Path of cookie.
  • domain: Domain of cookie.
  • secure: HTTPS only.
import cookie from 'json-cookie';

cookie.set('test', 'test');		// test=test
cookie.set('json-test', { name: '.modernator' });    // json-test={"name":".modernator"}

cookie.set('ex-test', 'test', {
	expires: 1
});		// ex-test=test; expires= ...

void cookie.get(string key)

Get cookie with key. If cookie isn't exist, it returns undefined.

import cookie from 'json-cookie';

cookie.get('test');		// test
cookie.get('json-test');	// Object { name: '.modernator' }

void cookie.delete(string key)

Delete cookie with key.

import cookie from 'json-cookie';

cookie.delete('test');
cookie.get('test');		//

Cautions

  • This module is client side only, not support on node.js.

json-cookie's People

Contributors

rico345100 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

gnet27

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.