@caucasus/az-utils 0.3.0 → 0.4.0
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/phone/{operators.d.ts → constants/operator.constants.d.ts} +1 -0
- package/dist/phone/{operators.js → constants/operator.constants.js} +2 -1
- package/dist/phone/constants/regex.constants.d.ts +4 -0
- package/dist/phone/constants/regex.constants.js +7 -0
- package/dist/phone/decorators/index.d.ts +2 -2
- package/dist/phone/decorators/index.js +4 -4
- package/dist/phone/decorators/{isAzPhone.decorator.js → is-az-phone.decorator.js} +2 -2
- package/dist/phone/decorators/{transformAzPhone.decorator.js → transform-az-phone.decorator.js} +2 -2
- package/dist/phone/format.d.ts +4 -0
- package/dist/phone/format.js +19 -0
- package/dist/phone/{getAzMobileOperator.d.ts → get-az-mobile-operator.d.ts} +1 -1
- package/dist/phone/get-az-mobile-operator.js +13 -0
- package/dist/phone/index.d.ts +8 -5
- package/dist/phone/index.js +12 -7
- package/dist/phone/{isValidAzPhone.js → is-valid-az-phone.js} +6 -6
- package/dist/phone/mask.d.ts +8 -0
- package/dist/phone/mask.js +23 -0
- package/dist/phone/{normalizeAzPhone.js → normalize-az-phone.js} +4 -4
- package/dist/phone/phone.types.d.ts +7 -0
- package/dist/phone/phone.types.js +2 -0
- package/package.json +1 -1
- package/dist/phone/constants.d.ts +0 -2
- package/dist/phone/constants.js +0 -5
- package/dist/phone/getAzMobileOperator.js +0 -13
- /package/dist/phone/decorators/{isAzPhone.decorator.d.ts → is-az-phone.decorator.d.ts} +0 -0
- /package/dist/phone/decorators/{transformAzPhone.decorator.d.ts → transform-az-phone.decorator.d.ts} +0 -0
- /package/dist/phone/{isValidAzPhone.d.ts → is-valid-az-phone.d.ts} +0 -0
- /package/dist/phone/{normalizeAzPhone.d.ts → normalize-az-phone.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OPERATOR_PREFIX_MAP = void 0;
|
|
3
|
+
exports.AZ_PHONE_PREFIX = exports.OPERATOR_PREFIX_MAP = void 0;
|
|
4
4
|
exports.OPERATOR_PREFIX_MAP = {
|
|
5
5
|
"50": "Azercell",
|
|
6
6
|
"51": "Azercell",
|
|
@@ -10,3 +10,4 @@ exports.OPERATOR_PREFIX_MAP = {
|
|
|
10
10
|
"70": "Nar",
|
|
11
11
|
"77": "Nar",
|
|
12
12
|
};
|
|
13
|
+
exports.AZ_PHONE_PREFIX = "+994";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NUMBER_PARTITION_LOCAL_REX = exports.NUMBER_PARTITION_WITH_PREFIX_REX = exports.NUMBER_CLEANING_REX = exports.NUMBER_LENGTH_REX = void 0;
|
|
4
|
+
exports.NUMBER_LENGTH_REX = /^\d{9}$/;
|
|
5
|
+
exports.NUMBER_CLEANING_REX = /[\s\-()]/g;
|
|
6
|
+
exports.NUMBER_PARTITION_WITH_PREFIX_REX = /^\+994(\d{2})(\d{3})(\d{2})(\d{2})$/;
|
|
7
|
+
exports.NUMBER_PARTITION_LOCAL_REX = /^0(\d{2})(\d{3})(\d{2})(\d{2})$/;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { IsAzPhone } from "./
|
|
2
|
-
export { TransformAzPhone } from "./
|
|
1
|
+
export { IsAzPhone } from "./is-az-phone.decorator";
|
|
2
|
+
export { TransformAzPhone } from "./transform-az-phone.decorator";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransformAzPhone = exports.IsAzPhone = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "IsAzPhone", { enumerable: true, get: function () { return
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "TransformAzPhone", { enumerable: true, get: function () { return
|
|
4
|
+
var is_az_phone_decorator_1 = require("./is-az-phone.decorator");
|
|
5
|
+
Object.defineProperty(exports, "IsAzPhone", { enumerable: true, get: function () { return is_az_phone_decorator_1.IsAzPhone; } });
|
|
6
|
+
var transform_az_phone_decorator_1 = require("./transform-az-phone.decorator");
|
|
7
|
+
Object.defineProperty(exports, "TransformAzPhone", { enumerable: true, get: function () { return transform_az_phone_decorator_1.TransformAzPhone; } });
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.IsAzPhone = IsAzPhone;
|
|
7
7
|
const class_validator_1 = require("class-validator");
|
|
8
|
-
const
|
|
8
|
+
const is_valid_az_phone_1 = __importDefault(require("../is-valid-az-phone"));
|
|
9
9
|
function IsAzPhone(validationOptions) {
|
|
10
10
|
return (target, propertyName) => {
|
|
11
11
|
(0, class_validator_1.registerDecorator)({
|
|
@@ -15,7 +15,7 @@ function IsAzPhone(validationOptions) {
|
|
|
15
15
|
options: validationOptions,
|
|
16
16
|
validator: {
|
|
17
17
|
validate(value) {
|
|
18
|
-
return typeof value === "string" && (0,
|
|
18
|
+
return typeof value === "string" && (0, is_valid_az_phone_1.default)(value);
|
|
19
19
|
},
|
|
20
20
|
defaultMessage(args) {
|
|
21
21
|
return `${args.property} must be a valid Azerbaijan phone number`;
|
package/dist/phone/decorators/{transformAzPhone.decorator.js → transform-az-phone.decorator.js}
RENAMED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransformAzPhone = TransformAzPhone;
|
|
4
4
|
const class_transformer_1 = require("class-transformer");
|
|
5
|
-
const
|
|
5
|
+
const normalize_az_phone_1 = require("../normalize-az-phone");
|
|
6
6
|
function TransformAzPhone() {
|
|
7
7
|
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
8
8
|
if (value === undefined || value === null)
|
|
9
9
|
return value;
|
|
10
10
|
if (typeof value !== "string")
|
|
11
11
|
return value;
|
|
12
|
-
return (0,
|
|
12
|
+
return (0, normalize_az_phone_1.normalizeAzPhone)(value);
|
|
13
13
|
});
|
|
14
14
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatAzPhoneInternational = formatAzPhoneInternational;
|
|
4
|
+
const operator_constants_1 = require("./constants/operator.constants");
|
|
5
|
+
const regex_constants_1 = require("./constants/regex.constants");
|
|
6
|
+
const normalize_az_phone_1 = require("./normalize-az-phone");
|
|
7
|
+
/**
|
|
8
|
+
* ex. 0501234567 → +994 50 123 45 67
|
|
9
|
+
*/
|
|
10
|
+
function formatAzPhoneInternational(phone) {
|
|
11
|
+
const normalized = (0, normalize_az_phone_1.normalizeAzPhone)(phone);
|
|
12
|
+
if (!normalized)
|
|
13
|
+
return phone;
|
|
14
|
+
const match = normalized.match(regex_constants_1.NUMBER_PARTITION_LOCAL_REX);
|
|
15
|
+
if (!match)
|
|
16
|
+
return phone;
|
|
17
|
+
const [, operator, p1, p2, p3] = match;
|
|
18
|
+
return `${operator_constants_1.AZ_PHONE_PREFIX}(${operator})${p1}-${p2}-${p3}`;
|
|
19
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AzMobileOperator } from "./
|
|
1
|
+
import { AzMobileOperator } from "./constants/operator.constants";
|
|
2
2
|
export declare function getAzMobileOperator(phone: string): AzMobileOperator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAzMobileOperator = getAzMobileOperator;
|
|
4
|
+
const operator_constants_1 = require("./constants/operator.constants");
|
|
5
|
+
const normalize_az_phone_1 = require("./normalize-az-phone");
|
|
6
|
+
function getAzMobileOperator(phone) {
|
|
7
|
+
const normalized = (0, normalize_az_phone_1.normalizeAzPhone)(phone);
|
|
8
|
+
if (!normalized) {
|
|
9
|
+
return "Unknown";
|
|
10
|
+
}
|
|
11
|
+
const prefix = normalized.slice(1, 3);
|
|
12
|
+
return operator_constants_1.OPERATOR_PREFIX_MAP[prefix] ?? "Unknown";
|
|
13
|
+
}
|
package/dist/phone/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export { isValidAzPhone } from "./
|
|
2
|
-
export { normalizeAzPhone } from "./
|
|
3
|
-
export { getAzMobileOperator } from "./
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export { isValidAzPhone } from "./is-valid-az-phone";
|
|
2
|
+
export { normalizeAzPhone } from "./normalize-az-phone";
|
|
3
|
+
export { getAzMobileOperator } from "./get-az-mobile-operator";
|
|
4
|
+
export { formatAzPhoneInternational } from "./format";
|
|
5
|
+
export { maskAzPhone } from "./mask";
|
|
6
|
+
export type { AzMobileOperator } from "./constants/operator.constants";
|
|
7
|
+
export * from "./decorators";
|
|
8
|
+
export * from "./phone.types";
|
package/dist/phone/index.js
CHANGED
|
@@ -14,11 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getAzMobileOperator = exports.normalizeAzPhone = exports.isValidAzPhone = void 0;
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "isValidAzPhone", { enumerable: true, get: function () { return
|
|
20
|
-
var
|
|
21
|
-
Object.defineProperty(exports, "normalizeAzPhone", { enumerable: true, get: function () { return
|
|
22
|
-
var
|
|
23
|
-
Object.defineProperty(exports, "getAzMobileOperator", { enumerable: true, get: function () { return
|
|
17
|
+
exports.maskAzPhone = exports.formatAzPhoneInternational = exports.getAzMobileOperator = exports.normalizeAzPhone = exports.isValidAzPhone = void 0;
|
|
18
|
+
var is_valid_az_phone_1 = require("./is-valid-az-phone");
|
|
19
|
+
Object.defineProperty(exports, "isValidAzPhone", { enumerable: true, get: function () { return is_valid_az_phone_1.isValidAzPhone; } });
|
|
20
|
+
var normalize_az_phone_1 = require("./normalize-az-phone");
|
|
21
|
+
Object.defineProperty(exports, "normalizeAzPhone", { enumerable: true, get: function () { return normalize_az_phone_1.normalizeAzPhone; } });
|
|
22
|
+
var get_az_mobile_operator_1 = require("./get-az-mobile-operator");
|
|
23
|
+
Object.defineProperty(exports, "getAzMobileOperator", { enumerable: true, get: function () { return get_az_mobile_operator_1.getAzMobileOperator; } });
|
|
24
|
+
var format_1 = require("./format");
|
|
25
|
+
Object.defineProperty(exports, "formatAzPhoneInternational", { enumerable: true, get: function () { return format_1.formatAzPhoneInternational; } });
|
|
26
|
+
var mask_1 = require("./mask");
|
|
27
|
+
Object.defineProperty(exports, "maskAzPhone", { enumerable: true, get: function () { return mask_1.maskAzPhone; } });
|
|
24
28
|
__exportStar(require("./decorators"), exports);
|
|
29
|
+
__exportStar(require("./phone.types"), exports);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isValidAzPhone = isValidAzPhone;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const operator_constants_1 = require("./constants/operator.constants");
|
|
5
|
+
const regex_constants_1 = require("./constants/regex.constants");
|
|
6
6
|
function isValidAzPhone(phone) {
|
|
7
7
|
if (!phone)
|
|
8
8
|
return false;
|
|
9
9
|
// Remove spaces, dashes, parentheses
|
|
10
|
-
const cleaned = phone.replace(
|
|
10
|
+
const cleaned = phone.replace(regex_constants_1.NUMBER_CLEANING_REX, "");
|
|
11
11
|
let localNumber;
|
|
12
12
|
if (cleaned.startsWith("+994")) {
|
|
13
13
|
localNumber = cleaned.slice(4);
|
|
@@ -18,17 +18,17 @@ function isValidAzPhone(phone) {
|
|
|
18
18
|
else if (cleaned.startsWith("0")) {
|
|
19
19
|
localNumber = cleaned.slice(1);
|
|
20
20
|
}
|
|
21
|
-
else if (cleaned.slice(0, 2) in
|
|
21
|
+
else if (cleaned.slice(0, 2) in operator_constants_1.OPERATOR_PREFIX_MAP) {
|
|
22
22
|
localNumber = cleaned;
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
// Must be exactly 9 digits after prefix removal
|
|
28
|
-
if (!
|
|
28
|
+
if (!regex_constants_1.NUMBER_LENGTH_REX.test(localNumber)) {
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
31
|
const operatorPrefix = localNumber.slice(0, 2);
|
|
32
|
-
return operatorPrefix in
|
|
32
|
+
return operatorPrefix in operator_constants_1.OPERATOR_PREFIX_MAP;
|
|
33
33
|
}
|
|
34
34
|
exports.default = isValidAzPhone;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maskAzPhone = maskAzPhone;
|
|
4
|
+
const operator_constants_1 = require("./constants/operator.constants");
|
|
5
|
+
const normalize_az_phone_1 = require("./normalize-az-phone");
|
|
6
|
+
/**
|
|
7
|
+
* @example +994501234567 → +994 50 *** ** 67
|
|
8
|
+
*/
|
|
9
|
+
function maskAzPhone(phone, options = {}) {
|
|
10
|
+
const normalized = (0, normalize_az_phone_1.normalizeAzPhone)(phone);
|
|
11
|
+
if (!normalized)
|
|
12
|
+
return { value: phone, isMasked: false };
|
|
13
|
+
const match = normalized.match(/^0(\d{2})(\d{7})$/);
|
|
14
|
+
if (!match)
|
|
15
|
+
return { value: phone, isMasked: false };
|
|
16
|
+
const visibleEnd = Math.min(Math.max(options.visibleEnd ?? 2, 2), 5);
|
|
17
|
+
const [, operator, rest] = match;
|
|
18
|
+
const maskedLength = rest.length - visibleEnd;
|
|
19
|
+
const masked = maskedLength > 0 ? "*".repeat(maskedLength) : "";
|
|
20
|
+
const visible = rest.slice(-visibleEnd);
|
|
21
|
+
const value = `${operator_constants_1.AZ_PHONE_PREFIX}(${operator})${masked}${visible}`;
|
|
22
|
+
return { value, isMasked: true };
|
|
23
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeAzPhone = normalizeAzPhone;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const is_valid_az_phone_1 = require("./is-valid-az-phone");
|
|
5
|
+
const regex_constants_1 = require("./constants/regex.constants");
|
|
6
6
|
function normalizeAzPhone(phone) {
|
|
7
|
-
if (!(0,
|
|
7
|
+
if (!(0, is_valid_az_phone_1.isValidAzPhone)(phone)) {
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
10
|
-
const cleaned = phone.replace(
|
|
10
|
+
const cleaned = phone.replace(regex_constants_1.NUMBER_CLEANING_REX, "");
|
|
11
11
|
let localNumber;
|
|
12
12
|
if (cleaned.startsWith("+994")) {
|
|
13
13
|
localNumber = cleaned.slice(4);
|
package/package.json
CHANGED
package/dist/phone/constants.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAzMobileOperator = getAzMobileOperator;
|
|
4
|
-
const operators_1 = require("./operators");
|
|
5
|
-
const normalizeAzPhone_1 = require("./normalizeAzPhone");
|
|
6
|
-
function getAzMobileOperator(phone) {
|
|
7
|
-
const normalized = (0, normalizeAzPhone_1.normalizeAzPhone)(phone);
|
|
8
|
-
if (!normalized) {
|
|
9
|
-
return "Unknown";
|
|
10
|
-
}
|
|
11
|
-
const prefix = normalized.slice(1, 3);
|
|
12
|
-
return operators_1.OPERATOR_PREFIX_MAP[prefix] ?? "Unknown";
|
|
13
|
-
}
|
|
File without changes
|
/package/dist/phone/decorators/{transformAzPhone.decorator.d.ts → transform-az-phone.decorator.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|