All Projects → Alex1990 → Tiny Cookie

Alex1990 / Tiny Cookie

Licence: mit
A tiny cookie manipulation plugin for the browser.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Tiny Cookie

Consent manager
Stellt ein Opt-In Cookie Banner zur Verfügung
Stars: ✭ 30 (-66.67%)
Mutual labels:  cookie
Agentweb
AgentWeb is a powerful library based on Android WebView.
Stars: ✭ 8,375 (+9205.56%)
Mutual labels:  cookie
Vue Cosha
🎨 A vue directive for the cosha library
Stars: ✭ 64 (-28.89%)
Mutual labels:  tiny
Session
A session handler for PHP and Slim 4+
Stars: ✭ 33 (-63.33%)
Mutual labels:  cookie
Cookie Autodelete
Firefox and Chrome WebExtension that deletes cookies and other browsing site data as soon as the tab closes, domain changes, browser restarts, or a combination of those events.
Stars: ✭ 1,015 (+1027.78%)
Mutual labels:  cookie
Clc
Tiny bash utility for coloring terminal output and prompt
Stars: ✭ 58 (-35.56%)
Mutual labels:  tiny
Easy Dom
EASYDOM-可能是最适合你的 DOM 课程
Stars: ✭ 21 (-76.67%)
Mutual labels:  cookie
Lightdm Tiny Greeter
👋 A Tiny GTK3 LightDM Greeter
Stars: ✭ 83 (-7.78%)
Mutual labels:  tiny
Nookies
🍪 A set of cookie helpers for Next.js
Stars: ✭ 1,035 (+1050%)
Mutual labels:  cookie
Smoldash
Smoldash, A tiny lodash alternative built for the modern web
Stars: ✭ 66 (-26.67%)
Mutual labels:  tiny
Http File Server
tiny portable HTTP file server. single binary, no dependencies. linux, osx, windows. #golang
Stars: ✭ 37 (-58.89%)
Mutual labels:  tiny
Embedio
A tiny, cross-platform, module based web server for .NET
Stars: ✭ 1,007 (+1018.89%)
Mutual labels:  tiny
Tiny Site
图片优化
Stars: ✭ 65 (-27.78%)
Mutual labels:  tiny
React Colorful
🎨 A tiny (2,5 KB) color picker component for React and Preact apps
Stars: ✭ 951 (+956.67%)
Mutual labels:  tiny
Printf
Tiny, fast, non-dependent and fully loaded printf implementation for embedded systems. Extensive test suite passing.
Stars: ✭ 1,157 (+1185.56%)
Mutual labels:  tiny
Dropwizard Jwt Cookie Authentication
Dropwizard bundle managing authentication through JWT cookies
Stars: ✭ 29 (-67.78%)
Mutual labels:  cookie
Genann
simple neural network library in ANSI C
Stars: ✭ 1,088 (+1108.89%)
Mutual labels:  tiny
Localslackirc
IRC gateway for slack, running on localhost for one user
Stars: ✭ 84 (-6.67%)
Mutual labels:  cookie
Redux Cookies Middleware
redux-cookies-middleware is a Redux middleware which syncs a subset of your Redux store state with cookies.
Stars: ✭ 75 (-16.67%)
Mutual labels:  cookie
Nanvix
Educational Spinoff of Nanvix
Stars: ✭ 65 (-27.78%)
Mutual labels:  tiny

tiny-cookie

Build Status codecov npm npm

English | 简体中文

A tiny cookie manipulation plugin for browser.

Upgrade from 1.x to 2.x: You can check the CHANGELOG.md

Install

NPM:

npm install tiny-cookie

Usage

ES2015 (recommended)

// You can import all methods.
import * as Cookies from 'tiny-cookie'

// Or, you can import the methods as needed.
import { isEnabled, get, set, remove } from 'tiny-cookie'

// No alias required, just imports.
import { isCookieEnabled, getCookie, setCookie, removeCookie } from 'tiny-cookie'

The tiny-cookie will expose an object Cookie on the global scope. Also, it can be as a CommonJS/AMD module (recommended).

APIs

isEnabled()

Alias: isCookieEnabled

Check if the cookie is enabled.

get(key)

Alias: getCookie

Get the cookie value with decoding, using decodeURIComponent.

getRaw(key)

Alias: getRawCookie

Get the cookie value without decoding.

getAll()

Alias: getAllCookies

Get all cookies with decoding, using decodeURIComponent.

set(key, value, options)

Alias: setCookie

Set a cookie with encoding the value, using encodeURIComponent. The options parameter is an object. And its property can be a valid cookie option, such as path(default: root path /), domain, expires/max-age, samesite or secure (Note: the secure flag will be set if it is an truthy value, such as true, or it will be not set). For example, you can set the expiration:

import { setCookie } from 'tiny-cookie';

const now = new Date;
now.setMonth(now.getMonth() + 1);

setCookie('foo', 'Foo', { expires: now.toGMTString() });

The expires property value can accept a Date object, a parsable date string (parsed by Date.parse()), an integer (unit: day) or a numeric string with a suffix character which specifies the time unit.

Unit suffix Representation
Y One year
M One month
D One day
h One hour
m One minute
s One second

Examples:

import { setCookie } from 'tiny-cookie';
const date = new Date;

date.setDate(date.getDate() + 21);

setCookie('dateObject', 'A date object', { expires: date });
setCookie('dateString', 'A parsable date string', { expires: date.toGMTString() });
setCookie('integer', 'Seven days later', { expires: 7 });
setCookie('stringSuffixY', 'One year later', { expires: '1Y' });
setCookie('stringSuffixM', 'One month later', { expires: '1M' });
setCookie('stringSuffixD', 'One day later', { expires: '1D' });
setCookie('stringSuffixh', 'One hour later', { expires: '1h' });
setCookie('stringSuffixm', 'Ten minutes later', { expires: '10m' });
setCookie('stringSuffixs', 'Thirty seconds later', { expires: '30s' });

setRaw(key, value, options)

Alias: setRawCookie

Set a cookie without encoding.

remove(key, options)

Alias: removeCookie

Remove a cookie on the current domain. If you want to remove the parent domain's cookie, you can use the options parameter, such as remove('cookieName', { domain: 'parentdomain.com' }).

FAQ

  1. How to use JSON as the encoder/decoder?

You can write your cookie get and set methods with JSON support easily:

import { getCookie, setCookie } from 'tiny-cookie';

export const getJSON = (key) => getCookie(key, JSON.parse);
export const setJSON = (key, value, options) => setCookie(key, value, JSON.stringify, options);

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].