Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mttankkeo/web_cookie
Ideally Implemented simple web client-cookie source code, and using Typescript.
https://github.com/mttankkeo/web_cookie
client-side cookie typescript-library web
Last synced: 4 days ago
JSON representation
Ideally Implemented simple web client-cookie source code, and using Typescript.
- Host: GitHub
- URL: https://github.com/mttankkeo/web_cookie
- Owner: MTtankkeo
- Created: 2023-10-02T18:20:55.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-25T16:28:59.000Z (12 months ago)
- Last Synced: 2024-11-09T13:26:08.003Z (about 2 months ago)
- Topics: client-side, cookie, typescript-library, web
- Language: TypeScript
- Homepage:
- Size: 44.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Web Cookie
Ideally Implemented simple web client-cookie source code, and using Typescript.
`See also: cookies are rarely controlled directly by the client.`> The example doesn't work in the local environment.
## Usage
### Get instance of cookie object
The following describes how to get a instance of cookie object.```ts
// Not Null-Safety
const version = Cookie.getObjectByKey("version");
``````ts
// Null-Safety
const version = Cookie.getObjectByKeyWithNullSafe("version", "1.0.0");
``````ts
const cookies: CookieObject[] = Cookie.objects;
```### Set value of cookie object
The following describes how to define a value of cookie object.```ts
// Useing setter
version.value = "1.0.0";// Useing function.
version.setValue("1.0.0");
```## Listener
The following describes how to register a callback function that is called whenever the value of a cookie object updates.### globally register listener
```ts
Cookie.addListener({
key: "version",
listener(value: string) {
console.log(`Update to ${value}`);
},
})
```### Register listener by instance
```ts
const version = Cookie.getObjectByKeyWithNullSafe("version", "1.0.0");version.addListener(value => {
console.log(`Update to ${value}`);
});
```