]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/array.pipe.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / pipes / array.pipe.ts
diff --git a/ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/array.pipe.ts b/ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/array.pipe.ts
new file mode 100755 (executable)
index 0000000..b61b0b0
--- /dev/null
@@ -0,0 +1,26 @@
+import { Pipe, PipeTransform } from '@angular/core';
+
+import * as _ from 'lodash';
+
+/**
+ * Convert the given value to an array.
+ */
+@Pipe({
+  name: 'array'
+})
+export class ArrayPipe implements PipeTransform {
+  /**
+   * Convert the given value into an array. If the value is already an
+   * array, then nothing happens, except the `force` flag is set.
+   * @param value The value to process.
+   * @param force Convert the specified value to an array, either it is
+   *              already an array.
+   */
+  transform(value: any, force = false): any[] {
+    let result = value;
+    if (!_.isArray(value) || (_.isArray(value) && force)) {
+      result = [value];
+    }
+    return result;
+  }
+}