helpers.js 921 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. /**
  3. * Returns a set/get style internal storage bucket.
  4. *
  5. * @return {object} the API to set and retrieve data
  6. */
  7. module.exports.createStore = function () {
  8. var bucket = {};
  9. /**
  10. * Sets a property on the store, with the given value.
  11. *
  12. * @param {string} property an identifier for the data
  13. * @param {*} value the value of the data being stored
  14. * @return {function} the set function itself to allow chaining
  15. */
  16. var set = function (property, value) {
  17. bucket[property] = value;
  18. return set;
  19. };
  20. /**
  21. * Returns the store item asked for, otherwise all of the items.
  22. *
  23. * @param {string|undefined} property the property being requested
  24. * @return {*} the store item that was matched
  25. */
  26. var get = function (property) {
  27. if (!property) {
  28. return bucket;
  29. }
  30. return bucket[property];
  31. };
  32. return {
  33. set: set,
  34. get: get
  35. };
  36. };