mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
feat: where filter, working on #118
doc: https://shopify.github.io/liquid/filters/where/ ruby impl: https://github.com/Shopify/liquid/blob/14cd011cb5eef042af192ad5294c8f0e1ae89f06/lib/liquid/standardfilters.rb
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { last } from '../../util/underscore'
|
||||
import { isTruthy } from '../../render/syntax'
|
||||
|
||||
export default {
|
||||
'join': (v: any[], arg: string) => v.join(arg === undefined ? ' ' : arg),
|
||||
@@ -20,5 +21,8 @@ export default {
|
||||
u[String(val)] = true
|
||||
return true
|
||||
})
|
||||
},
|
||||
'where': function<T> (arr: T[], property: string, value?: any): T[] {
|
||||
return arr.filter(obj => value === undefined ? isTruthy(obj[property]) : obj[property] === value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user