{"id":15015850,"url":"https://github.com/mainmatter/ember-cookies","last_synced_at":"2025-04-04T14:07:40.116Z","repository":{"id":6087944,"uuid":"53721571","full_name":"mainmatter/ember-cookies","owner":"mainmatter","description":"Cookies abstraction for Ember.js that works both in the browser as well as with Fastboot on the server","archived":false,"fork":false,"pushed_at":"2025-04-01T22:07:03.000Z","size":4352,"stargazers_count":115,"open_issues_count":17,"forks_count":47,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-03T10:41:03.974Z","etag":null,"topics":["cookies","ember","fastboot"],"latest_commit_sha":null,"homepage":null,"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/mainmatter.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":"2016-03-12T08:34:56.000Z","updated_at":"2025-03-31T06:24:12.000Z","dependencies_parsed_at":"2023-10-25T07:32:02.528Z","dependency_job_id":"099f9dfe-e046-47cd-9ca9-c1eddb860cf6","html_url":"https://github.com/mainmatter/ember-cookies","commit_stats":{"total_commits":754,"total_committers":33,"mean_commits":"22.848484848484848","dds":0.7188328912466844,"last_synced_commit":"91d3f37a28341e6d12c7dc88306efcc9daa8078c"},"previous_names":["simplabs/ember-cookies"],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mainmatter%2Fember-cookies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mainmatter%2Fember-cookies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mainmatter%2Fember-cookies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mainmatter%2Fember-cookies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mainmatter","download_url":"https://codeload.github.com/mainmatter/ember-cookies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190250,"owners_count":20898702,"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","ember","fastboot"],"created_at":"2024-09-24T19:48:03.132Z","updated_at":"2025-04-04T14:07:40.093Z","avatar_url":"https://github.com/mainmatter.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![CI](https://github.com/simplabs/ember-cookies/workflows/CI/badge.svg)\n\n# ember-cookies\n\n`ember-cookies` implements an abstract __cookie API that works both in the\nbrowser (via `document.cookie`) as well as with Fastboot in the server\ncontext__ (using the `request` and `response` accessible via the `fastBoot`\nservice).\n\n__Having access to cookies both in the browser as well as in FastBoot is key to\nbeing able to share a common session.__\n\n\u003e [!NOTE]\n\u003e ember-cookies was written and is maintained by [Mainmatter](https://mainmatter.com) and contributors.\n\u003e We offer consulting, training, and team augmentation for Ember.js – check out our [website](https://mainmatter.com/ember-consulting/) to learn more!\n\n## Installation\n\nInstall `ember-cookies` with\n\n`ember install ember-cookies`\n\n## Example Usage\n\n### Typescript\n\n```ts\n// app/controllers/index.ts\nimport { inject as service } from '@ember/service';\nimport Controller from '@ember/controller';\nimport CookiesService from 'ember-cookies/services/cookies';\n\ntype Cookie = { name: string; value?: string };\n\nexport default class IndexController extends Controller {\n  @service cookies!: CookiesService;\n\n  get allCookies(): Cookie[] {\n    this.cookies.write('now', new Date().getTime());\n\n    const cookies = this.cookies.read();\n    return Object.keys(cookies).reduce((acc, key) =\u003e {\n      let value = cookies[key];\n      acc.push({ name: key, value });\n\n      return acc;\n    }, [] as Cookie[]);\n  }\n\n  get singleCookie(): Cookie {\n    const cookie = this.cookies.read('now');\n    return { name: 'now', value: cookie };\n  }\n}\n```\n\n### Javascript\n\n```js\n// app/controllers/index.js\nimport Controller from '@ember/controller';\nimport { inject as service } from '@ember/service';\nimport { computed } from '@ember/object';\n\nexport default class ApplicationController extends Controller {\n  @service cookies;\n\n  @computed\n  get allCookies () {\n    let cookieService = this.cookies;\n    cookieService.write('now', new Date().getTime());\n\n    let cookies = cookieService.read();\n    return Object.keys(cookies).reduce((acc, key) =\u003e {\n      let value = cookies[key];\n      acc.push({ name: key, value });\n\n      return acc;\n    }, []);\n  }\n}\n```\n\n## API\n\nThe `cookies` service has methods for reading and writing cookies:\n\n* `read(name, options = {})`: reads the cookie with the given name, returns its\n  value as a `String`; options can be used to set `raw` (boolean, disables\n  URL-decoding the value).\n* `write(name, value, options = {})`: writes a cookie with the given name and\n  value; options can be used to set `domain`, `expires` (Date), `maxAge` (time\n  in seconds), `path`, `secure`, `raw` (boolean, disables URL-encoding the\n  value) and `sameSite`.\n* `clear(name, options = {})`: clears the cookie so that future reads do not\n  return a value; options can be used to specify `domain`, `path` or `secure`.\n* `exists(name)`: checks whether a cookie exists at all (even with a falsy\n  value) and returns `true` if that is the case or `false` otherwise.\n\n## Testing\n\n`ember-cookies` exposes the `clearAllCookies` test helper that clears\nall known cookies to reset state before and/or after tests:\n\n```js\nimport { module, test } from 'qunit';\nimport { setupTest } from 'ember-qunit';\nimport { clearAllCookies } from 'ember-cookies/test-support';\n\nmodule('Unit | Some Module', function (hooks) {\n  setupTest(hooks);\n\n  hooks.beforeEach(function () {\n    clearAllCookies();\n  });\n\n  // or you may wat to clear cookies after the test run\n  hooks.afterEach(function () {\n    clearAllCookies();\n  });\n});\n```\n\n## License\n\n`ember-cookies` is developed by and \u0026copy;\n[Mainmatter GmbH](http://mainmatter.com) and contributors. It is released under the\n[MIT License](https://github.com/simplabs/ember-simple-auth/blob/master/LICENSE).\n\n`ember-cookies` is not an official part of [Ember.js](http://emberjs.com) and\nis not maintained by the Ember.js Core Team.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmainmatter%2Fember-cookies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmainmatter%2Fember-cookies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmainmatter%2Fember-cookies/lists"}