@caucasus/az-utils 0.2.3 → 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.
Files changed (57) hide show
  1. package/README.md +32 -11
  2. package/dist/fin/decorators/index.d.ts +2 -0
  3. package/dist/fin/decorators/index.js +7 -0
  4. package/dist/fin/decorators/isFin.decorator.d.ts +2 -0
  5. package/dist/fin/decorators/isFin.decorator.js +23 -0
  6. package/dist/fin/decorators/transform-fin.decorators.d.ts +1 -0
  7. package/dist/fin/decorators/transform-fin.decorators.js +14 -0
  8. package/dist/fin/index.d.ts +3 -1
  9. package/dist/fin/index.js +20 -0
  10. package/dist/fin/isValidFin.d.ts +1 -0
  11. package/dist/fin/isValidFin.js +8 -0
  12. package/dist/fin/normalizeFin.d.ts +1 -0
  13. package/dist/fin/normalizeFin.js +8 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +2 -0
  16. package/dist/passport/constants.d.ts +1 -0
  17. package/dist/passport/constants.js +4 -0
  18. package/dist/passport/decorators/index.d.ts +2 -0
  19. package/dist/passport/decorators/index.js +7 -0
  20. package/dist/passport/decorators/isSeries.decorator.d.ts +2 -0
  21. package/dist/passport/decorators/isSeries.decorator.js +23 -0
  22. package/dist/passport/decorators/transformSeries.decorator.d.ts +1 -0
  23. package/dist/passport/decorators/transformSeries.decorator.js +14 -0
  24. package/dist/passport/index.d.ts +3 -1
  25. package/dist/passport/index.js +20 -0
  26. package/dist/passport/isValidSeries.d.ts +1 -0
  27. package/dist/passport/isValidSeries.js +9 -0
  28. package/dist/passport/normalizeSeries.d.ts +1 -0
  29. package/dist/passport/normalizeSeries.js +8 -0
  30. package/dist/phone/{operators.d.ts → constants/operator.constants.d.ts} +1 -0
  31. package/dist/phone/{operators.js → constants/operator.constants.js} +2 -1
  32. package/dist/phone/constants/regex.constants.d.ts +4 -0
  33. package/dist/phone/constants/regex.constants.js +7 -0
  34. package/dist/phone/decorators/index.d.ts +2 -2
  35. package/dist/phone/decorators/index.js +4 -4
  36. package/dist/phone/decorators/{isAzPhone.decorator.js → is-az-phone.decorator.js} +2 -2
  37. package/dist/phone/decorators/{transformAzPhone.decorator.js → transform-az-phone.decorator.js} +2 -2
  38. package/dist/phone/format.d.ts +4 -0
  39. package/dist/phone/format.js +19 -0
  40. package/dist/phone/{getAzMobileOperator.d.ts → get-az-mobile-operator.d.ts} +1 -1
  41. package/dist/phone/get-az-mobile-operator.js +13 -0
  42. package/dist/phone/index.d.ts +8 -5
  43. package/dist/phone/index.js +12 -7
  44. package/dist/phone/{isValidAzPhone.js → is-valid-az-phone.js} +6 -6
  45. package/dist/phone/mask.d.ts +8 -0
  46. package/dist/phone/mask.js +23 -0
  47. package/dist/phone/{normalizeAzPhone.js → normalize-az-phone.js} +4 -4
  48. package/dist/phone/phone.types.d.ts +7 -0
  49. package/dist/phone/phone.types.js +2 -0
  50. package/package.json +1 -1
  51. package/dist/phone/constants.d.ts +0 -2
  52. package/dist/phone/constants.js +0 -5
  53. package/dist/phone/getAzMobileOperator.js +0 -13
  54. /package/dist/phone/decorators/{isAzPhone.decorator.d.ts → is-az-phone.decorator.d.ts} +0 -0
  55. /package/dist/phone/decorators/{transformAzPhone.decorator.d.ts → transform-az-phone.decorator.d.ts} +0 -0
  56. /package/dist/phone/{isValidAzPhone.d.ts → is-valid-az-phone.d.ts} +0 -0
  57. /package/dist/phone/{normalizeAzPhone.d.ts → normalize-az-phone.d.ts} +0 -0
