1.6.2 • Published 3 months ago

@alicloud/cookie v1.6.2

Weekly downloads
140
License
MIT
Repository
-
Last release
3 months ago

@alicloud/cookie

(又一个)Cookie 的操作工具。

何时使用

需要读写浏览器 Cookie 时。本工具包有如下特点:

  • 无任何额外的依赖。
  • 考虑了安全传输(HTTPS)和跨站点访问(iframe)的问题,以最佳实践设定 SameSiteSecure 字段。了解更多:《在 HTTPS 和 iframe 下关于 SameSite + Secure 行为的研究
  • 考虑了三方 Cookie 禁用的问题,以最佳实践设定 Partitioned 字段。

API

getCookies()

获取当前页面可以访问到的全部 Cookie。

function getCookies(): Record<string, string>;
function getAllCookies(): Record<string, string>;

getAllCookies() 是一个别名。

getCookie()

获取当前页面可以访问到的某一个特定的 Cookie。

function getCookie(name: string): string | undefined;

setCookie()

写 Cookie。

function setCookie(name: string, value: string, extra: {
  // 默认为当前页面的二级域名,如 `.aliyun.com`
  // 如果是 IP 则为 IP,如 `127.0.0.1`
  domain?: string; 
  // 默认 '/'
  path?: string; 
  // 默认 180,若传入 0 则 Cookie 的 expires 为空,即成为 Session Cookie
  // 若传入 -1 则相当于删除 Cookie
  days?: number; 
  // 默认 true,传入 false 可保存原始的值(比如 value 已经由 base64 编码过)
  encoding?: boolean; 
} = {}): void;

deleteCookie()

删除特定 Cookie。本质上是设置 expires 为过去的时间,浏览器会自动清理过期的 Cookie。

function deleteCookie(name: string, extra: {
  domain?: string;
  path?: string;
} = {}): void;

canSetCookies()

嗅探是否可以在当前页写 Cookie。

注意,如果浏览器只是禁用了三方 Cookie(而非完全禁用 Cookie 功能),那还是可以通过 CHIPS 方案在兼容的浏览器下写 Partitioned Cookie。

由于本方法不接受参数,所以命名为复数,而非用来特指的单数。

function canSetCookies(): boolean;
1.7.0-beta.1

3 months ago

1.6.2

5 months ago

1.6.1

5 months ago

1.6.0

5 months ago

1.6.3-beta.1

5 months ago

1.6.0-beta.2

5 months ago

1.6.0-beta.1

7 months ago

1.6.0-alpha.2

11 months ago

1.6.0-alpha.1

11 months ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.2

2 years ago

1.4.0

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.2.0

2 years ago

1.2.1

2 years ago

1.1.82

2 years ago

1.3.0

2 years ago

1.1.78

3 years ago

1.1.76

3 years ago

1.1.79

3 years ago

1.1.81

3 years ago

1.1.80

3 years ago

1.1.60

3 years ago

1.1.59

3 years ago

1.1.58

3 years ago

1.1.57

3 years ago

1.1.56

3 years ago

1.1.54

3 years ago

1.1.53

3 years ago

1.1.52

3 years ago

1.1.50

3 years ago

1.1.49

3 years ago

1.1.47

3 years ago

1.1.46

3 years ago

1.1.45

3 years ago

1.1.44

3 years ago

1.1.43

3 years ago

1.1.39

3 years ago

1.1.41

3 years ago

1.1.40

3 years ago

1.1.38

3 years ago

1.1.37

3 years ago

1.1.29

3 years ago

1.1.34

3 years ago

1.1.33

3 years ago

1.1.32

3 years ago

1.1.36

3 years ago

1.1.28

3 years ago

1.1.27

3 years ago

1.1.26

3 years ago

1.1.25

3 years ago

1.1.24

3 years ago

1.1.23

3 years ago

1.1.22

3 years ago

1.1.20

3 years ago

1.1.17

3 years ago

1.1.16

3 years ago

1.1.15

3 years ago

1.1.14

3 years ago

1.1.13

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.52

4 years ago

1.0.51

4 years ago

1.0.48

4 years ago

1.0.49

4 years ago

1.0.50

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.43

4 years ago

1.0.41

4 years ago

1.0.39

4 years ago

1.0.40

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.31

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.7

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.1

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago

0.0.2

4 years ago