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

This commit is contained in:
liaoxuezhi 2019-05-08 19:38:55 +08:00
parent ce899390dd
commit 44fce36608

View File

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