{"id":18589629,"url":"https://github.com/alex1990/tiny-cookie","last_synced_at":"2025-04-04T08:09:59.465Z","repository":{"id":30825895,"uuid":"34383239","full_name":"Alex1990/tiny-cookie","owner":"Alex1990","description":"A tiny cookie manipulation plugin for the browser.","archived":false,"fork":false,"pushed_at":"2024-03-28T20:14:35.000Z","size":469,"stargazers_count":112,"open_issues_count":3,"forks_count":14,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T07:09:35.725Z","etag":null,"topics":["cookie","tiny","tiny-cookie"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Alex1990.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2015-04-22T10:07:11.000Z","updated_at":"2024-12-19T00:04:10.000Z","dependencies_parsed_at":"2024-06-18T13:21:14.040Z","dependency_job_id":"7b9f73ba-043b-409e-9554-d3f687808045","html_url":"https://github.com/Alex1990/tiny-cookie","commit_stats":{"total_commits":132,"total_committers":9,"mean_commits":"14.666666666666666","dds":"0.12878787878787878","last_synced_commit":"dc3f0bd5bfa0a4044445f6a2dc01b401e0b60653"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alex1990%2Ftiny-cookie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alex1990%2Ftiny-cookie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alex1990%2Ftiny-cookie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alex1990%2Ftiny-cookie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alex1990","download_url":"https://codeload.github.com/Alex1990/tiny-cookie/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142074,"owners_count":20890653,"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":["cookie","tiny","tiny-cookie"],"created_at":"2024-11-07T00:52:49.337Z","updated_at":"2025-04-04T08:09:59.440Z","avatar_url":"https://github.com/Alex1990.png","language":"JavaScript","readme":"# tiny-cookie\n\n[![Node.js CI](https://github.com/Alex1990/tiny-cookie/actions/workflows/node.js.yml/badge.svg?branch=main)](https://github.com/Alex1990/tiny-cookie/actions/workflows/node.js.yml)\n[![codecov](https://codecov.io/gh/Alex1990/tiny-cookie/branch/main/graph/badge.svg)](https://codecov.io/gh/Alex1990/tiny-cookie)\n[![npm](https://img.shields.io/npm/dm/tiny-cookie.svg)](https://www.npmjs.com/package/tiny-cookie)\n[![npm](https://img.shields.io/npm/v/tiny-cookie.svg)](https://www.npmjs.com/package/tiny-cookie)\n\n**English | [简体中文](README_zh-CN.md)**\n\nA tiny cookie manipulation plugin for browser.\n\n**Upgrade from 1.x to 2.x**: You can check the [CHANGELOG.md](https://github.com/Alex1990/tiny-cookie/blob/master/CHANGELOG.md#v200)\n\n\u003e If you're used tiny-cookie, then you may be interest in [micell](https://micell.org), a collection of functions focusing on web development.\n\n## Install\n\n**NPM:**\n\n```bash\nnpm install tiny-cookie\n```\n\n## Usage\n\n**ES2015 (recommended)**\n\n```js\n// You can import all methods.\nimport * as Cookies from 'tiny-cookie'\n\n// Or, you can import the methods as needed.\nimport { isEnabled, get, set, remove } from 'tiny-cookie'\n\n// No alias required, just imports.\nimport { isCookieEnabled, getCookie, setCookie, removeCookie } from 'tiny-cookie'\n```\n\nThe tiny-cookie will expose an object `Cookie` on the global scope. Also, it can be as a CommonJS/AMD module (**recommended**).\n\n## APIs\n\n### isEnabled()\n\n**Alias: isCookieEnabled**\n\nCheck if the cookie is enabled.\n\n### get(key)\n\n**Alias: getCookie**\n\nGet the cookie value with decoding, using `decodeURIComponent`.\n\n### getRaw(key)\n\n**Alias: getRawCookie**\n\nGet the cookie value without decoding.\n\n### getAll()\n\n**Alias: getAllCookies**\n\nGet all cookies with decoding, using `decodeURIComponent`.\n\n### set(key, value, options)\n\n**Alias: setCookie**\n\nSet a cookie with encoding the value, using `encodeURIComponent`. The `options` parameter is an object. And its property can be a valid cookie option, such as `path`(default: root path `/`), `domain`, `expires`/`max-age`, `samesite` or `secure` (Note: the `secure` flag will be set if it is an truthy value, such as `true`, or it will be not set). For example, you can set the expiration:\n\n```js\nimport { setCookie } from 'tiny-cookie';\n\nconst now = new Date;\nnow.setMonth(now.getMonth() + 1);\n\nsetCookie('foo', 'Foo', { expires: now.toGMTString() });\n```\n\nThe `expires` property value can accept a `Date` object, a parsable date string (parsed by `Date.parse()`), an integer (unit: day) or a numeric string with a suffix character which specifies the time unit.\n\n| Unit suffix | Representation |\n| ----------- | -------------- |\n| Y           | One year       |\n| M           | One month      |\n| D           | One day        |\n| h           | One hour       |\n| m           | One minute     |\n| s           | One second     |\n\n**Examples:**\n\n```js\nimport { setCookie } from 'tiny-cookie';\nconst date = new Date;\n\ndate.setDate(date.getDate() + 21);\n\nsetCookie('dateObject', 'A date object', { expires: date });\nsetCookie('dateString', 'A parsable date string', { expires: date.toGMTString() });\nsetCookie('integer', 'Seven days later', { expires: 7 });\nsetCookie('stringSuffixY', 'One year later', { expires: '1Y' });\nsetCookie('stringSuffixM', 'One month later', { expires: '1M' });\nsetCookie('stringSuffixD', 'One day later', { expires: '1D' });\nsetCookie('stringSuffixh', 'One hour later', { expires: '1h' });\nsetCookie('stringSuffixm', 'Ten minutes later', { expires: '10m' });\nsetCookie('stringSuffixs', 'Thirty seconds later', { expires: '30s' });\n```\n\n### setRaw(key, value, options)\n\n**Alias: setRawCookie**\n\nSet a cookie without encoding.\n\n### remove(key, options)\n\n**Alias: removeCookie**\n\nRemove a cookie on the current domain. If you want to remove the parent domain's cookie, you can use the `options` parameter, such as `remove('cookieName', { domain: 'parentdomain.com' })`.\n\n## FAQ\n\n1. How to use JSON as the encoder/decoder?\n\nYou can write your cookie get and set methods with JSON support easily:\n\n```js\nimport { getCookie, setCookie } from 'tiny-cookie';\n\nexport const getJSON = (key) =\u003e getCookie(key, JSON.parse);\nexport const setJSON = (key, value, options) =\u003e setCookie(key, value, JSON.stringify, options);\n```\n\n## License\n\nMIT.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex1990%2Ftiny-cookie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falex1990%2Ftiny-cookie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex1990%2Ftiny-cookie/lists"}