From 044ab5ea4c59ca3cde9f47c5fb7da380588506ed Mon Sep 17 00:00:00 2001 From: zhangchuanlong Date: Tue, 25 Jan 2022 15:21:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/is.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils/is.js b/src/utils/is.js index c2d18df..8035194 100644 --- a/src/utils/is.js +++ b/src/utils/is.js @@ -17,7 +17,7 @@ export function isNull(val) { } export function isObject(val) { - return !isNull(isNull) && is(val, 'Object') + return !isNull(val) && is(val, 'Object') } export function isArray(val) { @@ -80,6 +80,17 @@ export function isEmpty(val) { return false } +/** + * * 类似sql的isnull函数 + * * 第一个参数为null/undefined/''则返回第二个参数作为默认值,否则返回第一个参数 + * @param {Number|Boolean|String} val + * @param {Number|Boolean|String} replaceVal + * @returns + */ +export function isNullReplace(val, replaceVal = '') { + return isNullOrUndef(val) || val === '' ? replaceVal : val +} + export function isUrl(path) { const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/