├── README.md ├── package.json ├── index.js └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | ### sfcookies 2 | 3 | Built to give ReactJS, AngularJS, or any nativeJS Web Application access to browser cookies. 4 | [Visit on NPM](https://www.npmjs.com/package/sfcookies) 5 | 6 | bake_cookie(name, string) - Bake Cookie allows you to pass a name and a string value to store a cookie on the user's browser. It maps the name to the string. 7 | 8 | read_cookie(name) - returns the value of your of your baked cookie. 9 | 10 | delete_cookie(name) - removes the cookie from the browser history. 11 | 12 | ### usage 13 | 1) Run `npm install --save sfcookies` 14 | 15 | 2) Import these methods in es6 like so: 16 | `import { bake_cookie, read_cookie, delete_cookie } from 'sfcookies'` 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sfcookies", 3 | "version": "1.0.2", 4 | "description": "Giving react projects access to browser cookies. More description on usage on github.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/15Dkatz/sfcookies.git" 12 | }, 13 | "keywords": [ 14 | "Cookies", 15 | "React", 16 | "ReactJS" 17 | ], 18 | "author": "David Katz <15Dkatz@shcp.edu> (http://davidtkatz.com/)", 19 | "license": "ISC", 20 | "bugs": { 21 | "url": "https://github.com/15Dkatz/sfcookies/issues" 22 | }, 23 | "homepage": "https://github.com/15Dkatz/sfcookies#readme" 24 | } 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.bake_cookie = bake_cookie; 7 | exports.read_cookie = read_cookie; 8 | exports.delete_cookie = delete_cookie; 9 | function bake_cookie(name, value,date) { 10 | let expirey = date instanceof Date ? '; expires='+date : null 11 | var cookie = [name, '=', JSON.stringify(value), '; domain_.', window.location.host.toString(), '; path=/;',expirey].join(''); 12 | document.cookie = cookie; 13 | } 14 | 15 | // reads a cookie according to the given name 16 | function read_cookie(name) { 17 | var result = document.cookie.match(new RegExp(name + '=([^;]+)')); 18 | result = result != null ? JSON.parse(result[1]) : []; 19 | return result; 20 | } 21 | 22 | function delete_cookie(name) { 23 | document.cookie = [name, '=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain.', window.location.host.toString()].join(''); 24 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Node template 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | yarn-debug.log* 8 | yarn-error.log* 9 | 10 | # Runtime data 11 | pids 12 | *.pid 13 | *.seed 14 | *.pid.lock 15 | 16 | # Directory for instrumented libs generated by jscoverage/JSCover 17 | lib-cov 18 | 19 | # Coverage directory used by tools like istanbul 20 | coverage 21 | 22 | # nyc test coverage 23 | .nyc_output 24 | 25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 26 | .grunt 27 | 28 | # Bower dependency directory (https://bower.io/) 29 | bower_components 30 | 31 | # node-waf configuration 32 | .lock-wscript 33 | 34 | # Compiled binary addons (http://nodejs.org/api/addons.html) 35 | build/Release 36 | 37 | # Dependency directories 38 | node_modules/ 39 | .idea/ 40 | jspm_packages/ 41 | 42 | # Typescript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | 64 | --------------------------------------------------------------------------------