lyb-js 1.6.20 → 1.6.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
1
  /**
2
- * @description 隐藏手机号码中间的四位数字
3
- * @param mobile 需要处理的手机号码
4
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsMaskPhoneNumber-隐藏手机号码
2
+ * @description 将中间四位设置为星号
3
+ * @param str 需要处理的手机号码
5
4
  */
6
- export declare const libJsMaskPhoneNumber: (mobile: number | string) => string;
5
+ export declare const libJsMaskCenterFour: (str: number | string) => string;
@@ -1,9 +1,10 @@
1
1
  /**
2
- * @description 隐藏手机号码中间的四位数字
3
- * @param mobile 需要处理的手机号码
4
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsMaskPhoneNumber-隐藏手机号码
2
+ * @description 将中间四位设置为星号
3
+ * @param str 需要处理的手机号码
5
4
  */
6
- export const libJsMaskPhoneNumber = (mobile) => {
7
- const m = mobile.toString();
8
- return m.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
5
+ export const libJsMaskCenterFour = (str) => {
6
+ const m = str.toString();
7
+ const len = m.length;
8
+ const start = Math.floor((len - 4) / 2); // 中间四位起点
9
+ return m.slice(0, start) + "****" + m.slice(start + 4);
9
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-js",
3
- "version": "1.6.20",
3
+ "version": "1.6.21",
4
4
  "description": "自用JS方法库",
5
5
  "license": "ISC",
6
6
  "type": "module",