From 07aec861b9c95b0b4c4d96a0838f58de1fd3b791 Mon Sep 17 00:00:00 2001 From: Treecat Date: Thu, 23 Feb 2023 10:28:28 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-14316=20chore:=20=E4=BF=AE=E5=A4=8D=20st?= =?UTF-8?q?ring=20=E7=9A=84=E4=B8=80=E4=BA=9B=E7=BB=86=E8=8A=82=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/func/string.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/core/func/string.js b/src/core/func/string.js index c6f98fedc..f380b3581 100644 --- a/src/core/func/string.js +++ b/src/core/func/string.js @@ -1,4 +1,4 @@ -import {isString, each} from "../2.base"; +import { isString, each } from "../2.base"; /** * 判断字符串是否已指定的字符串开始 @@ -11,6 +11,7 @@ export function startWith(str, startTag) { if (startTag == null || startTag == "" || str.length === 0 || startTag.length > str.length) { return false; } + return str.substring(0, startTag.length) == startTag; } @@ -24,6 +25,7 @@ export function endWith(str, endTag) { if (endTag == null || endTag == "" || str.length === 0 || endTag.length > str.length) { return false; } + return str.substring(str.length - endTag.length) == endTag; } @@ -34,11 +36,12 @@ export function endWith(str, endTag) { * @return {String} 参数的值 */ export function getQuery(str, name) { - const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); + const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`); const r = str.substr(str.indexOf("?") + 1).match(reg); if (r) { return unescape(r[2]); } + return null; } @@ -58,16 +61,17 @@ export function appendQuery(str, paras) { src += "?"; } // 如果以问号结尾,说明没有其他参数 - if (BI.endWith(src, "?") !== false) { - } else { + if (!src.endsWith("?")) { src += "&"; } - each(paras, function (value, name) { + + each(paras, (name, value) => { if (typeof (name) === "string") { - src += name + "=" + value + "&"; + src += `${name}=${value}&`; } }); src = src.substr(0, src.length - 1); + return src; } @@ -89,11 +93,11 @@ export function replaceAll(str, s1, s2) { * @returns {String} 以指定字符开头的字符串 */ export function perfectStart(str, start) { - if (BI.startWith(str, start)) { + if (str.startsWith(start)) { return str; } - return start + str; + return start + str; } /** @@ -117,5 +121,6 @@ export function allIndexOf(str, sub) { str = str.substring(loc + sub.length, str.length); offset += loc + sub.length; } + return location; }