├── .npmignore
├── test
├── test.js
├── index.html
├── index.js
└── server.js
├── .gitignore
├── gulpfile.js
├── browser.js
├── index.js
├── package.json
├── LICENSE
└── README.md
/.npmignore:
--------------------------------------------------------------------------------
1 | public
2 | test
3 | node_modules
4 | .git
5 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | global.CookieDough = require('../index.js');
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 | *.swp
4 | npm-debug.log
5 | public
6 | ._*
7 | .git
8 |
9 | *.pem
10 |
--------------------------------------------------------------------------------
/test/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | test
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | var gulp = require('gulp'),
2 | browserify = require('browserify'),
3 | transform = require('vinyl-transform');
4 |
5 | gulp.task('browserify', function () {
6 | var browserified = transform(function (filename) {
7 | var b = browserify(filename);
8 | return b.bundle();
9 | });
10 |
11 | return gulp.src(['index.js','test/test.js'])
12 | .pipe(browserified)
13 | .pipe(gulp.dest('./public'));
14 | });
15 |
16 | gulp.task('default', ['browserify'])
17 |
--------------------------------------------------------------------------------
/test/index.js:
--------------------------------------------------------------------------------
1 | var chai = require('chai'),
2 | expect = chai.expect,
3 | subject = require('../index.js')
4 |
5 | describe('cookie-dough', function() {
6 | describe('set', function() {
7 | it('works', function () {
8 | subject.set('key', 123, {opts: true});
9 | expect(true).to.be.true
10 | });
11 | });
12 |
13 | describe('get', function() {
14 | it('works', function () {
15 | subject.get('key');
16 | expect(true).to.be.true
17 | });
18 | });
19 |
20 | });
21 |
--------------------------------------------------------------------------------
/test/server.js:
--------------------------------------------------------------------------------
1 | var express = require('express'),
2 | CookieDough = require('../index.js'),
3 | cookieParser = require('cookie-parser'),
4 | app = express();
5 |
6 | app.use(cookieParser());
7 |
8 | app.get('/', function (req, res) {
9 | var cookie = new CookieDough(req);
10 | console.log('set', cookie.set('test', 'value5'));
11 | console.log('get', cookie.get('test'));
12 | console.log('remove', cookie.remove('test'));
13 | console.log('all', cookie.all());
14 | res.json({});
15 | });
16 |
17 | app.listen(3030, function () {
18 | console.log('App is running on port 3030');
19 | })
20 |
--------------------------------------------------------------------------------
/browser.js:
--------------------------------------------------------------------------------
1 | var cookie = require('cookie');
2 |
3 | module.exports = function () {
4 | return {
5 | set: function (name, value, options) {
6 | return document.cookie = cookie.serialize(name, value, options);
7 | },
8 |
9 | get: function (name) {
10 | return cookie.parse(document.cookie)[name];
11 | },
12 |
13 | remove: function (name, options) {
14 | var opts = options || {};
15 | opts.expires = new Date(0);
16 |
17 | return !!(document.cookie = cookie.serialize(name, '', opts));
18 | },
19 |
20 | all: function () {
21 | return cookie.parse(document.cookie);
22 | }
23 | }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | var cookie = require('cookie');
2 |
3 | module.exports = function (req) {
4 | // This is a temp hack for remembering what has been set until express has a better api for cookies
5 | // see https://github.com/expressjs/express/pull/2237
6 | var cookiesSet = {}
7 | return {
8 | set: function (name, value, options) {
9 | var cookieStr = cookie.serialize(name, value, options);
10 | req.res.cookie.call(req.res, name, value, options);
11 | cookiesSet[name] = value
12 | return cookieStr;
13 | },
14 |
15 | get: function (name) {
16 | return cookiesSet[name] || req.cookies[name];
17 | },
18 |
19 | remove: function (name, options) {
20 | var opts = options || {};
21 | opts.expires = new Date(0);
22 |
23 | return !!(req.res.cookie(name, '', opts));
24 | },
25 |
26 | all: function () {
27 | return req.cookies;
28 | }
29 | }
30 | };
31 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cookie-dough",
3 | "version": "0.1.0",
4 | "description": "An isomorphic JavaScript cookie library",
5 | "main": "index.js",
6 | "directories": {
7 | "test": "test"
8 | },
9 | "scripts": {
10 | "test": "mocha"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git://github.com/change/cookie-dough.git"
15 | },
16 | "browser": "browser.js",
17 | "dependencies": {
18 | "cookie": "^0.1.2"
19 | },
20 | "devDependencies": {
21 | "browserify": "^10.1.3",
22 | "chai": "^2.3.0",
23 | "gulp": "^3.8.11",
24 | "mocha": "^2.2.4",
25 | "sinon": "^1.14.1",
26 | "vinyl-transform": "^1.0.0"
27 | },
28 | "keywords": [
29 | "cookie",
30 | "cookies",
31 | "cookie-dough",
32 | "rendr",
33 | "isomorphic"
34 | ],
35 | "author": "Josh Callender (https://github.com/saponifi3d)",
36 | "license": "MIT",
37 | "bugs": {
38 | "url": "https://github.com/change/cookie-dough/issues"
39 | },
40 | "homepage": "https://github.com/change/cookie-dough"
41 | }
42 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014-2016 Josh Callender
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | > Sorry all, this project is no longer used internally and hasn't been actively maintained in a while. We're closing out the remaining PRs & issues and archiving it.
2 |
3 | cookie-dough
4 | ============
5 |
6 | An isomorphic JavaScript cookie library.
7 |
8 | Wraps https://www.npmjs.com/package/cookie to work on the client and server. Also, required is having parsed cookies in express (for now).
9 |
10 | ## Usage
11 |
12 |
13 | ### Geting a cookie
14 |
15 | ```js
16 | // client-side
17 | // automatically parses the cookies for the page
18 | var cookie = require('cookie-dough')();
19 | cookie.get('name');
20 |
21 | // server-side
22 | var express = require('express'),
23 | CookieDough = require('cookie-dough'),
24 | cookieParser = require('cookie-parser');
25 |
26 | var app = express();
27 | app.use(cookieParser());
28 |
29 | app.get('/', function(req, res){
30 | var cookie = new CookieDough(req); // req is required when creating an instance
31 | cookie.get('name');
32 | });
33 | ```
34 |
35 | ### Getting all the cookies
36 | ```js
37 | // client-side
38 | // automatically parses the cookies for the page
39 | var cookie = require('cookie-dough')();
40 |
41 | // returns an object with all of the cookies
42 | // format: { cookieName: "cookie value" }
43 | cookie.all();
44 |
45 | // server-side
46 | var express = require('express'),
47 | CookieDough = require('cookie-dough'),
48 | cookieParser = require('cookie-parser');
49 |
50 | var app = express();
51 | app.use(cookieParser());
52 |
53 | app.get('/', function(req, res){
54 | var cookie = new CookieDough(req);
55 | cookie.all();
56 | });
57 | ```
58 |
59 | ### Setting a cookie
60 |
61 | ```js
62 | // client-side
63 | var cookie = require('cookie-dough')();
64 | cookie.set('name', 'value', { /* options */ });
65 |
66 | // server-side
67 | var express = require('express'),
68 | CookieDough = require('cookie-dough'),
69 | cookieParser = require('cookie-parser');
70 |
71 | var app = express();
72 | app.use(cookieParser());
73 |
74 | app.get('/', function(req, res){
75 | var cookie = new CookieDough(req);
76 | cookie.set('name', 'value', { /* options */ });
77 | });
78 | ```
79 |
80 | The options that you can set on a cookie:
81 |
82 | *path* - cookie path
83 |
84 | *expires* - absolute expiration date for the cookie (Date object)
85 |
86 | *maxAge* - relative max age of the cookie from when the client receives it (seconds)
87 |
88 | *domain* - domain for the cookie
89 |
90 | *secure* - true or false
91 |
92 | *httpOnly* - true or false
93 |
94 |
95 | ### Removing a cookie
96 |
97 | ```js
98 | // client-side
99 | var cookie = require('cookie-dough')();
100 | cookie.remove('name', { /* options */ });
101 |
102 | // server-side
103 | var express = require('express'),
104 | CookieDough = require('cookie-dough'),
105 | cookieParser = require('cookie-parser');
106 |
107 | var app = express();
108 | app.use(cookieParser());
109 |
110 | app.get('/', function(req, res){
111 | var cookie = new CookieDough(req);
112 | cookie.remove('name');
113 | });
114 | ```
115 |
116 | The options that can be set to remove a cookie are:
117 |
118 | *path* - cookie path
119 |
120 | *domain* - domain for the cookie
121 |
--------------------------------------------------------------------------------