package/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
  ![npm version](https://img.shields.io/npm/v/@caucasus/az-utils)
3
3
  ![license](https://img.shields.io/npm/l/@caucasus/az-utils)
4
4
 
5
-
6
5
  # az-utils 🇦🇿
7
6
 
8
7
  A lightweight, TypeScript-first utility library providing **Azerbaijan-specific helpers** commonly needed in backend development.
@@ -10,6 +9,7 @@ A lightweight, TypeScript-first utility library providing **Azerbaijan-specific
10
9
  This package focuses on **validation, normalization, and parsing** of data formats frequently used in Azerbaijan-based systems.
11
10
 
12
11
  > Initial release focuses on **Azerbaijan mobile phone utilities**
12
+ > Added support for **FIN and local ID utilities**
13
13
 
14
14
  ---
15
15
 
@@ -21,7 +21,18 @@ This package focuses on **validation, normalization, and parsing** of data forma
21
21
  - Normalize phone numbers to a standard local format
22
22
  - Detect mobile operator (Azercell, Bakcell, Nar)
23
23
 
24
- More utilities (FIN, IBAN, passport, addresses) will be added incrementally.
24
+ ### 📱 FIN Utilities
25
+
26
+ - Validate FIN
27
+ - Normalize FIN
28
+
29
+ ### 📱 Passport Utilities
30
+
31
+ - Validate local ID series
32
+ - Normalize ID series
33
+ - Supported series (AZE,AA,AB)
34
+
35
+ More utilities (IBAN, addresses) will be added incrementally.
25
36
 
26
37
  ---
27
38
 
@@ -41,6 +52,7 @@ import {
41
52
  getAzMobileOperator,
42
53
  IsAzPhone,
43
54
  TransformAzPhone
55
+ ...etc
44
56
  } from "az-utils";
45
57
 
46
58
  ```
@@ -52,7 +64,9 @@ isValidAzPhone("+994 (50) 123-45-67"); // true
52
64
  isValidAzPhone("0501234567"); // true
53
65
  isValidAzPhone("0401234567"); // false
54
66
  ```
67
+
55
68
  Supported input formats:
69
+
56
70
  - 0501234567
57
71
  - 050 123 45 67
58
72
  - (050) 123-45-67
@@ -90,29 +104,37 @@ getAzMobileOperator("0771234567");
90
104
  class TestDto {
91
105
  @IsAzPhone()
92
106
  phone!: string;
107
+
108
+ @IsFin()
109
+ fin!: string
110
+
111
+ @IsSeries()
112
+ idSeries!: string
93
113
  }
94
114
  ```
95
115
 
96
116
  ### Supported Prefixes
97
117
 
118
+ ## Mobile phones
119
+
98
120
  | Prefix | Operator |
99
- | -------- | -------- |
121
+ | ------------ | -------- |
100
122
  | 050, 051,010 | Azercell |
101
123
  | 055, 099 | Bakcell |
102
124
  | 070, 077 | Nar |
103
125
 
126
+ ## Local ID series
104
127
 
128
+ AZE, AA, AB
105
129
 
106
- ## 🛣 Roadmap
130
+ ---
107
131
 
108
- Planned additions:
132
+ ## 🛣 Roadmap
109
133
 
110
- - FIN (Fərdi İdentifikasiya Nömrəsi) validation
134
+ Planned additions:
111
135
 
112
136
  - Azerbaijan IBAN validation
113
137
 
114
- - Passport series validation
115
-
116
138
  - Address parsing utilities
117
139
 
118
140
  - Localization helpers (AZ / EN / RU)
@@ -129,9 +151,8 @@ Please:
129
151
 
130
152
  - Avoid breaking changes without discussion
131
153
 
132
- ## 📄 License
154
+ ## 📄 License
133
155
 
134
156
  MIT License © Contributors
135
157
 
136
- ---
137
-
158
+ ---
@@ -0,0 +1,2 @@
1
+ export { IsFin } from "./isFin.decorator";
2
+ export { TransformFin } from "./transform-fin.decorators";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformFin = exports.IsFin = void 0;
4
+ var isFin_decorator_1 = require("./isFin.decorator");
5
+ Object.defineProperty(exports, "IsFin", { enumerable: true, get: function () { return isFin_decorator_1.IsFin; } });
6
+ var transform_fin_decorators_1 = require("./transform-fin.decorators");
7
+ Object.defineProperty(exports, "TransformFin", { enumerable: true, get: function () { return transform_fin_decorators_1.TransformFin; } });
@@ -0,0 +1,2 @@
1
+ import { ValidationOptions } from "class-validator";
2
+ export declare function IsFin(validationOptions?: ValidationOptions): PropertyDecorator;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsFin = IsFin;
4
+ const class_validator_1 = require("class-validator");
5
+ const isValidFin_1 = require("../isValidFin");
6
+ function IsFin(validationOptions) {
7
+ return function (target, propertyKey) {
8
+ (0, class_validator_1.registerDecorator)({
9
+ name: "IsFin",
10
+ target: target.constructor,
11
+ propertyName: propertyKey,
12
+ options: validationOptions,
13
+ validator: {
14
+ validate(value) {
15
+ return typeof value === "string" && (0, isValidFin_1.isValidFin)(value);
16
+ },
17
+ defaultMessage() {
18
+ return "$property must be a valid Azerbaijan FIN";
19
+ },
20
+ },
21
+ });
22
+ };
23
+ }
@@ -0,0 +1 @@
1
+ export declare function TransformFin(): PropertyDecorator;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformFin = TransformFin;
4
+ const class_transformer_1 = require("class-transformer");
5
+ const normalizeFin_1 = require("../normalizeFin");
6
+ function TransformFin() {
7
+ return (0, class_transformer_1.Transform)(({ value }) => {
8
+ if (value === undefined || value === null)
9
+ return value;
10
+ if (typeof value !== "string")
11
+ return value;
12
+ return (0, normalizeFin_1.normalizeFin)(value);
13
+ });
14
+ }
@@ -1 +1,3 @@
1
- export {};
1
+ export { isValidFin } from "./isValidFin";
2
+ export { normalizeFin } from "./normalizeFin";
3
+ export * from "./decorators";
package/dist/fin/index.js CHANGED
@@ -1,2 +1,22 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.normalizeFin = exports.isValidFin = void 0;
18
+ var isValidFin_1 = require("./isValidFin");
19
+ Object.defineProperty(exports, "isValidFin", { enumerable: true, get: function () { return isValidFin_1.isValidFin; } });
20
+ var normalizeFin_1 = require("./normalizeFin");
21
+ Object.defineProperty(exports, "normalizeFin", { enumerable: true, get: function () { return normalizeFin_1.normalizeFin; } });
22
+ __exportStar(require("./decorators"), exports);
@@ -0,0 +1 @@
1
+ export declare function isValidFin(fin: string): boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidFin = isValidFin;
4
+ function isValidFin(fin) {
5
+ if (typeof fin !== "string")
6
+ return false;
7
+ return /^[A-Z0-9]{7}$/.test(fin.toUpperCase());
8
+ }
@@ -0,0 +1 @@
1
+ export declare function normalizeFin(fin: string): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeFin = normalizeFin;
4
+ function normalizeFin(fin) {
5
+ if (typeof fin !== "string")
6
+ return fin;
7
+ return fin.toUpperCase();
8
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * from "./phone";
2
+ export * from "./fin";
3
+ export * from "./passport";
package/dist/index.js CHANGED
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./phone"), exports);
18
+ __exportStar(require("./fin"), exports);
19
+ __exportStar(require("./passport"), exports);
@@ -0,0 +1 @@
1
+ export declare const SERIES_REGEX: RegExp;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SERIES_REGEX = void 0;
4
+ exports.SERIES_REGEX = /^(AZE\d{8}|AA\d{7}|AB\d{7})$/;
@@ -0,0 +1,2 @@
1
+ export { IsSeries } from "./isSeries.decorator";
2
+ export { TransformSeries } from "./transformSeries.decorator";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformSeries = exports.IsSeries = void 0;
4
+ var isSeries_decorator_1 = require("./isSeries.decorator");
5
+ Object.defineProperty(exports, "IsSeries", { enumerable: true, get: function () { return isSeries_decorator_1.IsSeries; } });
6
+ var transformSeries_decorator_1 = require("./transformSeries.decorator");
7
+ Object.defineProperty(exports, "TransformSeries", { enumerable: true, get: function () { return transformSeries_decorator_1.TransformSeries; } });
@@ -0,0 +1,2 @@
1
+ import { ValidationOptions } from "class-validator";
2
+ export declare function IsSeries(validationOptions?: ValidationOptions): PropertyDecorator;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsSeries = IsSeries;
4
+ const class_validator_1 = require("class-validator");
5
+ const isValidSeries_1 = require("../isValidSeries");
6
+ function IsSeries(validationOptions) {
7
+ return function (target, propertyKey) {
8
+ (0, class_validator_1.registerDecorator)({
9
+ name: "IsSeries",
10
+ target: target.constructor,
11
+ propertyName: propertyKey,
12
+ options: validationOptions,
13
+ validator: {
14
+ validate(value) {
15
+ return typeof value === "string" && (0, isValidSeries_1.isValidSeries)(value);
16
+ },
17
+ defaultMessage() {
18
+ return "$property must be a valid Azerbaijan series";
19
+ },
20
+ },
21
+ });
22
+ };
23
+ }
@@ -0,0 +1 @@
1
+ export declare function TransformSeries(): PropertyDecorator;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformSeries = TransformSeries;
4
+ const class_transformer_1 = require("class-transformer");
5
+ const normalizeSeries_1 = require("../normalizeSeries");
6
+ function TransformSeries() {
7
+ return (0, class_transformer_1.Transform)(({ value }) => {
8
+ if (value === undefined || value === null)
9
+ return value;
10
+ if (typeof value !== "string")
11
+ return value;
12
+ return (0, normalizeSeries_1.normalizeSeries)(value);
13
+ });
14
+ }
@@ -1 +1,3 @@
1
- export {};
1
+ export { isValidSeries } from "./isValidSeries";
2
+ export { normalizeSeries } from "./normalizeSeries";
3
+ export * from "./decorators";
@@ -1,2 +1,22 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.normalizeSeries = exports.isValidSeries = void 0;
18
+ var isValidSeries_1 = require("./isValidSeries");
19
+ Object.defineProperty(exports, "isValidSeries", { enumerable: true, get: function () { return isValidSeries_1.isValidSeries; } });
20
+ var normalizeSeries_1 = require("./normalizeSeries");
21
+ Object.defineProperty(exports, "normalizeSeries", { enumerable: true, get: function () { return normalizeSeries_1.normalizeSeries; } });
22
+ __exportStar(require("./decorators"), exports);
@@ -0,0 +1 @@
1
+ export declare function isValidSeries(series: string): boolean;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidSeries = isValidSeries;
4
+ const constants_1 = require("./constants");
5
+ function isValidSeries(series) {
6
+ if (typeof series !== "string")
7
+ return false;
8
+ return constants_1.SERIES_REGEX.test(series.toUpperCase());
9
+ }
@@ -0,0 +1 @@
1
+ export declare function normalizeSeries(series: string): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeSeries = normalizeSeries;
4
+ function normalizeSeries(series) {
5
+ if (typeof series !== "string")
6
+ return series;
7
+ return series.toUpperCase().trim();
8
+ }
@@ -1,2 +1,3 @@
1
1
  export type AzMobileOperator = "Azercell" | "Bakcell" | "Nar" | "Unknown";
2
2
  export declare const OPERATOR_PREFIX_MAP: Record<string, AzMobileOperator>;
3
+ export declare const AZ_PHONE_PREFIX: "+994";
@@ -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,4 @@
1
+ export declare const NUMBER_LENGTH_REX: RegExp;
2
+ export declare const NUMBER_CLEANING_REX: RegExp;
3
+ export declare const NUMBER_PARTITION_WITH_PREFIX_REX: RegExp;
4
+ export declare const NUMBER_PARTITION_LOCAL_REX: RegExp;
@@ -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 "./isAzPhone.decorator";
2
- export { TransformAzPhone } from "./transformAzPhone.decorator";
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 isAzPhone_decorator_1 = require("./isAzPhone.decorator");
5
- Object.defineProperty(exports, "IsAzPhone", { enumerable: true, get: function () { return isAzPhone_decorator_1.IsAzPhone; } });
6
- var transformAzPhone_decorator_1 = require("./transformAzPhone.decorator");
7
- Object.defineProperty(exports, "TransformAzPhone", { enumerable: true, get: function () { return transformAzPhone_decorator_1.TransformAzPhone; } });
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 isValidAzPhone_1 = __importDefault(require("../isValidAzPhone"));
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, isValidAzPhone_1.default)(value);
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`;
@@ -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 normalizeAzPhone_1 = require("../normalizeAzPhone");
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, normalizeAzPhone_1.normalizeAzPhone)(value);
12
+ return (0, normalize_az_phone_1.normalizeAzPhone)(value);
13
13
  });
