fix: default filter not applied for empty array

This commit is contained in:
harttle
2020-03-26 01:39:30 +08:00
parent 94d67d254d
commit c371762c43
5 changed files with 22 additions and 28 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ export function escapeOnce (str: string) {
}
export function newlineToBr (v: string) {
return v.replace(/\n/g, '<br />')
return v.replace(/\n/g, '<br/>')
}
export function stripHtml (v: string) {
+3 -2
View File
@@ -1,8 +1,9 @@
import { isFalsy } from '../../render/boolean'
import { toValue } from '../../util/underscore'
import { isArray, isString, toValue } from '../../util/underscore'
export function Default<T1, T2> (v: string | T1, arg: T2): string | T1 | T2 {
return isFalsy(toValue(v)) || v === '' ? arg : v
if (isArray(v) || isString(v)) return v.length ? v : arg
return isFalsy(toValue(v)) ? arg : v
}
export function json (v: any) {
return JSON.stringify(v)