From 5cd85cf72d03d6caa6663d49e56c5bad5910fa5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E4=BC=A0=E9=BE=99?= Date: Mon, 16 May 2022 18:29:32 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E4=BF=AE=E6=94=B9=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 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/utils/is.js b/src/utils/is.js index 2df0009..876c99f 100644 --- a/src/utils/is.js +++ b/src/utils/is.js @@ -16,6 +16,10 @@ export function isNull(val) { return val === null } +export function isWhitespace(val) { + return val === '' +} + export function isObject(val) { return !isNull(val) && is(val, 'Object') } @@ -64,6 +68,10 @@ export function isNullOrUndef(val) { return isNull(val) || isUndef(val) } +export function isNullOrWhitespace(val) { + return isNullOrUndef(val) || isWhitespace(val) +} + export function isEmpty(val) { if (isArray(val) || isString(val)) { return val.length === 0 @@ -81,14 +89,14 @@ export function isEmpty(val) { } /** - * * 类似sql的isnull函数 - * * 第一个参数为null/undefined/''则返回第二个参数作为默认值,否则返回第一个参数 + * * 类似mysql的IFNULL函数 + * * 第一个参数为null/undefined/'' 则返回第二个参数作为备用值,否则返回第一个参数 * @param {Number|Boolean|String} val - * @param {Number|Boolean|String} replaceVal + * @param {Number|Boolean|String} def * @returns */ -export function isNullReplace(val, replaceVal = '') { - return isNullOrUndef(val) || val === '' ? replaceVal : val +export function ifNull(val, def = '') { + return isNullOrWhitespace(val) ? def : val } export function isUrl(path) {