typescript-cookie
Advanced tools
Comparing version 0.1.1 to 1.0.0
{ | ||
"name": "typescript-cookie", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "A simple, lightweight API for handling cookies in the browser", | ||
@@ -29,4 +29,4 @@ "author": "Klaus Hartl", | ||
"scripts": { | ||
"test": "jest --ci", | ||
"test:e2e": "jest --config '{\"testMatch\":[\"**/?(*.)e2e.js\"]}' test/browser.e2e.js", | ||
"test": "jest", | ||
"test:e2e": "jest --config '{\"testMatch\":[\"**/?(*.)e2e.js\"]}'", | ||
"coverage": "jest --coverage", | ||
@@ -58,2 +58,3 @@ "lint": "standard && ts-standard", | ||
"eslint-plugin-markdown": "^2.2.0", | ||
"fast-check": "^2.17.0", | ||
"http-server": "^13.0.0", | ||
@@ -60,0 +61,0 @@ "jest": "^27.1.0", |
@@ -29,19 +29,13 @@ # TypeScript Cookie [![CI Status](https://github.com/carhartl/typescript-cookie/actions/workflows/ci.yml/badge.svg)](https://github.com/carhartl/typescript-cookie/actions/workflows/ci.yml) [![BrowserStack Test](https://github.com/carhartl/typescript-cookie/actions/workflows/browserstack.yml/badge.svg)](https://github.com/carhartl/typescript-cookie/actions/workflows/browserstack.yml) [![TypeScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![Maintainability](https://api.codeclimate.com/v1/badges/d87f5ff1ca1041f8723a/maintainability)](https://codeclimate.com/github/carhartl/typescript-cookie/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/d87f5ff1ca1041f8723a/test_coverage)](https://codeclimate.com/github/carhartl/typescript-cookie/test_coverage) [![npm](https://img.shields.io/github/package-json/v/carhartl/typescript-cookie)](https://www.npmjs.com/package/typescript-cookie) [![size](https://img.shields.io/bundlephobia/minzip/typescript-cookie)](https://www.npmjs.com/package/typescript-cookie) [![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/typescript-cookie/badge?style=rounded)](https://www.jsdelivr.com/package/npm/typescript-cookie) | ||
Importing setter: | ||
Importing: | ||
```javascript | ||
import { setCookie } from 'typescript-cookie' | ||
```typescript | ||
import { getCookie, setCookie } from 'typescript-cookie' | ||
``` | ||
All other functions not being used can be tree-shaken by a bundler. | ||
Functions not being used (that is imported) can be tree-shaken by a bundler. | ||
Importing all: | ||
```javascript | ||
import { getCookie, removeCookie, setCookie } from 'typescript-cookie' | ||
``` | ||
Create a cookie, valid across the entire site: | ||
```javascript | ||
```typescript | ||
setCookie('name', 'value') | ||
@@ -52,3 +46,3 @@ ``` | ||
```javascript | ||
```typescript | ||
setCookie('name', 'value', { expires: 7 }) | ||
@@ -59,3 +53,3 @@ ``` | ||
```javascript | ||
```typescript | ||
setCookie('name', 'value', { expires: 7, path: '' }) | ||
@@ -66,3 +60,3 @@ ``` | ||
```javascript | ||
```typescript | ||
getCookie('name') // => 'value' | ||
@@ -74,19 +68,11 @@ getCookie('nothing') // => undefined | ||
```javascript | ||
```typescript | ||
getCookies() // => { name: 'value' } | ||
``` | ||
_Note: It is not possible to read a particular cookie by passing one of the cookie attributes (which may or may not | ||
have been used when writing the cookie in question):_ | ||
_Note: It is not possible to read a particular cookie by additionally passing specific cookie attributes. A cookie will only be available if it's visible from where the code is called, visibility being controlled by `path` and `domain` used when setting a cookie._ | ||
```javascript | ||
getCookie('foo', { domain: 'sub.example.com' }) // `domain` won't have any effect...! | ||
``` | ||
The cookie with the name `foo` will only be available on `.get()` if it's visible from where the | ||
code is called; the domain and/or path attribute will not have an effect when reading. | ||
Delete cookie: | ||
```javascript | ||
```typescript | ||
removeCookie('name') | ||
@@ -97,3 +83,3 @@ ``` | ||
```javascript | ||
```typescript | ||
setCookie('name', 'value', { path: '' }) | ||
@@ -104,9 +90,9 @@ removeCookie('name') // fail! | ||
_IMPORTANT! When deleting a cookie and you're not relying on the [default attributes](#cookie-attributes), you must pass the exact same path and domain attributes that were used to set the cookie:_ | ||
_IMPORTANT! When deleting a cookie you must pass the exact same path and domain attributes that were used to set the cookie:_ | ||
```javascript | ||
```typescript | ||
removeCookie('name', { path: '', domain: '.yourdomain.com' }) | ||
``` | ||
_Note: Removing a nonexistent cookie neither raises any exception nor returns any value._ | ||
_Note: Removing a nonexistent cookie neither raises an exception nor returns any value._ | ||
@@ -125,3 +111,3 @@ ## Encoding | ||
Define when the cookie will be removed. Value must be a [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) which will be interpreted as days from time of creation or a [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance. If omitted, the cookie becomes a session cookie. | ||
Define when the cookie will be removed. Value must be a [`number`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#the-primitives-string-number-and-boolean) which will be interpreted as days from time of creation or a [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance. If omitted, the cookie becomes a session cookie. | ||
@@ -134,5 +120,5 @@ To create a cookie that expires in less than a day, you can check the [FAQ on the Wiki](https://github.com/js-cookie/js-cookie/wiki/Frequently-Asked-Questions#expire-cookies-in-less-than-a-day). | ||
```javascript | ||
```typescript | ||
setCookie('name', 'value', { expires: 365 }) | ||
getCookie('name') // => 'value' | ||
getCookie('name') | ||
removeCookie('name') | ||
@@ -143,3 +129,3 @@ ``` | ||
A [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) indicating the path where the cookie is visible. | ||
A [`string`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#the-primitives-string-number-and-boolean) indicating the path where the cookie is supposed to be visible. | ||
@@ -150,5 +136,5 @@ **Default:** `/` | ||
```javascript | ||
```typescript | ||
setCookie('name', 'value', { path: '' }) | ||
getCookie('name') // => 'value' | ||
getCookie('name') | ||
removeCookie('name', { path: '' }) | ||
@@ -159,3 +145,3 @@ ``` | ||
A [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) indicating a valid domain where the cookie should be visible. The cookie will also be visible to all subdomains. | ||
A [`string`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#the-primitives-string-number-and-boolean) indicating a valid domain where the cookie should be visible. The cookie will also be visible to all subdomains. | ||
@@ -166,7 +152,6 @@ **Default:** Cookie is visible only to the domain or subdomain of the page where the cookie was created, except for Internet Explorer (see below). | ||
Assuming a cookie that is being created on `site.com`: | ||
```javascript | ||
```typescript | ||
setCookie('name', 'value', { domain: 'subdomain.site.com' }) | ||
getCookie('name') // => undefined (need to read at 'subdomain.site.com') | ||
getCookie('name') | ||
removeCookie('name', { domain: 'subdomain.site.com' }) | ||
``` | ||
@@ -182,5 +167,5 @@ | ||
```javascript | ||
```typescript | ||
setCookie('name', 'value', { secure: true }) | ||
getCookie('name') // => 'value' | ||
getCookie('name') | ||
removeCookie('name') | ||
@@ -191,3 +176,3 @@ ``` | ||
A [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), allowing to control whether the browser is sending a cookie along with cross-site requests. | ||
A [`string`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#the-primitives-string-number-and-boolean), allowing to control whether the browser is sending a cookie along with cross-site requests. | ||
@@ -200,5 +185,5 @@ Default: not set. | ||
```javascript | ||
```typescript | ||
setCookie('name', 'value', { sameSite: 'strict' }) | ||
getCookie('name') // => 'value' | ||
getCookie('name') | ||
removeCookie('name') | ||
@@ -251,3 +236,5 @@ ``` | ||
```typescript | ||
import Cookies from 'typescript-cookie' | ||
import Cookies from 'typescript-cookie/dist/src/compat' | ||
Cookies.get('name') | ||
``` | ||
@@ -267,6 +254,2 @@ | ||
## Security | ||
For vulnerability reports, send an e-mail to `typescript-cookie at googlegroups dot com` | ||
## Releasing | ||
@@ -273,0 +256,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
30730
21
263