helper.js 724 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. class Helper {
  3. constructor() {
  4. this.store = {};
  5. }
  6. /**
  7. * @returns {Object} - The plugin store
  8. */
  9. list() {
  10. return this.store;
  11. }
  12. /**
  13. * Get helper plugin function by name
  14. * @param {String} name - The name of the helper plugin
  15. * @returns {Function}
  16. */
  17. get(name) {
  18. return this.store[name];
  19. }
  20. /**
  21. * Register a helper plugin
  22. * @param {String} name - The name of the helper plugin
  23. * @param {Function} fn - The helper plugin function
  24. */
  25. register(name, fn) {
  26. if (!name) throw new TypeError('name is required');
  27. if (typeof fn !== 'function') throw new TypeError('fn must be a function');
  28. this.store[name] = fn;
  29. }
  30. }
  31. module.exports = Helper;