Aam-Digital/ndb-core

View on GitHub
src/app/utils/flatten-array/flatten-array.pipe.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { Pipe, PipeTransform } from "@angular/core";

/**
 * Flatten a deep array while also removing "undefined" items
 */
@Pipe({
  name: "flattenArray",
  standalone: true,
})
export class FlattenArrayPipe implements PipeTransform {
  transform(value): any[] {
    if (!Array.isArray(value)) {
      return value ? [value] : [];
    }

    return [].concat(...value.map((e) => this.transform(e)));
  }
}