mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
fix: comparison for empty/nil, fixes #321
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { Drop } from './drop'
|
||||
import { Comparable } from './comparable'
|
||||
import { isObject, isString, isArray } from '../util/underscore'
|
||||
import { isObject, isString, isArray, toValue } from '../util/underscore'
|
||||
|
||||
export class EmptyDrop extends Drop implements Comparable {
|
||||
public equals (value: any) {
|
||||
if (value instanceof EmptyDrop) return false
|
||||
value = toValue(value)
|
||||
if (isString(value) || isArray(value)) return value.length === 0
|
||||
if (isObject(value)) return Object.keys(value).length === 0
|
||||
return false
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Drop } from './drop'
|
||||
import { Comparable } from './comparable'
|
||||
import { isNil, toValue } from '../util/underscore'
|
||||
import { BlankDrop } from '../drop/blank-drop'
|
||||
|
||||
export class NullDrop extends Drop implements Comparable {
|
||||
public equals (value: any) {
|
||||
return isNil(toValue(value)) || value instanceof BlankDrop
|
||||
return isNil(toValue(value))
|
||||
}
|
||||
public gt () {
|
||||
return false
|
||||
|
||||
+3
-2
@@ -2,11 +2,12 @@ import { NullDrop } from '../drop/null-drop'
|
||||
import { EmptyDrop } from '../drop/empty-drop'
|
||||
import { BlankDrop } from '../drop/blank-drop'
|
||||
|
||||
const nil = new NullDrop()
|
||||
export const literalValues = {
|
||||
'true': true,
|
||||
'false': false,
|
||||
'nil': new NullDrop(),
|
||||
'null': new NullDrop(),
|
||||
'nil': nil,
|
||||
'null': nil,
|
||||
'empty': new EmptyDrop(),
|
||||
'blank': new BlankDrop()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user