File tree 1 file changed +17
-3
lines changed
1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -238,9 +238,9 @@ export function isEmpty(v: any): boolean {
238
238
*/
239
239
export function isHexCode ( c : number ) : boolean {
240
240
return (
241
- ( 0x30 /* 0 */ <= c && c <= 0x39 /* 9 */ ) ||
242
- ( 0x41 /* A */ <= c && c <= 0x46 /* F */ ) ||
243
- ( 0x61 /* a */ <= c && c <= 0x66 /* f */ )
241
+ ( 0x30 /* 0 */ <= c && c <= 0x39 ) /* 9 */ ||
242
+ ( 0x41 /* A */ <= c && c <= 0x46 ) /* F */ ||
243
+ ( 0x61 /* a */ <= c && c <= 0x66 ) /* f */
244
244
) ;
245
245
}
246
246
@@ -359,6 +359,19 @@ export function inArray(needle: any, haystack: any): boolean {
359
359
return res ;
360
360
}
361
361
362
+ // isJson 检查变量是否JSON字符串.
363
+ export function isJson ( text : any ) : boolean {
364
+ if ( typeof text !== 'string' ) {
365
+ return false ;
366
+ }
367
+ try {
368
+ JSON . parse ( text ) ;
369
+ return true ;
370
+ } catch ( error ) {
371
+ return false ;
372
+ }
373
+ }
374
+
362
375
export default {
363
376
isString,
364
377
isArray,
@@ -391,4 +404,5 @@ export default {
391
404
objectOf,
392
405
isNaturalNum,
393
406
inArray,
407
+ isJson,
394
408
} ;
You can’t perform that action at this time.
0 commit comments