tele_number_utils 1.0.1 → 1.0.3
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.
- package/README.md +12 -0
- package/dist/country/getCountry.d.ts +1 -1
- package/dist/country/getCountry.d.ts.map +1 -1
- package/dist/country/getCountry.js +8 -4
- package/package.json +3 -7
- package/tsconfig.json +17 -0
package/README.md
CHANGED
|
@@ -191,6 +191,18 @@ Feel free to open an issue or PR to improve country detection, formatting option
|
|
|
191
191
|
|
|
192
192
|
---
|
|
193
193
|
|
|
194
|
+
## ☕ Support the Project
|
|
195
|
+
|
|
196
|
+
If this package helps you, you can support my work ❤️
|
|
197
|
+
|
|
198
|
+
### 💳 Payoneer
|
|
199
|
+
|
|
200
|
+
If you prefer Payoneer, you can send support to:
|
|
201
|
+
|
|
202
|
+
- **Payoneer Email:** p7894727@gmail.com
|
|
203
|
+
|
|
204
|
+
(Thank you for your support 🙏)
|
|
205
|
+
|
|
194
206
|
## License
|
|
195
207
|
|
|
196
208
|
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCountry.d.ts","sourceRoot":"","sources":["../../src/country/getCountry.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;
|
|
1
|
+
{"version":3,"file":"getCountry.d.ts","sourceRoot":"","sources":["../../src/country/getCountry.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAuCF,oBAAoB;AACpB,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,KAAG,OAuB3C,CAAC"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { parsePhoneNumber } from "../parsed";
|
|
2
2
|
import { country_list } from "./country";
|
|
3
3
|
import { UK_COUNTRY_CODE, UK_DEPENDENCIES, CANADIAN_AREA_CODES, US_CANADA_COUNTRY_CODE, PUERTO_RICO_COUNTRY_CODE, } from "./util";
|
|
4
|
+
const NOT_FOUND_RESULT = {
|
|
5
|
+
name: "Not found",
|
|
6
|
+
dialingCode: "Invalid dialing code",
|
|
7
|
+
flagUrl: "Invalid Flag url",
|
|
8
|
+
alphaTwoCode: "Invalid alpha tow code",
|
|
9
|
+
};
|
|
4
10
|
/** Get country by alphaTwoCode */
|
|
5
11
|
const getCountryByAlpha = (alpha) => country_list.find((c) => c.alphaTwoCode === alpha) || null;
|
|
6
12
|
/** Get country by dialing code */
|
|
@@ -26,8 +32,6 @@ const handleUK = (nationalNumber) => {
|
|
|
26
32
|
export const getCountry = (number) => {
|
|
27
33
|
try {
|
|
28
34
|
const parsed = parsePhoneNumber(number);
|
|
29
|
-
if (!parsed)
|
|
30
|
-
return "Invalid Phone number";
|
|
31
35
|
let matched = null;
|
|
32
36
|
switch (parsed.callingCode) {
|
|
33
37
|
case US_CANADA_COUNTRY_CODE:
|
|
@@ -41,9 +45,9 @@ export const getCountry = (number) => {
|
|
|
41
45
|
getCountryByAlpha(parsed.country || "") ||
|
|
42
46
|
getCountryByDialingCode(parsed.callingCode || "");
|
|
43
47
|
}
|
|
44
|
-
return matched ||
|
|
48
|
+
return matched || NOT_FOUND_RESULT;
|
|
45
49
|
}
|
|
46
50
|
catch {
|
|
47
|
-
return
|
|
51
|
+
return NOT_FOUND_RESULT;
|
|
48
52
|
}
|
|
49
53
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tele_number_utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"format": "prettier --write 'src/**/*.{ts,tsx,js,json,md}'"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
|
-
"
|
|
18
|
-
"phone-utils",
|
|
17
|
+
"phonephone-utils",
|
|
19
18
|
"phone-number",
|
|
20
19
|
"phone-number-utils",
|
|
21
20
|
"phone-parser",
|
|
@@ -46,8 +45,5 @@
|
|
|
46
45
|
"prettier": "^3.7.4",
|
|
47
46
|
"ts-node": "^10.9.2",
|
|
48
47
|
"typescript": "^5.9.3"
|
|
49
|
-
}
|
|
50
|
-
"files": [
|
|
51
|
-
"dist"
|
|
52
|
-
]
|
|
48
|
+
}
|
|
53
49
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "dist",
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"target": "ES2020",
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"skipLibCheck": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*"],
|
|
16
|
+
"exclude": ["node_modules", "dist"]
|
|
17
|
+
}
|