Code Monkey home page Code Monkey logo

cookie-machine's Introduction

cookie-machine npm version Build Status

A universal cookie library.

Installing

npm i cookie-machine -S

Although tests are running on node >=4.0 (because of jsdom), the library should support node >=0.12.

Currently, only CommonJS is supported. Please submit an issue if you'd like any other module to be supported. Although, browser builds have low chances of being supported because it doesn't make any sense.

Usage

// server-side / node
var cookie = require('cookie-machine');

http.createServer(function(req, res) {
  cookie.init(res);
  cookie.set('yolo', 'swag');
});

// browser
var cookie = require('cookie-machine');
// notice that we no longer have to call `init` here.
// init is only required for the server-side.
cookie.set('yolo', 'swag');

Check out more examples.

API

Here are some of the methods exposed by the library:

init(object res): void

  • res - An object which is expected to be node's native response.

Initializes cookie to be ready for node. In the client, this is a noop.

get(string key): any

  • key - The key of the cookie to be get. Returns the value of the key in the cookie.

set(string key, any value [, object options]): void

  • key - The key of the cookie to be stored.
  • value - The value of the cookie to be stored.
  • options - (optional, defaults to { expires: new Date(0) }) Cookie options such as expired, domain, path, and etc.

Set a value in the cookie.

remove(string key [, object options]): void

  • key - Key in the cookie to be removed.
  • options - (optional, defaults to { expires: new Date(0) }) Cookie options such as expired, domain, path, and etc.

Remove a key in the cookie.

License

MIT

This project was motivated by cookie-dough.

cookie-machine's People

Contributors

srph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cookie-machine's Issues

More test cases

I'm really feeling tired atm. Halp plox. Also need tests for get in the server.

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.