{"id":15825328,"url":"https://github.com/theodorejb/es-cookie","last_synced_at":"2025-04-30T21:27:27.424Z","repository":{"id":57226903,"uuid":"81019781","full_name":"theodorejb/es-cookie","owner":"theodorejb","description":"A simple, lightweight module for handling cookies","archived":false,"fork":false,"pushed_at":"2024-04-19T17:09:42.000Z","size":32,"stargazers_count":46,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-27T06:06:54.835Z","etag":null,"topics":["cookies","javascript","module"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theodorejb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-05T20:26:59.000Z","updated_at":"2025-03-21T17:35:39.000Z","dependencies_parsed_at":"2024-06-18T15:25:02.545Z","dependency_job_id":null,"html_url":"https://github.com/theodorejb/es-cookie","commit_stats":{"total_commits":27,"total_committers":4,"mean_commits":6.75,"dds":"0.14814814814814814","last_synced_commit":"cac86beb697b8bf8ee6e557508021d41e850ac05"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theodorejb%2Fes-cookie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theodorejb%2Fes-cookie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theodorejb%2Fes-cookie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theodorejb%2Fes-cookie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theodorejb","download_url":"https://codeload.github.com/theodorejb/es-cookie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251784733,"owners_count":21643348,"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":["cookies","javascript","module"],"created_at":"2024-10-05T09:07:53.280Z","updated_at":"2025-04-30T21:27:27.400Z","avatar_url":"https://github.com/theodorejb.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# es-cookie\n[![NPM version](https://img.shields.io/npm/v/es-cookie.svg)](https://www.npmjs.org/package/es-cookie)\n\nA simple, lightweight module for handling cookies\n\n* Includes TypeScript definitions\n* Published as a native ES module\n* [RFC 6265](https://tools.ietf.org/html/rfc6265) compliant\n* No dependencies\n* Originally based on js-cookie, but rewritten in TypeScript with a lean, type-safe API\n\n## Installation\n\n`npm install es-cookie`\n\n## Usage\n\nImport entire module:\n\n```javascript\nimport * as Cookies from 'es-cookie';\n\nCookies.set('name', 'value');\nCookies.get('name'); // =\u003e 'value'\n```\n\nAlternatively, just import the functions you need:\n\n```javascript\nimport {set as setCookie, get as getCookie} from 'es-cookie';\n\nsetCookie('name', 'value');\ngetCookie('name'); // =\u003e 'value'\n```\n\nCreate a cookie that expires 7 days from now, valid across the entire site:\n\n```javascript\nCookies.set('name', 'value', { expires: 7 });\n```\n\n## Functions\n\n### set\n\nCreates a new cookie. The first parameter is for the name, and the second\nfor the value. The third parameter is optional and allows you to modify\nattributes for the new cookie (see the [Attributes section](#attributes) below).\n\n```javascript\n// Create an expiring cookie, valid to the path of the current page:\nCookies.set('name', 'value', { expires: 7, path: '' });\n```\n\n### get\n\nReturns a single cookie with the specified name, or `undefined` if the cookie doesn't exist.\n\n```javascript\nCookies.get('name'); // =\u003e 'value'\nCookies.get('nothing'); // =\u003e undefined\n```\n\n### getAll\n\nReturns an object containing all visible cookies.\n\n```javascript\nCookies.getAll(); // =\u003e { name: 'value' }\n```\n\n### remove\n\nDeletes a single cookie by name.\n\n```javascript\nCookies.remove('name');\n```\n\n*IMPORTANT! When removing a cookie, you must pass the exact same path and\ndomain attributes that were used to set the cookie, unless you're using\nthe default attributes.*\n\n```javascript\nCookies.set('name', 'value', { path: '' });\nCookies.remove('name'); // fail!\nCookies.remove('name', { path: '' }); // removed!\n```\n\n*Note: Removing a nonexistent cookie does not raise an exception or return a value.*\n\n### parse\n\nParses a cookie string (e.g. `document.cookie`) and returns the names/values as an object.\n\n```javascript\nCookies.parse('c=v; name=value'); // =\u003e {c: 'v', name: 'value'}\n```\n\n### encode\n\nTakes a name, value, and attributes object and returns an encoded string\nwhich can be used to create a new cookie.\n\n```javascript\nCookies.encode('c', 'v', {secure: true}); // =\u003e 'c=v; Secure'\n```\n\n## Attributes\n\n### expires\n\nDefine when the cookie will be removed. Value can be a number which\nwill be interpreted as days from time of creation or a `Date` instance.\nIf omitted, the cookie becomes a session cookie.\n\nTo create a cookie that expires in less than a day, use a `Date` object.\n\n**Default:** Cookie is removed when the user closes the browser.\n\n**Examples:**\n\n```javascript\nCookies.set('name', 'value', { expires: 365 });\nCookies.get('name'); // =\u003e 'value'\nCookies.remove('name');\n\nlet twoHoursFromNow = new Date();\ntwoHoursFromNow.setHours(twoHoursFromNow.getHours() + 2);\nCookies.set('name', 'value', { expires: twoHoursFromNow });\n```\n\n### path\n\nA string indicating the path where the cookie is visible.\n\n**Default:** `/`\n\n**Examples:**\n\n```javascript\nCookies.set('name', 'value', { path: '' });\nCookies.get('name'); // =\u003e 'value'\nCookies.remove('name', { path: '' });\n```\n\n### domain\n\nA string indicating a valid domain where the cookie should be visible.\nThe cookie will also be visible to all subdomains.\n\n**Default:** Cookie is visible only to the domain or subdomain of the page where the cookie was created.\n\n**Examples:**\n\nAssuming a cookie that is being created on `site.com`:\n\n```javascript\nCookies.set('name', 'value', { domain: 'subdomain.site.com' });\nCookies.get('name'); // =\u003e undefined (need to read at 'subdomain.site.com')\n```\n\n### secure\n\nEither `true` or `false`, indicating if the cookie transmission requires a secure protocol (https).\n\n**Default:** No secure protocol requirement.\n\n**Examples:**\n\n```javascript\nCookies.set('name', 'value', { secure: true });\nCookies.get('name'); // =\u003e 'value'\nCookies.remove('name');\n```\n\n### sameSite\n\nA string with a value of either `strict`, `lax`, or `none`. When enabled,\nsupporting browsers will only send the cookie if the request originates\nfrom the same website the cookie is from. This provides some protection\nagainst cross-site request forgery attacks (CSRF).\n\nThe strict mode withholds the cookie from any kind of cross-site usage\n(including inbound links from external sites). The lax mode withholds the\ncookie on cross-domain subrequests (e.g. images or frames), but sends it\nwhenever a user navigates safely from an external site (e.g. by following\na link).\n\n**Default:** No same-site requirement is set - the browser default will be used.\n\n**Examples:**\n\n```javascript\nCookies.set('name', 'value', { sameSite: 'strict' });\nCookies.set('other', 'value', { sameSite: 'lax' });\n```\n\n### partitioned\n\nEither `true` or `false`, indicating that the cookie should be stored using partitioned storage.\nSee [Cookies Having Independent Partitioned State (CHIPS)](https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies) for more details.\n\n**Default:** Cookie will not be partitioned.\n\n**Examples:**\n\n```javascript\nCookies.set('name', 'value', { secure: true, partitioned: true });\nCookies.get('name'); // =\u003e 'value'\nCookies.remove('name');\n```\n\n## Encoding\n\nThis project is [RFC 6265](http://tools.ietf.org/html/rfc6265#section-4.1.1)\ncompliant. Special characters that are not allowed in the cookie name or\nvalue are encoded with their UTF-8 Hex equivalent using\n[percent-encoding](http://en.wikipedia.org/wiki/Percent-encoding).\n\nThe only character allowed in cookie names or values that is still encoded\nis the percent (`%`) character. It is escaped in order to interpret\npercent input as literal.\n\n## Author\n\nTheodore Brown  \n\u003chttps://theodorejb.me\u003e\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheodorejb%2Fes-cookie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheodorejb%2Fes-cookie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheodorejb%2Fes-cookie/lists"}