tele_number_utils 1.0.0 → 1.0.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.
- 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 +21 -2
- package/src/country/country.ts +0 -1502
- package/src/country/getCountry.ts +0 -73
- package/src/country/util.ts +0 -75
- package/src/formatter/index.ts +0 -41
- package/src/index.ts +0 -4
- package/src/parsed/index.ts +0 -289
- package/src/parsed/test.ts +0 -37
|
@@ -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.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,7 +13,26 @@
|
|
|
13
13
|
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
14
14
|
"format": "prettier --write 'src/**/*.{ts,tsx,js,json,md}'"
|
|
15
15
|
},
|
|
16
|
-
"keywords": [
|
|
16
|
+
"keywords": [
|
|
17
|
+
"phonephone-utils",
|
|
18
|
+
"phone-number",
|
|
19
|
+
"phone-number-utils",
|
|
20
|
+
"phone-parser",
|
|
21
|
+
"phone-formatter",
|
|
22
|
+
"phone-validation",
|
|
23
|
+
"country-detector",
|
|
24
|
+
"country-from-phone",
|
|
25
|
+
"dialing-code",
|
|
26
|
+
"calling-code",
|
|
27
|
+
"international-phone",
|
|
28
|
+
"e164",
|
|
29
|
+
"nanpa",
|
|
30
|
+
"shared-country-code",
|
|
31
|
+
"typescript",
|
|
32
|
+
"ts",
|
|
33
|
+
"utility",
|
|
34
|
+
"telecom"
|
|
35
|
+
],
|
|
17
36
|
"author": "",
|
|
18
37
|
"license": "ISC",
|
|
19
38
|
"devDependencies": {
|