{"id":13734698,"url":"https://github.com/ScottHamper/Cookies","last_synced_at":"2025-05-08T11:30:37.270Z","repository":{"id":2772568,"uuid":"3771441","full_name":"ScottHamper/Cookies","owner":"ScottHamper","description":"JavaScript Client-Side Cookie Manipulation Library","archived":false,"fork":false,"pushed_at":"2020-05-16T21:49:46.000Z","size":252,"stargazers_count":1771,"open_issues_count":14,"forks_count":169,"subscribers_count":47,"default_branch":"master","last_synced_at":"2024-05-17T16:49:18.217Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ScottHamper.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-20T03:23:26.000Z","updated_at":"2024-04-16T20:33:33.000Z","dependencies_parsed_at":"2022-08-05T22:16:09.872Z","dependency_job_id":null,"html_url":"https://github.com/ScottHamper/Cookies","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScottHamper%2FCookies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScottHamper%2FCookies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScottHamper%2FCookies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScottHamper%2FCookies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScottHamper","download_url":"https://codeload.github.com/ScottHamper/Cookies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213758655,"owners_count":15634354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T03:00:58.976Z","updated_at":"2024-08-03T03:03:55.793Z","avatar_url":"https://github.com/ScottHamper.png","language":"JavaScript","funding_links":[],"categories":["awesome-web-storage [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)","Storage","JavaScript","Storage [🔝](#readme)","front-end-development","存储"],"sub_categories":["Different Storage APIs","Runner","运行器","运行器e2e测试"],"readme":"# Cookies.js\n\nCookies.js is a small client-side javascript library that makes managing cookies easy.\n\n[Features](#features)  \n[Browser Compatibility](#browser-compatibility)  \n[Getting the Library](#getting-the-library)  \n[Use in CommonJS/Node Environments Without `window`](#use-in-commonjsnode-environments-without-window)  \n[A Note About Encoding](#a-note-about-encoding)  \n[API Reference](#api-reference)\n\n## Features\n- [RFC6265](http://www.rfc-editor.org/rfc/rfc6265.txt) compliant\n- Cross browser\n- Lightweight\n- No dependencies\n- Public domain\n- Supports AMD / CommonJS loaders\n\n## Browser Compatibility\nThe following browsers have passed all of the automated Cookies.js tests:\n- Chrome\n- Firefox 3+\n- Safari 4+\n- Opera 10+\n- Internet Explorer 6+\n\n## Getting the Library\n#### Direct downloads\n- [v1.2.3 Minified](https://raw.github.com/ScottHamper/Cookies/1.2.3/dist/cookies.min.js) (~1.2 KB gzipped)\n- [v1.2.3 Unminified](https://raw.github.com/ScottHamper/Cookies/1.2.3/dist/cookies.js) (~1.9 KB gzipped)\n\n#### Node Package Manager\n`npm install cookies-js`\n\n#### Bower\n`bower install cookies-js`\n\n## Use in CommonJS/Node Environments Without `window`\nIn environments where there is no native `window` object, Cookies.js will export a factory method\nthat accepts a `window` instance. For example, using [jsdom](https://github.com/tmpvar/jsdom), you\nmight do something like:\n\n```javascript\nvar jsdom = require('jsdom');\nvar window = jsdom.jsdom().parentWindow;\nvar Cookies = require('cookies-js')(window);\n\n// Use Cookies as you normally would\n```\n\n## A Note About Encoding\n[RFC6265](http://www.rfc-editor.org/rfc/rfc6265.txt) defines a strict set of allowed characters for\ncookie keys and values. In order to effectively allow any character to be used in a key or value,\nCookies.js will URI encode disallowed characters in their UTF-8 representation. As such, Cookies.js\nalso expects cookie keys and values to already be URI encoded in a UTF-8 representation when it\naccesses cookies. Keep this in mind when working with cookies on the server side.\n\n#### .NET Users\nDo not use [HttpUtility.UrlEncode](http://msdn.microsoft.com/en-us/library/4fkewx0t.aspx) and\n[HttpUtility.UrlDecode](http://msdn.microsoft.com/en-us/library/adwtk1fy.aspx) on cookie keys or\nvalues. `HttpUtility.UrlEncode` will improperly escape space characters to `'+'` and lower case every\nescape sequence. `HttpUtility.UrlDecode` will improperly unescape every `'+'` to a space character.\nInstead, use\n[System.Uri.EscapeDataString](http://msdn.microsoft.com/en-us/library/system.uri.escapedatastring.aspx)\nand [System.Uri.UnescapeDataString](http://msdn.microsoft.com/en-us/library/system.uri.unescapedatastring.aspx).\n\n\n## API Reference\n\n**Methods**  \n[Cookies.set(key, value [, options])](#cookiessetkey-value--options)  \n[Cookies.get(key)](#cookiesgetkey)  \n[Cookies.expire(key [, options])](#cookiesexpirekey--options)\n\n**Properties**  \n[Cookies.enabled](#cookiesenabled)  \n[Cookies.defaults](#cookiesdefaults)\n\n### Methods\n\n#### Cookies.set(key, value [, options])\n*Alias: Cookies(key, value [, options])*\n\nSets a cookie in the document. If the cookie does not already exist, it will be created. Returns the `Cookies` object.\n\n| Option    | Description                                                                                      | Default     |\n| --------: | ------------------------------------------------------------------------------------------------ | ----------- |\n|    *path* | A string value of the path of the cookie                                                         | `\"/\"`       |\n|  *domain* | A string value of the domain of the cookie                                                       | `undefined` |\n| *expires* | A number (of seconds), a date parsable string, or a `Date` object of when the cookie will expire | `undefined` |\n|  *secure* | A boolean value of whether or not the cookie should only be available over SSL                   | `false`     |\n\nA default value for any option may be set in the `Cookies.defaults` object.\n\n**Example Usage**\n```javascript\n// Setting a cookie value\nCookies.set('key', 'value');\n\n// Chaining sets together\nCookies.set('key', 'value').set('hello', 'world');\n\n// Setting cookies with additional options\nCookies.set('key', 'value', { domain: 'www.example.com', secure: true });\n\n// Setting cookies with expiration values\nCookies.set('key', 'value', { expires: 600 }); // Expires in 10 minutes\nCookies.set('key', 'value', { expires: '01/01/2012' });\nCookies.set('key', 'value', { expires: new Date(2012, 0, 1) });\nCookies.set('key', 'value', { expires: Infinity });\n\n// Using the alias\nCookies('key', 'value', { secure: true });\n```\n\n#### Cookies.get(key)\n*Alias: Cookies(key)*\n\nReturns the value of the most locally scoped cookie with the specified key.\n\n**Example Usage**\n```javascript\n// First set a cookie\nCookies.set('key', 'value');\n\n// Get the cookie value\nCookies.get('key'); // \"value\"\n\n// Using the alias\nCookies('key'); // \"value\"\n```\n    \n#### Cookies.expire(key [, options])\n*Alias: Cookies(key, `undefined` [, options])*\n\nExpires a cookie, removing it from the document. Returns the `Cookies` object.\n\n| Option    | Description                                                                                      | Default     |\n| --------: | ------------------------------------------------------------------------------------------------ | ----------- |\n|    *path* | A string value of the path of the cookie                                                         | `\"/\"`       |\n|  *domain* | A string value of the domain of the cookie                                                       | `undefined` |\n\nA default value for any option may be set in the `Cookies.defaults` object.\n\n**Example Usage**\n```javascript\n// First set a cookie and get its value\nCookies.set('key', 'value').get('key'); // \"value\"\n\n// Expire the cookie and try to get its value\nCookies.expire('key').get('key'); // undefined\n\n// Using the alias\nCookies('key', undefined);\n```\n    \n\n### Properties\n\n#### Cookies.enabled\nA boolean value of whether or not the browser has cookies enabled.\n\n**Example Usage**\n```javascript\nif (Cookies.enabled) {\n    Cookies.set('key', 'value');\n}\n```\n\n#### Cookies.defaults\nAn object representing default options to be used when setting and expiring cookie values.\n\n| Option    | Description                                                                                      | Default     |\n| --------: | ------------------------------------------------------------------------------------------------ | ----------- |\n|    *path* | A string value of the path of the cookie                                                         | `\"/\"`       |\n|  *domain* | A string value of the domain of the cookie                                                       | `undefined` |\n| *expires* | A number (of seconds), a date parsable string, or a `Date` object of when the cookie will expire | `undefined` |\n|  *secure* | A boolean value of whether or not the cookie should only be available over SSL                   | `false`     |\n\n**Example Usage**\n```javascript\nCookies.defaults = {\n    path: '/',\n    secure: true\n};\n\nCookies.set('key', 'value'); // Will be secure and have a path of '/'\nCookies.expire('key'); // Will expire the cookie with a path of '/'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FScottHamper%2FCookies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FScottHamper%2FCookies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FScottHamper%2FCookies/lists"}