meemup-library 1.3.99 → 1.4.2

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.
@@ -2,49 +2,57 @@ export default new class {
2
2
  unFormatPhoneNumber(phone = "(000) 000-0000") {
3
3
  if (!phone)
4
4
  return "";
5
- phone = phone.replace(/\(/g, "");
6
- phone = phone.replace(/\)/g, "");
7
- phone = phone.replace(/-/g, "");
8
- phone = phone.replace(/ /g, "");
9
- phone = phone.replace(/\+/g, "");
10
- return phone;
5
+ return phone.replace(/[\(\)\-\+ ]/g, "");
11
6
  }
12
7
  formatPhoneNumber(phone = "0000000000") {
13
8
  let unformat = this.unFormatPhoneNumber(phone);
14
9
  if (unformat.length === 10)
15
10
  unformat = "1" + unformat;
16
11
  const len = unformat.length;
17
- let p0 = unformat.slice(0, len - len - 10);
18
- let p1 = unformat.slice(len - 10, len - 7);
19
- let p2 = unformat.slice(len - 7, len - 4);
20
- let p3 = unformat.slice(len - 4, len);
21
- return `+${p0} (${p1}) ${p2}-${p3}`;
12
+ // بررسی اینکه آیا شماره دست کم 11 رقم دارد تا به فرمت زیر تبدیل شود: +1 (XXX) XXX-XXXX
13
+ if (len >= 11) {
14
+ let p0 = unformat.slice(0, len - 10); // بخش کد کشور یا کدهای اضافی
15
+ let p1 = unformat.slice(len - 10, len - 7); // سه رقم اول
16
+ let p2 = unformat.slice(len - 7, len - 4); // سه رقم بعدی
17
+ let p3 = unformat.slice(len - 4, len); // چهار رقم آخر
18
+ return `+${p0} (${p1}) ${p2}-${p3}`;
19
+ }
20
+ else {
21
+ // بازگرداندن شماره تلفن بدون تغییر اگر طول آن کمتر از 11 رقم باشد
22
+ return phone;
23
+ }
22
24
  }
23
25
  formatAccordingToLength(phone = "0000000000") {
24
26
  let unFormat = this.unFormatPhoneNumber(phone);
25
- if (unFormat.length < 4)
27
+ // استفاده از تک عبارت شرطی برای تعیین فرمت بر اساس طول رشته
28
+ if (unFormat.length < 4) {
26
29
  return `(${unFormat}`;
27
- else if (unFormat.length < 7)
28
- return `(${unFormat.substring(0, 3)}) ${unFormat.substring(3, 6)}`;
29
- else
30
+ }
31
+ else if (unFormat.length < 7) {
32
+ return `(${unFormat.substring(0, 3)}) ${unFormat.substring(3)}`;
33
+ }
34
+ else {
30
35
  return `(${unFormat.substring(0, 3)}) ${unFormat.substring(3, 6)}-${unFormat.substring(6)}`;
31
- // let p1 = unFormat.slice(len - 10, len - 7);
32
- // let p2 = unFormat.slice(len - 7, len - 4);
33
- // let p3 = unFormat.slice(len - 4, len);
34
- // return `(${p1}) ${p2}-${p3}`;
36
+ }
35
37
  }
36
38
  toDisplay(phone = "0000000000", init = "") {
37
39
  let unformat = this.unFormatPhoneNumber(phone);
40
+ // بررسی صحت عدد بودن رشته
38
41
  if (isNaN(+unformat) || unformat === "")
39
42
  return init;
43
+ // اگر شماره 10 رقمی است، کد کشور را به آن اضافه می‌کنیم
40
44
  if (unformat.length === 10)
41
45
  unformat = "1" + unformat;
42
46
  const len = unformat.length;
43
- // let p0 = unformat.slice(0, len - len - 10);
44
- let p1 = unformat.slice(len - 10, len - 7);
45
- let p2 = unformat.slice(len - 7, len - 4);
46
- let p3 = unformat.slice(len - 4, len);
47
- return `(${p1}) ${p2}-${p3}`;
47
+ // اطمینان از اینکه طول رشته مناسب است (حداقل 11 رقم برای کشور)
48
+ if (len >= 11) {
49
+ let p1 = unformat.substring(len - 10, len - 7); // سه رقم اول
50
+ let p2 = unformat.substring(len - 7, len - 4); // سه رقم بعدی
51
+ let p3 = unformat.substring(len - 4); // چهار رقم آخر
52
+ return `(${p1}) ${p2}-${p3}`;
53
+ }
54
+ // اگر طول رشته کم‌تر از 11 است، همان مقدار اولیه را باز می‌گردانیم
55
+ return init;
48
56
  }
49
57
  toSave(phone = "(000) 000-0000") {
50
58
  let str = this.unFormatPhoneNumber(phone ? phone : "");
@@ -54,7 +62,6 @@ export default new class {
54
62
  }
55
63
  toForm(phone = "(000) 000-0000") {
56
64
  return this.unFormatPhoneNumber(phone ? phone : "");
57
- // if (data.startsWith(removeCountryCode)) return data.split(removeCountryCode)[0];
58
65
  // return data;
59
66
  }
60
67
  toCanadianPhoneForm(phone) {
@@ -63,7 +70,7 @@ export default new class {
63
70
  return data.substring(data.length - 10);
64
71
  return data;
65
72
  }
66
- toCanadianPhoneSave(phone, countryCode = "1") {
73
+ toCanadianPhoneSave(phone, countryCode = "+1") {
67
74
  let data = this.toSave(phone);
68
75
  if (data === "")
69
76
  return "";
@@ -1,2 +1,2 @@
1
1
  import { initAccount } from "../IAccount";
2
- export const initKitchenDisplayAccount = Object.assign(Object.assign({}, initAccount), { deviceIdentifier: "", clientAgent: "kds" });
2
+ export const initKitchenDisplayAccount = Object.assign(Object.assign({}, initAccount), { deviceIdentifier: "", clientAgent: "KDS-App" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meemup-library",
3
- "version": "1.3.99",
3
+ "version": "1.4.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "remove:one": "rimraf dist",
12
12
  "remove:two": "rimraf ./src/dist",
13
13
  "test": "echo \"Error: no test specified\" && exit 1",
14
- "commit": "git add . && git commit -m \"version.1.3.99 \" && git push origin "
14
+ "commit": "git add . && git commit -m \"version.1.4.2 \" && git push origin "
15
15
  },
16
16
  "files": [
17
17
  "/dist"