From 402787bfae00ec5c7bb25bb7d8eaa7c2ecf26c96 Mon Sep 17 00:00:00 2001 From: pany <939630029@qq.com> Date: Mon, 22 Aug 2022 10:17:28 +0800 Subject: [PATCH] style: validate.ts --- src/utils/validate.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/utils/validate.ts b/src/utils/validate.ts index 64adbfc..56bfce9 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -1,4 +1,7 @@ -export const isExternal = (path: string) => /^(https?:|mailto:|tel:)/.test(path) +export const isExternal = (path: string) => { + const reg = /^(https?:|mailto:|tel:)/ + return reg.test(path) +} export const isArray = (arg: any) => { if (typeof Array.isArray === "undefined") { @@ -7,6 +10,13 @@ export const isArray = (arg: any) => { return Array.isArray(arg) } +export function isString(str: any) { + if (typeof str === "string" || str instanceof String) { + return true + } + return false +} + export const isValidURL = (url: string) => { const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/