Code Monkey home page Code Monkey logo

cookie-monster's People

Contributors

cameronr avatar ccheever avatar euwest avatar iclanzan avatar jacobrask avatar jasonkarns avatar kahnvex avatar todesignandconquer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cookie-monster's Issues

Conform to Storage api?

Cookies are the old-school way to store data client side. local storage and session storage, both conforming to the Storage API, are now the recommended way to store client-only data (in general).

Cookies and local/session stores all function fundamentally the same way: as key/value stores. Of course, cookies have additional properties (path, domain, secure, etc), but that's really just metadata on the key/value pair.

I would like to propose that the cookie-monster API conform to the Storage API such that switching between stores is trivial.

As the current API is only get and set, a first step could be to alias getItem to get and setItem to set. Following that, removeItem and clear methods could be added for safe removal of single items and the entire cookie string, respectively. And finally, for completeness, key and length could be added (though they are clearly low on the priority list).

I don't see any backwards compatibility issues if getItem and setItem are aliased to the current methods. Of course, if it's desired to actually deprecate get/set then it would be beneficial to have them aliased for a while with warning messages, and then remove the get/set variants in a major version bump.

More than happy to submit a couple PRs if this sounds like something that might be acceptable.

Refactoring and future maintenance

I'm still using the old version of Cookie monster in some of my projects but the version 0.2.1 is fairly outdated and non-maintained. I'd like to refactor it in a proper ES6 format and bundle it into different formats using Rollup. If you give me an ok, I'll prepare the pull request for version 1.0. Additionally, I'm also interested in maintaining the package since, well, I'm using it already and had contributed to it in the past.

Change proposal:

  • Refactor to ES6
  • Expose cookie-monster class instead of an instance that is implicitly initialised with global document object
  • Deprecate legacy .get(), .set() and .remove() methods
  • Implement .key(n) method and .length property to completely conform to localStorage API
  • Add argument type checks to .getItem() and .removeItem()
  • Use Rollup + Buble to build modules in all necessary formats (ESM, commonjs and universal)
  • Replace Karma + Mocha + Chai bundle with Jest for testing to decrease the number of explicit development dependencies

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.