14
14
  }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * ex. 0501234567 → +994 50 123 45 67
3
+ */
4
+ export declare function formatAzPhoneInternational(phone: string): string;
@@ -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 "./operators";
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
+ }
@@ -1,5 +1,8 @@
1
- export { isValidAzPhone } from "./isValidAzPhone";
2
- export { normalizeAzPhone } from "./normalizeAzPhone";
3
- export { getAzMobileOperator } from "./getAzMobileOperator";
4
- export type { AzMobileOperator } from "./operators";
5
- export * from './decorators';
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";
@@ -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 isValidAzPhone_1 = require("./isValidAzPhone");
19
- Object.defineProperty(exports, "isValidAzPhone", { enumerable: true, get: function () { return isValidAzPhone_1.isValidAzPhone; } });
20
- var normalizeAzPhone_1 = require("./normalizeAzPhone");
21
- Object.defineProperty(exports, "normalizeAzPhone", { enumerable: true, get: function () { return normalizeAzPhone_1.normalizeAzPhone; } });
22
- var getAzMobileOperator_1 = require("./getAzMobileOperator");
23
- Object.defineProperty(exports, "getAzMobileOperator", { enumerable: true, get: function () { return getAzMobileOperator_1.getAzMobileOperator; } });
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 operators_1 = require("./operators");
5
- const constants_1 = require("./constants");
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(constants_1.NUMBER_CLEANING_REX, "");
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 operators_1.OPERATOR_PREFIX_MAP) {
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 (!constants_1.NUMBER_LENGTH_REX.test(localNumber)) {
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 operators_1.OPERATOR_PREFIX_MAP;
32
+ return operatorPrefix in operator_constants_1.OPERATOR_PREFIX_MAP;
33
33
  }
34
34
  exports.default = isValidAzPhone;
@@ -0,0 +1,8 @@
1
+ import { MaskAzPhoneOptions } from "./phone.types";
2
+ /**
3
+ * @example +994501234567 → +994 50 *** ** 67
4
+ */
5
+ export declare function maskAzPhone(phone: string, options?: MaskAzPhoneOptions): {
6
+ value: string;
7
+ isMasked: boolean;
8
+ };
@@ -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 isValidAzPhone_1 = require("./isValidAzPhone");
5
- const constants_1 = require("./constants");
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, isValidAzPhone_1.isValidAzPhone)(phone)) {
7
+ if (!(0, is_valid_az_phone_1.isValidAzPhone)(phone)) {
8
8
  return null;
9
9
  }
10
- const cleaned = phone.replace(constants_1.NUMBER_CLEANING_REX, "");
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);
@@ -0,0 +1,7 @@
1
+ export interface MaskAzPhoneOptions {
2
+ /**
3
+ * Visible digits at the end (2–5)
4
+ * @default 2
5
+ */
6
+ visibleEnd?: number;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caucasus/az-utils",
3
- "version": "0.2.3",
3
+ "version": "0.4.0",
4
4
  "description": "Azerbaijan-specific utility functions for Node.js backends",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -1,2 +0,0 @@
1
- export declare const NUMBER_LENGTH_REX: RegExp;
2
- export declare const NUMBER_CLEANING_REX: RegExp;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NUMBER_CLEANING_REX = exports.NUMBER_LENGTH_REX = void 0;
4
- exports.NUMBER_LENGTH_REX = /^\d{9}$/;
5
- exports.NUMBER_CLEANING_REX = /[\s\-()]/g;
@@ -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
- }