ScottHamper / Cookies

JavaScript Client-Side Cookie Manipulation Library
The Unlicense
1.77k stars 169 forks source link

Method to retrieve all cookies #51

Closed Florian-R closed 9 years ago

Florian-R commented 9 years ago

Just asking if this is something welcome before i open a PR. It's sometimes convenient to retrieve all the cookies in a raw. Quickly done implementation


function getAll () {
  var len = Cookies._cacheKeyPrefix.length

  if (Cookies._cachedDocumentCookie !== Cookies._document.cookie) {
    Cookies._renewCache();
  }

  var cookies = {}

  for (key in Cookies._cache) {
    cookies[key.substr(len)] = decodeURIComponent(Cookies._cache[key])
  }

  return cookies
}

Mind a PR for this, or you'd prefer to keep the API ultra slick?

ScottHamper commented 9 years ago

Hey @Florian-R ,

This feature has actually been requested in the past. You can read https://github.com/ScottHamper/Cookies/pull/12 for background.

If you can clearly explain a real world use case where this ends up being a valuable feature, then I would absolutely consider adding it.

Florian-R commented 9 years ago

Sorry for the dupe, missed #12 when I’ve searched for precedent issues. Going to close this, as I wanted this merely as a convenience (not having to keep an array of all possible keys and iterate on them), but after reading the initial issue, I agree there's subtle edge-case. Thanks for taking the time to answer to this.