whenEmpty.js 446 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. module.exports = function whenEmpty(fn, defaultFn) {
  3. if (Array.isArray(this.items) && !this.items.length) {
  4. return fn(this);
  5. }
  6. if (!Object.keys(this.items).length) {
  7. return fn(this);
  8. }
  9. if (defaultFn !== undefined) {
  10. if (Array.isArray(this.items) && this.items.length) {
  11. return defaultFn(this);
  12. }
  13. if (Object.keys(this.items).length) {
  14. return defaultFn(this);
  15. }
  16. }
  17. return this;
  18. };