Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/caojianping/tsx-cookie
Cookie的TypeScript封装,提供通用的API方法,同时支持泛型方法。
https://github.com/caojianping/tsx-cookie
cookie getitem jts-cookie setitem typescript
Last synced: 9 days ago
JSON representation
Cookie的TypeScript封装,提供通用的API方法,同时支持泛型方法。
- Host: GitHub
- URL: https://github.com/caojianping/tsx-cookie
- Owner: caojianping
- License: mit
- Created: 2019-09-03T10:06:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-30T06:46:27.000Z (over 1 year ago)
- Last Synced: 2024-10-14T01:17:49.210Z (about 1 month ago)
- Topics: cookie, getitem, jts-cookie, setitem, typescript
- Language: TypeScript
- Homepage:
- Size: 7.81 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tsx-cookie
Cookie的TypeScript封装,提供通用的API方法,同时支持泛型方法。
## Installing
Using npm:
```bash
$ npm install tsx-cookie
```## Example
```ts
import Cookie, {ICookieOption} from 'tsx-cookie';const name1 = 'cookie_number';
const value1 = 666888;
const expires1 = 3600 * 1000 * 2;// 过期时间
Cookie.setItem(name1, value1, expires1);// return true/false;
Cookie.getItem(name1);// return 666888/null;
Cookie.removeItem(name1);// return true/false;const name2 = 'cookie_string';
const value2 = 'hello world';
const expires2 = 3600 * 1000 * 2;
Cookie.setItem(name2, value2, expires2);// return true/false;
Cookie.getItem(name2);// return 'hello world'/null;
Cookie.removeItem(name2);// return true/false;Cookie.getAllKeys();// return ['cookie_number', 'cookie_string']
```## API
```ts
/**
* cookie选项接口
*/
export interface ICookieOption {
// 名称
name: string;// 数值
value: any;// 过期时间,单位:毫秒
expires?: number;// 路径
path?: string;
}
```
##### Cookie.setItem(name: string, value: T [, expires: number] [, path: string]): boolean
##### Cookie.setItems(options: Array): boolean
##### Cookie.getItem(name: string): T | null
##### Cookie.getAllKeys(): Array
##### Cookie.removeItem(name: string[, path: string]): boolean
##### Cookie.clear([, path: string]): void