util-helpers
Version:
37 lines (36 loc) • 1.51 kB
TypeScript
type Options = {
loose?: boolean;
useExtend?: boolean;
};
/**
* 检测值是否为中文
*
* @alias module:Validator.isChinese
* @since 1.1.0
* @see {@link http://www.unicode.org/reports/tr38/#BlockListing 4.4 Listing of Characters Covered by the Unihan Database}
* @see {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射 Unicode字符平面映射}
* @see {@link https://zh.wikipedia.org/wiki/Unicode區段 Unicode区段}
* @param {*} value 要检测的值
* @param {Object} [options] 配置项
* @param {boolean} [options.loose=false] 宽松模式,默认`false`。如果为`true`,只要包含中文就返回`true`
* @param {boolean} [options.useExtend=false] 使用统一表意文字扩展A-I,默认`false`。注意:如果不支持 `RegExp.prototype.unicode`,扩展字符集将自动不生效,如IE浏览器。
* @returns {boolean} 值是否为中文
* @example
*
* isChinese('林某某'); // true
* isChinese('林A'); // false
*
* // 宽松模式,只要包含中文即为true
* isChinese('林A', { loose: true }); // true
* isChinese('A林A', { loose: true }); // true
*
* // 扩展字符集的字符
* isChinese('𠮷'); // false
*
* // 使用中文扩展字符集,需要浏览器支持 RegExp.prototype.unicode 才生效。
* isChinese('𠮷', { useExtend: true }); // true
* isChinese('𠮷aa', { useExtend: true, loose: true }); // true
*
*/
declare function isChinese(value: any, options?: Options): boolean;
export default isChinese;