SmartParks_visitore/uni_modules/lime-shared/isRegExp/index.ts

33 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2025-08-21 11:23:54 +08:00
// @ts-nocheck
/**
*
* @param obj -
* @returns true false
*
* @example
* // 基础检测
* isRegExp(/abc/); // true
* isRegExp(new RegExp('abc')); // true
*
* @example
* // 非正则表达式检测
* isRegExp('hello'); // false
* isRegExp({}); // false
* isRegExp(null); // false
*
* @description
* 1. Object.prototype.toString
* 2.
* - iframe
* - Node.js vm
* 3. instanceof
* 4. ES3+
*/
export function isRegExp(obj : any) : boolean {
// #ifndef APP-ANDROID
return Object.prototype.toString.call(obj) === '[object RegExp]';
// #endif
// #ifdef APP-ANDROID
return obj instanceof RegExp//Object.prototype.toString.call(obj) === '[object RegExp]';
// #endif
}