mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 22:10:41 -07:00
refactor: IDrop interface => abstract method
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { isNil, isString } from '../util/underscore'
|
||||
import { isDrop } from '../drop/idrop'
|
||||
import { Drop } from '../drop/drop'
|
||||
import { EmptyDrop } from '../drop/empty-drop'
|
||||
|
||||
export class BlankDrop extends EmptyDrop {
|
||||
equals (value: any) {
|
||||
if (value === false) return true
|
||||
if (isNil(isDrop(value) ? value.valueOf() : value)) return true
|
||||
if (isNil(value instanceof Drop ? value.valueOf() : value)) return true
|
||||
if (isString(value)) return /^\s*$/.test(value)
|
||||
return super.equals(value)
|
||||
}
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
export abstract class Drop {
|
||||
abstract valueOf(): any;
|
||||
|
||||
liquid_method_missing (name: string) { // eslint-disable-line
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Drop } from './drop'
|
||||
import { IComparable } from './icomparable'
|
||||
import { isObject, isString, isArray } from '../util/underscore'
|
||||
import { IDrop } from '../drop/idrop'
|
||||
|
||||
export class EmptyDrop extends Drop implements IDrop, IComparable {
|
||||
export class EmptyDrop extends Drop implements IComparable {
|
||||
equals (value: any) {
|
||||
if (isString(value) || isArray(value)) return value.length === 0
|
||||
if (isObject(value)) return Object.keys(value).length === 0
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Drop } from './drop'
|
||||
import { isFunction } from '../util/underscore'
|
||||
|
||||
export interface IDrop {
|
||||
valueOf(): any
|
||||
}
|
||||
|
||||
export function isDrop (value: any): value is IDrop {
|
||||
return value instanceof Drop && isFunction((value as any).valueOf)
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Drop } from './drop'
|
||||
import { IComparable } from './icomparable'
|
||||
import { isNil } from '../util/underscore'
|
||||
import { IDrop, isDrop } from '../drop/idrop'
|
||||
import { BlankDrop } from '../drop/blank-drop'
|
||||
|
||||
export class NullDrop extends Drop implements IDrop, IComparable {
|
||||
export class NullDrop extends Drop implements IComparable {
|
||||
equals (value: any) {
|
||||
return isNil(isDrop(value) ? value.valueOf() : value) || value instanceof BlankDrop
|
||||
return isNil(value instanceof Drop ? value.valueOf() : value) || value instanceof BlankDrop
|
||||
}
|
||||
gt () {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user