Skip to content

YogendraShelke/native-cookies

Repository files navigation

native-cookies

Cookie manager for React Native

Installation

npm install native-cookies

# for iOS only
npx pod-install ios

Usage

Import

import  Cookies  from  "native-cookies";

Get

// get all cookies which are belonged to 'http://github.com/'
Cookies.get("http://github.com/").then((cookie) =>  console.log(cookie));


// get cookie named 'foo' from 'http://github.com/'
Cookies.get("http://github.com/", "foo").then((cookie) =>  console.log(cookie));

Set

// set cookie 'foo=bar' for 'http://github.com/'
Cookies.set("http://github.com/", "foo", "bar").then(() =>
	console.log("success")
);


// set cookie 'foo=bar' for 'http://github.com/' with options:
Cookies.set("http://github.com/", "foo", "bar", {
	path:  "enterprise",
	domain:  "github.com",
}).then(() =>  console.log("success"));

Options

  • domain

Specifies the value for the Domain Set-Cookie attribute. By default, no domain is set, and most clients will consider the cookie to apply to only the current domain.

  • expires

Specifies the Date object to be the value for the Expires Set-Cookie attribute. By default, no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete it on a condition like exiting a web browser application.

  • path

Specifies the value for the Path Set-Cookie attribute. By default, the path is considered the "default path". By default, no maximum age is set, and most clients will consider this a "non-persistent cookie" and will delete it on a condition like exiting a web browser application

Clear

// clear all cookies for 'http://github.com'
Cookies.clear("http://github.com");

ClearAll

// clear all cookies for all domains
Cookies.clearAll();

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published