feat: compact filter

This commit is contained in:
harttle
2021-02-04 22:47:34 +08:00
parent ec4a711e00
commit f42c217fc0
3 changed files with 14 additions and 4 deletions
+5 -1
View File
@@ -1,4 +1,4 @@
import { isArray, last as arrayLast } from '../../util/underscore'
import { isArray, isNil, last as arrayLast } from '../../util/underscore'
import { toArray } from '../../util/collection'
import { isTruthy } from '../../render/boolean'
import { FilterImpl } from '../../template/filter/filter-impl'
@@ -24,6 +24,10 @@ export function map<T1, T2> (this: FilterImpl, arr: Scope[], property: string) {
return toArray(arr).map(obj => this.context.getFromScope(obj, property.split('.')))
}
export function compact<T> (this: FilterImpl, arr: T[]) {
return toArray(arr).filter(x => !isNil(x))
}
export function concat<T1, T2> (v: T1[], arg: T2[] | T2): (T1 | T2)[] {
return toArray(v).concat(arg)
}