优化 default filter 支持其他类型定义

This commit is contained in:
liaoxuezhi 2019-05-08 19:38:55 +08:00
parent ce899390dd
commit 44fce36608
1 changed files with 5 additions and 5 deletions

View File

@ -176,17 +176,17 @@ export const filters: {
},
url_encode: input => encodeURIComponent(input),
url_decode: input => decodeURIComponent(input),
default: (input, ...rest) => input || rest.map((item: any) => {
default: (input, defaultValue) => input || (() => {
try {
if (item === 'undefined') {
if (defaultValue === 'undefined') {
return undefined;
}
return JSON.parse(item);
return JSON.parse(defaultValue);
} catch (e) {
return item;
return defaultValue;
}
}).join(":"),
})(),
join: (input, glue) => (input && input.join ? input.join(glue) : input),
split: (input, delimiter = ",") =>
typeof input === "string" ? input.split(delimiter) : input,