1.0.11 • Published 4 years ago
@eneropl/js-cookies v1.0.11
npm i --save-dev @eneropl/js-cookies
To use package:
import cookies from '@eneropl/js-cookies'
const userDeail = {
name: 'Alex',
age: 20
};
cookies.set('user', userDetail, {
// This cookie will be stored for 1 hour
maxAge: 3600,
path: '/;
}); // true
Getting the cookie value for the specified key. If the function finds a cookie with the specified key, the function will return a value, otherwise false.
// In cookie storage "name=Alex;"
cookies.get('name'); // Alex
cookies.get('someCookie'); // false
Removes the cookie for the given key. If there is access and the cookie was successfully deleted, the function will return true, otherwise false. Also, there are cases when, to delete a cookie, you need to specify additional defining cookie parameters that were specified when the cookie was created or defined in the cookie parameters (see developer console), in which case the options conditional parameter is used to explicitly indicate the cookie.
// In cookie storage "name=Alex; age=20", when age from different domain or httpOnly.
cookies.delete('name') // true. Cookie deleted successfully.
cookies.delete('age') // false. Available cookie with "age" doesn't exist to delete.