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
439 B

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