You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
351 B

4 years ago
  1. 'use strict';
  2. module.exports = function transform(fn) {
  3. var _this = this;
  4. if (Array.isArray(this.items)) {
  5. this.items = this.items.map(fn);
  6. } else {
  7. var collection = {};
  8. Object.keys(this.items).forEach(function (key) {
  9. collection[key] = fn(_this.items[key], key);
  10. });
  11. this.items = collection;
  12. }
  13. return this;
  14. };