-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
|
||
import { desensitizeMobile } from '@nmsn/utils'; | ||
|
||
export default () => { | ||
const source = '13112345678'; | ||
const result = desensitizeMobile(source); | ||
return ( | ||
<div> | ||
<p>source: {JSON.stringify(source)}</p> | ||
<p>result: {JSON.stringify(result)}</p> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
title: desensitizeMobile | ||
toc: false | ||
--- | ||
|
||
## desensitizeMobile | ||
|
||
给手机号码脱敏 | ||
|
||
<code src="./demo.tsx"></code> | ||
|
||
### API | ||
|
||
```typescript | ||
const data = desensitizeMobile(mobile: string | number); | ||
``` | ||
|
||
### Params | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
| ---- | ------------ | -------- | ------ | | ||
| mobile | 入参,电话号码 | `string \| number` | - | | ||
|
||
|
||
### Result | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
| ---- | -------------- | -------- | ------ | | ||
| data | 返回的脱敏电话号 | `string` | '' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import phoneDesensitization from '.'; | ||
|
||
it('phoneDesensitization', () => { | ||
expect(phoneDesensitization('13111111111')).toEqual('131****1111'); | ||
expect(() => phoneDesensitization('')).toThrow(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import regex from '@/regex'; | ||
|
||
const desensitizeMobile = (mobile: string | number) => { | ||
const _phone = mobile.toString(); | ||
|
||
if (!regex.mobile.test(_phone)) { | ||
throw new Error('No valid mobile number'); | ||
} | ||
|
||
const reg = /(\d{3})\d{4}(\d{4})/; | ||
return _phone.replace(reg, '$1****$2'); | ||
}; | ||
|
||
export default desensitizeMobile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7a14526
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
utils – ./
utils-nmsn.vercel.app
utils-git-main-nmsn.vercel.app
nmsn-utils.vercel.app