mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
refactor: Drop.prototype.value => valueOf
This commit is contained in:
@@ -5,7 +5,7 @@ import { EmptyDrop } from '../drop/empty-drop'
|
||||
export class BlankDrop extends EmptyDrop {
|
||||
equals (value: any) {
|
||||
if (value === false) return true
|
||||
if (isNil(isDrop(value) ? value.value() : value)) return true
|
||||
if (isNil(isDrop(value) ? value.valueOf() : value)) return true
|
||||
if (isString(value)) return /^\s*$/.test(value)
|
||||
return super.equals(value)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ export class EmptyDrop extends Drop implements IDrop, IComparable {
|
||||
leq () {
|
||||
return false
|
||||
}
|
||||
value () {
|
||||
valueOf () {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,9 +2,9 @@ import { Drop } from './drop'
|
||||
import { isFunction } from '../util/underscore'
|
||||
|
||||
export interface IDrop {
|
||||
value(): any
|
||||
valueOf(): any
|
||||
}
|
||||
|
||||
export function isDrop (value: any): value is IDrop {
|
||||
return value instanceof Drop && isFunction((value as any).value)
|
||||
return value instanceof Drop && isFunction((value as any).valueOf)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { BlankDrop } from '../drop/blank-drop'
|
||||
|
||||
export class NullDrop extends Drop implements IDrop, IComparable {
|
||||
equals (value: any) {
|
||||
return isNil(isDrop(value) ? value.value() : value) || value instanceof BlankDrop
|
||||
return isNil(isDrop(value) ? value.valueOf() : value) || value instanceof BlankDrop
|
||||
}
|
||||
gt () {
|
||||
return false
|
||||
@@ -20,7 +20,7 @@ export class NullDrop extends Drop implements IDrop, IComparable {
|
||||
leq () {
|
||||
return false
|
||||
}
|
||||
value () {
|
||||
valueOf () {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export function parseExp (exp: string, scope: Scope): any {
|
||||
|
||||
export function evalExp (str: string, scope: Scope): any {
|
||||
const value = parseExp(str, scope)
|
||||
return isDrop(value) ? value.value() : value
|
||||
return isDrop(value) ? value.valueOf() : value
|
||||
}
|
||||
|
||||
function parseValue (str: string, scope: Scope): any {
|
||||
@@ -93,7 +93,7 @@ function parseValue (str: string, scope: Scope): any {
|
||||
|
||||
export function evalValue (str: string, scope: Scope): any {
|
||||
const value = parseValue(str, scope)
|
||||
return isDrop(value) ? value.value() : value
|
||||
return isDrop(value) ? value.valueOf() : value
|
||||
}
|
||||
|
||||
export function isTruthy (val: any): boolean {
|
||||
|
||||
Reference in New Issue
Block a user