@caucasus/az-utils 0.1.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/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 samurai-jack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ ![pipeline status](https://gitlab.com/samurai-jack/az-utils/badges/master/pipeline.svg)
2
+ ![npm version](https://img.shields.io/npm/v/@samurai-jack/az-utils)
3
+ ![license](https://img.shields.io/npm/l/@samurai-jack/az-utils)
4
+
5
+
6
+ # az-utils 🇦🇿
7
+
8
+ A lightweight, TypeScript-first utility library providing **Azerbaijan-specific helpers** commonly needed in backend development.
9
+
10
+ This package focuses on **validation, normalization, and parsing** of data formats frequently used in Azerbaijan-based systems.
11
+
12
+ > ✅ Current version: **v0.1.0**
13
+ > Initial release focuses on **Azerbaijan mobile phone utilities**
14
+
15
+ ---
16
+
17
+ ## ✨ Features
18
+
19
+ ### 📱 Phone Utilities
20
+
21
+ - Validate Azerbaijan mobile phone numbers
22
+ - Normalize phone numbers to a standard local format
23
+ - Detect mobile operator (Azercell, Bakcell, Nar)
24
+
25
+ More utilities (FIN, IBAN, passport, addresses) will be added incrementally.
26
+
27
+ ---
28
+
29
+ ## 📦 Installation
30
+
31
+ ```bash
32
+ npm install @samurai-jack/az-utils
33
+
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ```
39
+ import {
40
+ isValidAzPhone,
41
+ normalizeAzPhone,
42
+ getAzMobileOperator
43
+ } from "az-utils";
44
+
45
+ ```
46
+
47
+ ## ✅ Validate Phone Number
48
+
49
+ ```
50
+ isValidAzPhone("+994 (50) 123-45-67"); // true
51
+ isValidAzPhone("0501234567"); // true
52
+ isValidAzPhone("0401234567"); // false
53
+ ```
54
+ Supported input formats:
55
+ - 0501234567
56
+ - 050 123 45 67
57
+ - (050) 123-45-67
58
+ - 994501234567
59
+ - +994501234567
60
+
61
+ ## 🔄Normalize Phone Number
62
+
63
+ ```
64
+ normalizeAzPhone("+994701112233");
65
+ // "0701112233"
66
+
67
+ normalizeAzPhone("(050) 123-45-67");
68
+ // "0501234567"
69
+
70
+ ```
71
+
72
+ ## 🏷 Detect Mobile Operator
73
+
74
+ ```
75
+ getAzMobileOperator("0501234567");
76
+ // "Azercell"
77
+
78
+ getAzMobileOperator("0551234567");
79
+ // "Bakcell"
80
+
81
+ getAzMobileOperator("0771234567");
82
+ // "Nar"
83
+
84
+ ```
85
+
86
+ ### Supported Prefixes
87
+
88
+ | Prefix | Operator |
89
+ | -------- | -------- |
90
+ | 050, 051,010 | Azercell |
91
+ | 055, 099 | Bakcell |
92
+ | 070, 077 | Nar |
93
+
94
+
95
+
96
+ ## 🛣 Roadmap
97
+
98
+ Planned additions:
99
+
100
+ - FIN (Fərdi İdentifikasiya Nömrəsi) validation
101
+
102
+ - Azerbaijan IBAN validation
103
+
104
+ - Passport series validation
105
+
106
+ - Address parsing utilities
107
+
108
+ - Localization helpers (AZ / EN / RU)
109
+
110
+ ## 🤝 Contributing
111
+
112
+ Contributions are welcome.
113
+
114
+ Please:
115
+
116
+ - Keep changes small and focused
117
+
118
+ - Add tests for new functionality
119
+
120
+ - Avoid breaking changes without discussion
121
+
122
+ ## 📄 License
123
+
124
+ MIT License © Contributors
125
+
126
+ ---
127
+
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from "./phone";
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./phone"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare const NUMBER_LENGTH_REX: RegExp;
2
+ export declare const NUMBER_CLEANING_REX: RegExp;
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1,2 @@
1
+ import { AzMobileOperator } from "./operators";
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 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
+ }
@@ -0,0 +1,4 @@
1
+ export { isValidAzPhone } from "./isValidAzPhone";
2
+ export { normalizeAzPhone } from "./normalizeAzPhone";
3
+ export { getAzMobileOperator } from "./getAzMobileOperator";
4
+ export type { AzMobileOperator } from "./operators";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAzMobileOperator = exports.normalizeAzPhone = exports.isValidAzPhone = void 0;
4
+ var isValidAzPhone_1 = require("./isValidAzPhone");
5
+ Object.defineProperty(exports, "isValidAzPhone", { enumerable: true, get: function () { return isValidAzPhone_1.isValidAzPhone; } });
6
+ var normalizeAzPhone_1 = require("./normalizeAzPhone");
7
+ Object.defineProperty(exports, "normalizeAzPhone", { enumerable: true, get: function () { return normalizeAzPhone_1.normalizeAzPhone; } });
8
+ var getAzMobileOperator_1 = require("./getAzMobileOperator");
9
+ Object.defineProperty(exports, "getAzMobileOperator", { enumerable: true, get: function () { return getAzMobileOperator_1.getAzMobileOperator; } });
@@ -0,0 +1 @@
1
+ export declare function isValidAzPhone(phone: string): boolean;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidAzPhone = isValidAzPhone;
4
+ const operators_1 = require("./operators");
5
+ const constants_1 = require("./constants");
6
+ function isValidAzPhone(phone) {
7
+ if (!phone)
8
+ return false;
9
+ // Remove spaces, dashes, parentheses
10
+ const cleaned = phone.replace(constants_1.NUMBER_CLEANING_REX, "");
11
+ let localNumber;
12
+ if (cleaned.startsWith("+994")) {
13
+ localNumber = cleaned.slice(4);
14
+ }
15
+ else if (cleaned.startsWith("994")) {
16
+ localNumber = cleaned.slice(3);
17
+ }
18
+ else if (cleaned.startsWith("0")) {
19
+ localNumber = cleaned.slice(1);
20
+ }
21
+ else if (cleaned.slice(0, 2) in operators_1.OPERATOR_PREFIX_MAP) {
22
+ localNumber = cleaned;
23
+ }
24
+ else {
25
+ return false;
26
+ }
27
+ // Must be exactly 9 digits after prefix removal
28
+ if (!constants_1.NUMBER_LENGTH_REX.test(localNumber)) {
29
+ return false;
30
+ }
31
+ const operatorPrefix = localNumber.slice(0, 2);
32
+ return operatorPrefix in operators_1.OPERATOR_PREFIX_MAP;
33
+ }
@@ -0,0 +1 @@
1
+ export declare function normalizeAzPhone(phone: string): string | null;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeAzPhone = normalizeAzPhone;
4
+ const isValidAzPhone_1 = require("./isValidAzPhone");
5
+ const constants_1 = require("./constants");
6
+ function normalizeAzPhone(phone) {
7
+ if (!(0, isValidAzPhone_1.isValidAzPhone)(phone)) {
8
+ return null;
9
+ }
10
+ const cleaned = phone.replace(constants_1.NUMBER_CLEANING_REX, "");
11
+ let localNumber;
12
+ if (cleaned.startsWith("+994")) {
13
+ localNumber = cleaned.slice(4);
14
+ }
15
+ else if (cleaned.startsWith("994")) {
16
+ localNumber = cleaned.slice(3);
17
+ }
18
+ else if (cleaned.startsWith("0")) {
19
+ localNumber = cleaned.slice(1);
20
+ }
21
+ else {
22
+ localNumber = cleaned;
23
+ }
24
+ return "0".concat(localNumber);
25
+ }
@@ -0,0 +1,2 @@
1
+ export type AzMobileOperator = "Azercell" | "Bakcell" | "Nar" | "Unknown";
2
+ export declare const OPERATOR_PREFIX_MAP: Record<string, AzMobileOperator>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPERATOR_PREFIX_MAP = void 0;
4
+ exports.OPERATOR_PREFIX_MAP = {
5
+ "50": "Azercell",
6
+ "51": "Azercell",
7
+ "10": "Azercell",
8
+ "55": "Bakcell",
9
+ "99": "Bakcell",
10
+ "70": "Nar",
11
+ "77": "Nar",
12
+ };
@@ -0,0 +1,2 @@
1
+ export declare const NUMBER_LENGTH_REX: RegExp;
2
+ export declare const NUMBER_CLEANING_REX: RegExp;
@@ -0,0 +1,5 @@
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;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@caucasus/az-utils",
3
+ "version": "0.1.0",
4
+ "description": "Azerbaijan-specific utility functions for Node.js backends",
5
+ "type": "commonjs",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "test": "vitest"
14
+ },
15
+ "devDependencies": {
16
+ "typescript": "^5.9.3",
17
+ "vitest": "^4.0.17"
18
+ },
19
+ "keywords": [
20
+ "azerbaijan",
21
+ "utils",
22
+ "validation",
23
+ "nodejs"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "author": "Javid Guliyev",
29
+ "license": "MIT"
30
+ }